For my elevator assignment, I need to keep the old average wait time and average travel time, and compare them with the new average wait time and average travel time (by changing the time it takes for the elevator to ascend or descend from 2 seconds to 1 second. The variable is floorTime). However, I am not sure how I could do this without replacing the old numbers that are passed to the class that sets the wait time and the travel time.
How could I have my program calculate two sets of different numbers without having to create more methods just for the new values? (Using old values, calculate, then save average time. Old values changes to new, calculates, then saves as new average time. All using the same methods)
Here's the code that sends the values to the Building class:
Building class that initializes the elevators with the values above:
I tried to create another object to pass in the new values, but that would replace the old one. The only other way that I can think of doing this is to have separate calculation for old values and new values, which would double the amount of code lines.
Jeong Ryu wrote:I tried to create another object to pass in the new values, but that would replace the old one.
You didn't show us the rest of your Building class, but I guess your member variables NUM_FLOORS and NUM_ELEVATORS are static. That means that there's only one copy of those variables, which is shared by all instances of class Building. Make the variables non-static (and change their names, to make them conform standard Java naming conventions).