File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Elevator problem: How to add a condition to move one elevator at a time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Elevator problem: How to add a condition to move one elevator at a time" Watch "Elevator problem: How to add a condition to move one elevator at a time" New topic
Author

Elevator problem: How to add a condition to move one elevator at a time

Jeong Ryu
Greenhorn

Joined: Sep 25, 2012
Posts: 28
[UPDATE]: I think I found the problem. I will post here if I can't figure it out, along with a more specific question.


Hi CR,

I am working on an elevator project where I have to move 8 elevators independently to different floors to pick up and drop off passengers. I have most of the code written, and it works sort of when I am only using one elevator. When I try to move all 8 elevators, they just move to the same floor at the same time.

I think the problem is that because there is no condition to invoke the takeAction method in the elevator class, each time the elevators are looped, they all just go through the takeAction method, which is why they are all moving together. How could I add a condition before the switch statement, so that only the elevators that are NOT in motion goes through the takeAction method?

Any insights would be greatly appreciated!







fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11229
    
  16

without looking at a single line of code, my thoughts go like this:

In the real world, what would an actual bank of elevators look like? Would one elevator know anything about the location/movement of any of the others? Or would there be some kind of central controller that knew the current position and destination of every elevator, as well as handling all the requests (i.e. "call to this floor" or "go to that floor").


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jeong Ryu
Greenhorn

Joined: Sep 25, 2012
Posts: 28
fred rosenberger wrote:without looking at a single line of code, my thoughts go like this:

In the real world, what would an actual bank of elevators look like? Would one elevator know anything about the location/movement of any of the others? Or would there be some kind of central controller that knew the current position and destination of every elevator, as well as handling all the requests (i.e. "call to this floor" or "go to that floor").


Thanks! Here, I was trying to see whether or not the elevator is stopped (in the takeAction method, the stop time decrements every time it is moving up or down. The problem, though, is that STOP_TIME will always be 3 because it will not decrement until the elevator is moving up or down. So, I thought that this is where the variable that acts as a position holder is used (for the control center you had mentioned). But, I am not sure how to create this variable that holds the positions of the elevator. I tried to create an Building class object, but I keep getting an error that says constructor is not defined. How do I use an array of another class by creating an object to access it, without it giving me this error (I want to use it, not send new arguments. I need to access the elevator array from the Building class so that I could set the elevator array in Elevator class to the one from the Building class)?

This is what I currently have:




EDIT: I just realized that I need to have to for loop keep looping back to 0, or else no elevators will move after i becomes 8. And that FLOOR_TIME == 3 will always be true, since the FLOOR_TIME never gets the chance to decrement, since this for loop happens before the elevators moving up and down(which causes the FLOOR_TIME to decrement and then reset to 3 after). Sigh.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Elevator problem: How to add a condition to move one elevator at a time