Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi, I don't really have a code, I just have questions that I'm hoping someone can answer.

1) Basically, at the start, the elevator is situated at a given floor. Its first action is to load on some passengers. // I know this part will be a method, I'm just trying to figure out what variables to use.

2) Elevator moves from current floor to destination floor:
- it announces every floor it passes. // Would this part be a loop? Depending how many floors the building has?
-It will not have to stop at any of these floors just the destination floor

3) At the destination floor it performs two actions:
- offloads a certain amount of riders (not necessarily all of them)
- onload a certain number of people (but do not overload the elevator) // Would these two actions also be loops as well for loading and unloading riders?

What I have tried:

I haven't tried to code anything yet. My professor says not to look at the tutorial, but try and figure out what variables and methods I would need for my code. And if some of you are going to be rude, just don't answer my questions. I genuinely came here for help, because my professor or my classmates aren't really a big help and programming isn't easy so I would appreciate it very much so if I wasn't attacked for trying to get some type of help.

Anyway, the first thing I need to figure out is what variables I need to use in my code, there are three types: variables having to with the riders, the riders involved, and variables having to with the operation of the elevator.

here are the variables I have so far:
currentFloor
destinationFloor
loadingRiders
unloadingRiders
totalRiders
numberOfFloors
elevatorUp
elevatorDown

If anyone has any feedback that would help, that would be greatly apprieciated, or any variables that they think should be added would help me alot, that way I know how to create my methods. Thank you.
Posted
Updated 29-Oct-20 7:54am
Comments
onelopez 16-Jun-17 22:53pm    
Looks good, if you are trying to keep this simple, start using a switch statement with possible states of the elevator. Once inside the case statements perform logic desired for that state. Elevator loading people, then let that state change to the next state, moving to desired floor.
PIEBALDconsult 16-Jun-17 23:18pm    
printf ( "Out of service.\n" ) ;
pt1401 17-Jun-17 1:42am    
The trick is to read the requirement and identify the objects, operations and variables.
Something like this :-

1) At the start, the elevator is situated at a given floor. Its first action is to load on some passengers
Objects: Elevator, Passenger
Operations: Elevator.Load(int passengerCount)
Variables: currentFloor, passengersToLoad

2) Elevator moves from current floor to destination floor:
- it announces every floor it passes. // Would this part be a loop? Depending how many floors the building has?
-It will not have to stop at any of these floors just the destination floor
Operations: Elevator.MoveTo(int destinationFloor), Elevator.Announce(int floorNumber)

3) At the destination floor it performs two actions:
- offloads a certain amount of riders (not necessarily all of them)
- onload a certain number of people (but do not overload the elevator) // Would these two actions also be loops as well for loading and unloading riders?
Operations: Elevator.Unload(int passengersToUnload), Elevator.Unload(int passengersToLoad)
Variables: maxPassengers

That should give you a starting point for the objects you need (just one, Elevator), and the methods.
Then you need to code the methods by translating the requirements into logic and then code.
What you have is good so far, good luck...
Kadeidra W 17-Jun-17 12:06pm    
Thank you so much! This was really a big help! I appreciate it!

An interesting homework, but I can't do your homework. Nevertheless, it's too tempting that I will give you a head start (as an excuse):
Let's examine the interactions between a riders and the lift. Assuming the lift starts at a random floor, and a passenger calls it from a random floor, and want to ride to a different random floor, a snippet of the pseudo code can be expressed as shown:
numberOfFloors = 10;
ridership = 0;
elevatorMovement = 0; // -1 for down, 0 for still, 1 for up

// lift at random floor on start of the program
liftCurrentFloor = Math.floor((Math.random() * numberOfFloors) + 1);

// a method to move lift to the calling passenger
moveLift(destinationFloor){
  elevatorMovement = destinationFloor - liftCurrentFloor;
  liftCurrentFloor = destinationFloor;

  loadPassenger(); // If the passenger is outside the lift
   
  unloadPassenger(); // If the passender is inside the lift
}

loadPassenger(){
  ridership++;
  desiredFloor = Math.floor((Math.random() * numberOfFloors) + 1);
  // use a loop to check that the desiredFloor != liftCurrentFloor before calling
  moveLift(desiredFloor);
}

unloadPassenger(){
  ridership--;
}

// A passenger call the lift from a random floor
callLift(){
  moveLift(Math.floor((Math.random() * numberOfFloors) + 1));
}
I have merely thrown in some light to help your kick start. In reality, you will expect multiple passengers calling from and going to different floors simultaneously. One way to tackle this is to create a passenger object in code with properties like floorAt, floorTo, isInsideLift etc. And in your lift object, you can handle them as an array of passengers. Got it?
Happy coding!
P.S. at least I have quenched my thirst a bit.
 
Share this answer
 
v5
Quote:
simulate the operation of an elevator

An elevator is an automata, which mean that it operate with events.
So it is all a matter of logic, and all fit in 1 question: "What happens if ?"
To know if you need a variable, answer this question: "Does it operate differently if ?"
- totalRiders: Does it operate differently depending on the number of riders ?
- loadingRiders, unloadingRiders: Does it operate differently for loading riders and for unloading riders ?
- loadingRiders, unloadingRiders: Does it operate differently if no rider load or unload.
Quote:
1) Basically, at the start, the elevator is situated at a given floor. Its first action is to load on some passengers.

Are you sure about the first action ? What if elevator is on floor 4 and you call it from floor 1.
Quote:
3) At the destination floor it performs two actions:
- offloads a certain amount of riders (not necessarily all of them)
- onload a certain number of people (but do not overload the elevator) // Would these two actions also be loops as well for loading and unloading riders?

Do you really think the elevator is counting the passengers ?
Quote:
And if some of you are going to be rude, just don't answer my questions.

Sometimes, having someone being a little rude to you, is the best way to make you crank your brain, and finally being good to you.
Albert Einstein wrote:
Everything should be made as simple as possible, but no simpler.
 
Share this answer
 
Comments
Kadeidra W 17-Jun-17 12:11pm    
I understand what you're getting at with the questions. Basically this is what my assignment said exactly, I didn't try to even break it down that way! Thank you, this makes me think a little more!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900