Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PYTHN Question 3 - 20 Marks Create a class called SupermarketQueue in this file. This class will replicate how a queue at a supermarket
PYTHN """ Question 3 - 20 Marks Create a class called SupermarketQueue in this file. This class will replicate how a queue at a supermarket cashier operates. Create a constructor that takes no arguments. The class should have one private instance variable called 'queue' which is of type deque. The constructor should instantiate an empty deque. You will need to import deque from collections. Create a getter property for the queue variable. Create a method called add_to_queue that takes one argument 'customer', a tuple, that represents the name of a customer in position 0 (a string) and the number of items that customer has in position 1 (an integer). The method should add the customer to the end of the queue deque. The method should return nothing, but print some feedback 'Customerjoined queue'. Create a method called serve that takes no arguments. The method should remove the customer at the beginning of the queue to mimic serving them at the cash register. The method should return nothing, but print some feedback 'Serving customer '. Create a __str__ method that returns a string representing all the customer names in the queue, from first to last, in the format: 1: with items 2: with items n: with items Create a method called rearrange_queue that takes no arguments. This method should change the queue instance variable so that the order of the customers in the original queue is reorganised so that the customer with the fewest items is first, ascending to the customer with the most items last. YOUR_NAME YOUR_ID <<<< CHANGE THESE Resources (You can visit this website only. You cannot click links on the webpage): https://docs.python.org/3/howto/sorting.html """ # DEFINE YOUR CLASS HERE if __name__ == '__main__': supermarketQueue = SupermarketQueue() supermarketQueue.add_to_queue(('Johnny', 6)) # Customer Johnny joined queue supermarketQueue.add_to_queue(('Sally', 20)) # Customer Sally joined queue supermarketQueue.add_to_queue(('Nevine', 11)) # Customer Nevine joined queue print('Correct queue?', supermarketQueue.queue == deque([('Johnny', 6), ('Sally', 20), ('Nevine', 11)]), ' ') supermarketQueue.serve() # Serving customer Johnny print('Correct queue?', supermarketQueue.queue == deque([('Sally', 20), ('Nevine', 11)]), ' ') supermarketQueue.add_to_queue(('Diego', 7)) """ 1: Sally with 20 items 2: Nevine with 11 items 3: Diego with 7 items """ print(supermarketQueue, ' ') supermarketQueue.rearrange_queue() """ 1: Diego with 7 items 2: Nevine with 11 items 3: Sally with 20 items """ print(supermarketQueue)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started