wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes How to use two different numbers for the same calculation? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to use two different numbers for the same calculation?" Watch "How to use two different numbers for the same calculation?" New topic
Author

How to use two different numbers for the same calculation?

Jeong Ryu
Greenhorn

Joined: Sep 25, 2012
Posts: 28
Hi CR,

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.

Any input would be greatly appreciated!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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).

See: Understanding Instance and Class Members in Oracle's Java Tutorials.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use two different numbers for the same calculation?
 
Similar Threads
2-D array of boolean
Elevator Final Result
English and American English
problem with variable
Question on creating objects