This week's book giveaway is in the Spring forum.
We're giving away four copies of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 and have Marten Deinum & Iuliana Cosmina on-line!
See this thread for details.
Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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!







 
lowercase baba
Posts: 12988
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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").
 
Jeong Ryu
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic