From jacobson@math-cs.cns.uni.edu Thu Oct 24 18:11:09 2002 Date: Thu, 24 Oct 2002 18:09:13 -0500 (CDT) From: Mark Jacobson To: 810-061-01@uni.edu, 810-061-02@uni.edu Subject: The pauses between creating new Vehicles in Lane class... Hi 061 students, We will start on chapters 6 and 7 tommorrow in class. If you have not purchased the chapters 6, 7 and 8 packet, you probably want to do that very soon. The computer science secretary is on vacation tommorrow (Friday) but there will be a student assistant in the office part of the time, or you can see me. They cost $2.10 total for the 65-70 pages of the Williams College textbook. Here is a suggestion for the pause you build into the Lane class. Obviously, the pause must be bigger or longer for SLOW lanes than it is for Lanes that are for fast cars. public void run() { double pauseAmount = Math.abs(12000 / velocity); // Loop until the program stops. while ( true ) So if the velocity for the Lane is 4, we have pause of 3000, if 3, pause is 4000, if 2, pause is 6000, if 1, pause is 12000 if 1.5, pause is 8000 So my slowest car Lane pauses 12000 milliseconds or about 12 seconds before it creates the next new Vehicle object and has it pull on to the interstate. The reason that I use Math.abs() above, is because a negative velocity (not required) that moves the cars from right to left, would give a negative quotient. Math.abs( 12000 / velocity ) would become Math.abs( -6000 ) is the velocity is -2, but the absolute value of -6000 is 6000. Math.abs( -1000 ) is 1000 Math.abs( 12000 ) is 12000 The absolute value of -5 is 5. Math.abs(-5) equals 5 Mark