Thread: java question
View Single Post
Old Nov 7, 2004, 05:45 PM   #1 (permalink)
lime
DriverHeaven Newbie
 
Join Date: Oct 2004
Posts: 8
lime is on a distinguished road

java question

i'm working on a simulator project and i'm having trouble in one area....

i run a simulation of planes landing and taking off on one runway, the user inputs the minutes to run the sim, the prob of a plane landing and taking off, the minutes it takes to land and to take off....the constructor and everything is fine but i'm having trouble in this one method

the method runs the actual simulation ... it generates random doubles to check if a plane wants to land and if a plane wants to take off, if so it adds them to the appropriate queue. the part i'm having trouble with is getting the average wait time in the queue and the number of planes left in each queue....here's the code i have for this method so far, any ideas ????

Code:
public void runSim() {
 		rnd = new Random();
 		while(interval <= minutes){
 			temp = rnd.nextDouble();
 			if(temp < probLand){
 				landingQ.add(new airplane(interval));
 			}
 			temp = rnd.nextDouble();
 			if(temp < probTake){
 				takeOffQ.add(new airplane(interval));
 			}
 			if(landingQ.size() > maxLand)
 				maxLand++;
 			if(takeOffQ.size() > maxTake)
 			    maxTake++;		    
 			if(!landingQ.isEmpty()){
 				landed++;
 			    landSum += interval - ((airplane)landingQ.front()).getStart();
 				landingQ.remove();
 				interval += minToLand;
 			}
 			else if((landingQ.isEmpty()) && (!takeOffQ.isEmpty())){
 				tookOff++;
 			    takeSum += interval - ((airplane)takeOffQ.front()).getStart();
 				takeOffQ.remove();
 				interval += minToTake;
 			}
 			else if((landingQ.isEmpty()) && (takeOffQ.isEmpty())){
 				interval++;
 		    }			
 		} // end while
 		leftLand = landingQ.size();
 		leftTake = takeOffQ.size();
 		if(landed == 0)
 			avgLand = 0;
 		else
 			avgLand = landSum/landed;
 		if(tookOff == 0)
 			avgTake = 0;
 		else
 			avgTake = takeSum/tookOff;
 	} // end method runSim()

Last edited by lime; Nov 7, 2004 at 05:52 PM.
lime is offline   Reply With Quote