Question

In: Computer Science

Hi, I would be grateful for some helot with this Python problem. Your task is to...

Hi, I would be grateful for some helot with this Python problem. Your task is to implement the simple elevator in Python using classes. The default strategy is the simple "start at the bottom, go to the top, then go to the bottom". Can you write a better strategy, one that is more efficient? Description / Specification Create three classes: Building, Elevator, and Customer. Equip the building with an elevator. Ask user to customize the number of floors and the number of customers. Program should have error checking to make sure the user inputs are valid. For example, if a user gives non-integer inputs, notify the user that the inputs are incorrect and prompt again. Each customer starts from a random floor, and has a random destination floor. Each customer will use the elevator only once, i.e., when a customer moves out of the elevator, he/she will never use it again. When all customers have reached their destination floor, the simulation is finished. Part of the grade on this assignment will be the appropriateness of your classes, methods, and any functions you use. The quality of the code will matter as well as the performance. All class methods require a docstring for a general description of the method. Implement both your own strategy and the default strategy and compare. Your strategy does not have to be better but the comparison is required. Don't use any global variables. Notes and Hints In your main function, at the beginning ask the user for the number of floors and the number of customers which can be used to create an instance of Building. Then we only need to call the run and output methods repeatedly in a while loop. Randomly select the floors (to and from) for each customer. Use the randint function from the random module. To compare efficiency of strategy, count the number of floors visited for your strategy versus the default strategy. Make a demo to create usable output from your simulation.

Solutions

Expert Solution

import random

floors=raw_input('Please enter the number of floors for the simulation:')  
while floors.isalpha() or floors.isspace() or int(floors) <=0:  
    floors=raw_input('Please re enter a digit for number of floors:')  
customers=raw_input('Please enter the number of customers in the building:')  
while customers.isalpha() or customers.isspace() or int(customers) <0:  
    customers=raw_input('Please re enter a digit for number of customers:')  
count = 1  

class building:  
    def num_of_floors():    
        num_of_floors = floors      
    def customer_list():    
        customer_list = customers    
    def run(self):    
    def output(self):    
        print elevator.cur_floor    

class elevator:    
    def num_of_floors():    
        building.num_of_floors    
    def register_list():    
        register_list = []    
    def cur_floor(building):    
        cur_floor = 1    
    def direction(self):    
        if elevator.cur_floor == 1:    
            direction = up    
        if elevator.cur_floor == floors:    
            direction = down    
    def move(self):    
        if elevator.direction == up:    
            cur_floor +=1    
        if elevator.direction == down:    
            cur_floor -=1    
    def register_customer(self, customer):    
        register_list.append(customer.ID)    
    def cancel_customer (self, customer):    
        register_list.remove(customer.ID)    

class customer:    
    def cur_floor(customer):    
        cur_floor = random.randint(0,int(floors))    
    def dst_floor(customer):    
        dst_floor = random.randint(0,int(floors))    
        while dst_floor == cur_floor:    
            dst_floor = random.randint(0,int(floors))    
    def ID():    
        cust_id = count    
        count+=1    
    def cust_dict(cust_id,dst_floor):    
        cust_dict = {cust_id:dst_floor}    
    def in_elevator():    
        in_elevator = 0    
        if customer.ID in register_list:    
            in_elevator = 1    
    def finished():    
        if customer.ID not in register_list:    
            pass   

Related Solutions

Hi, I would like the numerical solution for this task so I can be able to...
Hi, I would like the numerical solution for this task so I can be able to model it in a kinetic modeling programme like Berkely Madonna (BM). This was the reason why I started my membership with Chegg Study but unfortunately, the solution to this problem was not available. I'm looking forward to hearing from you. you will find the task in de link below. With kind regards, Ahmed https://www.chegg.com/homework-help/comprehensive-problem-multiple-reactions-heat-effects-styren-chapter-12-problem-24qp-solution-9780132317160-exc in J.Snyder en B.Subramaniam, Chem. Eng. Sci., 49, 5585 (1994)....
CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
Hello! I have some problem wit this task. Comprehensive Problem 7-1 David and Darlene Jasper have...
Hello! I have some problem wit this task. Comprehensive Problem 7-1 David and Darlene Jasper have one child, Sam, who is 6 years old (birthdate July 1, 2013). The Jaspers reside at 4639 Honeysuckle Lane, Los Angeles, CA 90248. David's Social Security number is 577-11-3311, Darlene's is 477-98-4731, and Sam's is 589-22-1142. David's birthdate is May 29, 1986 and Darlene's birthday is January 31, 1988. David and Darlene's earnings and withholdings for 2019 are: David: Earnings from Apple Company (office...
Java Program to Fully Parenthesize an expression. Hi guys. I have a small task which I...
Java Program to Fully Parenthesize an expression. Hi guys. I have a small task which I cannot find the solution for. It involves expressions with Infix I'll need a Java Program to convert an expression, eg. 3+6*(x-y)+x^2 to ((3 + (6 * (x-y))) + (x ^ 2)) Kindly assist. Thanks
hi i do not know what is wrong with my python code. this is the class:...
hi i do not know what is wrong with my python code. this is the class: class Cuboid: def __init__(self, width, length, height, colour): self.__width = width self.__length = length self.__height = height self.__colour = colour self.surface_area = (2 * (width * length) + 2 * (width * height) + 2 * (length * height)) self.volume = height * length * width def get_width(self): return self.__width def get_length(self): return self.__length def get_height(self): return self.__height def get_colour(self): return self.__colour def set_width(self,...
Hi. I am running into trouble solving the problem below and would greatly appreciate a step-by-step...
Hi. I am running into trouble solving the problem below and would greatly appreciate a step-by-step explanation on how to arrive at the correct answers and explanations: SHIELD, Inc., uses a standard costing system and develops its overhead rates from the current annual budget. The budget is based on an expected annual output of 120,000 units requiring 480,000 direct labor hours. (Practical capacity is 500,000 hours.) Annual budgeted overhead costs total $787,200, of which $556,800 is fixed overhead. A total...
Hi , I want some information about age of nanotechnology
Hi , I want some information about age of nanotechnology
HI There, there is no solution for a problem that I am looking for. Advanced Accouting...
HI There, there is no solution for a problem that I am looking for. Advanced Accouting - Chapter 4, problem 30. Can you please assist? Thanks. Posada Company acquired 7,000 of the 10,000 outstanding shares of Sabathia Company on January 1, 2013, for $840,000. The subsidiary’s total fair value was assessed at $1,200,000 although its book value on that date was $1,130,000. The $70,000 fair value in excess of Sabathia’s book value was assigned to a patent with a 5-year...
Hi I am having the following problem. At the moment I am trying to create a...
Hi I am having the following problem. At the moment I am trying to create a bode plot for the following function. G(s)=(Ks+3)/((s+2)(s+3)) Note: Not K(s+2)! I then want to plot multiple bode plots for various values of K. Eg. 1,2,3, etc. I am having two separate issues. 1. How do I define the TF with a constant K in the location required (a multiple of s in the numerator) 2. How do I create multiple bode plots for values...
Hi! I am in an intro level Finance course and I am stuck on this problem....
Hi! I am in an intro level Finance course and I am stuck on this problem. Any help would be greatly appreciated. I am deciding on opening a restaurant. I was able to scrape together some capital from friends and family, but I must pay them back in 4 years at 12% per annum. I figure that it will cost me $165,000 to start up with rent, deposits, equipment, salaries, chicken, basil, rice, etc. for the first year, but I...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT