Office Building
You must programmatically create an office building. You will have to create 5 classes, Elevator, Programmer, Artist, Executive, and Worker. All the classes will work with each other. Please use any python data structures (List, Sets, and Dictionaries) and what we have learned about object-oriented programming to develop this program. You will find documentation for the functions that you must implement for each class below. Feel free to use the accompanying unit test to test your code. Feel free to use Grader Than to submit your work to receive your Grade instantly and help. You may submit your work via Moodle or Grader Than.
WORKER
This is a base class for Programmer, Artist, and Executive. The worker has a first name (str) and last name (str) a destination floor (int) and a total amount of energy (float 0-1).
def __init__(first_name:str, last_name:str, destination:int):
The constructor for the class. first_name is a string representing the first name of the worker. last_name is a string representing the last name of the worker. the destination is an integer representing the floor the workers are going to get off on.
def get_destination() ->int:
Should return destination specified when the worker was constructed.
def get_name() -> str:
should return the first and last name separated by a space.
def __hash__()->int:
This should hash the string returned by get_name().
def __eq__(other)->bool:
This should test if one object of type Worker is equal to another type. Hint, testing if their names are equal will suffice.
def work(hours:float):
A worker only has enough energy to work 8 hours a day. This should decrease the worker's energy by a quantity that will make their energy level 0 when they have worked 8 hours. Or make their energy equal to .5 when they have worked 4 hours.
def get_energy() ->float :
Returns the current amount of energy the worker has within a 0-1 range. This should change after work() is called with a given amount of hours. This should never return less than 0.
EXECUTIVE
This class extends workers but overrides worker class's functions because executives only work 5 hours a day. Executives' destination floor is a random floor between 40 and 60.
def __init__(first_name:str, last_name:str):
Their floor should be randomly selected between 40 and 60.
def work(hours):
An executive only has enough energy to work 5 hours a day. This should decrease the worker's energy by a quantity that will make their energy level 0 when they have worked 5 hours.
ARTIST
This class extends workers but overrides worker class's functions because artists only work 6 hours a day. Artist's destination floor is a random floor between 20 and 39.
def __init__(first_name:str, last_name:str):
Their floor should be randomly selected between 20 and 39
def work(hours:float):
An artist only has enough energy to work 6hours a day. This should decrease the worker's energy by a quantity that will make their energy level 0 when they have worked 6 hours.
PROGRAMMER
This class extends workers but overrides work class's functions because programmers work 10 hours a day. The programmer's destination floor is a random floor between 1 and 19.
def __init__(first_name:str, last_name:str):
Their floor should be randomly selected between 1 and 19
def work(hours:float):
A programmer only has enough energy to work 10 hours a day. This should decrease the worker's energy by a quantity that will make their energy level 0 when they have worked 10 hours.
ELEVATOR
An elevator is an object that is able to hold workers and transport them to a destination. The elevator's destination is a specific floor (int). This destination of the elevator my change depending on its occupants and the minimum and maximum floor that is services.
def __init__(capacity:int, min_floor:int, max_floor:int):
This is the constructor of the elevator the capacity is the maximum amount of occupants that this elevator my hold. min_floor is the lowest floor that the elevator may go to and the max_floor - 1 is the highest floor that the elevator may travel to, both values will be greater than 0. min_floor < max_floor.
def add_occupant(person:Worker)->bool:
This method adds a worker to the elevator. If the elevator is already full (meaning the total number of workers on the elevator currently is >= the capacity specified at initialization) then the worker should not be added to the elevator. Returns True if the person was added to the elevator and false if they were not added.
def services_floor(floor:int)-> bool:
This should return True if the floor specified as a parameter is >= min_floor specified at initialization of this object and < max_floor specified at initialization of this object.
def riders() -> set:
This should return a set containing all of the workers on the elevator.
def max_riders() -> int:
This will return the capacity specified at initialization.
def full() -> bool:
This will return True if the total number of workers on this elevator is >= the capacity specified when this object was created.
def current_floor() -> int:
A number indicating which floor this elevator is currently on, this should never be less than 0. See move() to understand how this elevator may move from one floor to the next.
def direction() -> int:
This function will return a number greater than or less than zero. The value return will tell you which direction the elevator is going to move the next time move() is called. This will decide the direction by choosing the closest worker's destination to the elevator's current floor.
def move() -> set:
This function will move the elevator up or down one floor. The direction that the elevator will move is based on the value returned by direction(). Please see the direction() documentation for a better understanding. This function will return a set of workers on the elevator whose destination is equal to the floor that the elevator has moved to. Once this method is called and it has returned a set of workers that have gotten off the elevator those workers that have left the elevator should not be in the set of workers returned by riders().
This assignment has been answered 6 times in private sessions.
Or buy a ready solution below.
© 2024 Codify Tutor. All rights reserved