|
|||||||
| Programming, Coding, (Web)Design Discuss all your programming or design needs with likeminded people. |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
DriverHeaven Newbie
Join Date: Nov 2004
Posts: 8
Rep Power: 0 ![]() |
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 10:52 PM. |
|
|
|
|
|
#2 |
|
Delete Me
Join Date: Mar 2004
Posts: 14,648
Rep Power: 0 ![]() ![]() ![]() ![]() ![]() ![]() |
i'll look at it tomorrow when I'm more awake, just thought I'd let you knwo now so you wouldn't think you'd been abandoned
|
|
|
|
|
|
#3 |
|
Delete Me
Join Date: Mar 2004
Posts: 14,648
Rep Power: 0 ![]() ![]() ![]() ![]() ![]() ![]() |
hrmm..I dunno...that's a really round about way to do the program.....what all is in your landingQ class?
|
|
|
|
|
|
|
|
DriverHeaven Newbie
Join Date: Nov 2004
Posts: 8
Rep Power: 0 ![]() |
the landingQ is just an UnboundedQueue....it's fine...i just need help on how to check if the runway is free, if so and the landingQ isn't empty, then allow a plane to land, so the runway is not free for minToLand minutes....then go from there... i'm having trouble with that part
|
|
|
|
|
|
#5 |
|
DriverHeaven Senior Member
Join Date: Oct 2003
Location: around
Posts: 792
Rep Power: 0 ![]() |
My guess is landSum, landed, takeSum, tookOff are of an integral type. In this case, you need to convert at least one of the operands to a float.
E.g.: avgLand = (float)landSum/landed; On the other hand, double type is a performance killer on 32 bit platforms, so you'd be better off with float. Or if that is not a concern, just use if(Math.random()<whatever){ } I hope that solves your problem. If not get back to me. |
|
|
|
|
|
#6 |
|
Back in London
Join Date: Jul 2003
Location: London
Posts: 1,797
Rep Power: 0 ![]()
|
why dont you go to a developer forum where you will get loads more help.
devshed.com for example not saying the people here dont know cause some of them do but on developer forums its all about develoing
__________________
/|\ Asus P5W DH Deluxe, Intel C2D E6600, 2GB Corsair XMS2-6400C4 DDR2, E-VGA GeForce 7800 GT, Creative X-Fi Extreme Music, 500GB Seagate 7200.10 SATA, Lian Li PC-V1100 Aluminum Case Black, etc. http://germanjulian.com /|\ |
|
|
|
|
|
#7 | |
|
DriverHeaven Senior Member
Join Date: Oct 2003
Location: around
Posts: 792
Rep Power: 0 ![]() |
Quote:
|
|
|
|
|
|
|
|
|
DriverHeaven Newbie
Join Date: Nov 2004
Posts: 8
Rep Power: 0 ![]() |
well we had a lab exam with a similar problem and i figured out how to do that in the exam....so know my program works...i did use a boolean for runwayFree and it works better now....thanks for your help
|
|
|
|
|
|
#9 |
|
DriverHeaven Newbie
Join Date: May 2003
Posts: 10
Rep Power: 0 ![]() |
code looks good, although I would use math.random instead
|
|
|
|
![]() |
| Thread Tools | |
|
|