Starting from:
$30

$24

Programming Assignment 3 Paging Mr. Otis Solution




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 oor, travels to the top oor, reverses direction and continues until all passengers have been picked up and dropped o . You should track the number of oors 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 oor.




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 oors in the building and the number of passengers. The inputs should be veri ed as valid (positive integers). If they are invalid, the user should be asked to re-enter them.




1
Each passenger is on a oor chosen at random. Their destination oor 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 oor and all of the passengers on that oor including those waiting for the elevator and those that have already exited the elevator.




The simulation ends when all passengers have reached their destination oors. 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






oors
Number of oors 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






oors
Number of oors in the building


register


list
List of customers in the elevator






curr




oor
Current oor the elevator is on


direction
Direction of travel


move(self)
Method to move the elevator one oor


reg




pass(self, passenger)
Passenger enters elevator








exit




pass(self, passenger)
Passenger exits elevator


















Passenger
src


oor
Passenger’s starting oor


dest


oor
Passenger’s destination oor






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:




#




CS 224 Spring 2019



Programming Assignment 3



 
Your wonderful, pithy, erudite description of the assignment.



 
Author: Your name here



Date: March 13, 2019



#













Submission: The name of your program must be otis.py. Submit your solution as a compressed directory by 11:59 PM on the due date. In addition to the program, you must submit a README le that describes your elevator strategy and compares its performance to that of the default strategy.





















































































































More products