Starting from:

$27.99

Programming Assignment 3- elevator simulator


Description: For this assignment, you will write several Python classes to simulate an
elevator.
Details: Your simple elevator simulator will control a single elevator in a building. You
will implement two strategies: a default strategy and one that you design. The default
strategy is very straightforward: the elevator starts at a random floor, travels to the
top floor, reverses direction and continues until all passengers have been picked up and
dropped off. You should track the number of floors the elevator travels to service all
requests. Note that passengers only get on the elevator when it is traveling in the
direction of their desired floor.
The following will help you design your code:
• Implement three classes: Building, Elevator, and Passenger. See below for more
details.
• Your program will prompt the user to enter the number of floors in the building
and the number of passengers. The inputs should be verified as valid (positive
integers). If they are invalid, the user should be asked to re-enter them.
1
• Each passenger is on a floor chosen at random. Their destination floor is also
chosen at random.
• Each passenger rides the elevator exactly one time.
• Every time the elevator moves you will print a representation of the building
showing every floor and all of the passengers on that floor including those waiting
for the elevator and those that have already exited the elevator.
• The simulation ends when all passengers have reached their destination floors.
• Do not use any global variables.
The Classes: Each of the three classes will have the data attributes and methods listed
below. You may add others.
Class Attribute/Method Description
Building num floors Number of floors in the building
passenger list List of passengers
elevator The building’s elevator (object)
run(self) Method that operates the elevator
output(self) Prints the building
Elevator num floors Number of floors in the building
register list List of customers in the elevator
curr floor Current floor the elevator is on
direction Direction of travel
move(self) Method to move the elevator one floor
reg pass(self, passenger) Passenger enters elevator
exit pass(self, passenger) Passenger exits elevator
Passenger src floor Passenger’s starting floor
dest floor Passenger’s destination floor
direction Passenger’s director of travel
id Passenger’s ID
in elevator Indicates if passenger is in elevator
done Indicates if passenger arrived and exited
2
Adhere to common coding conventions and comment your code.. Include a comment
at the top that looks like this:
#

# Programming Assignment 3
#
# Your wonderful, pithy, erudite description of the assignment.

More products