Question: Python 03 x6 Av Create a class called SupermarketQueue in this file. This class will replicate how a queue at a supermarket cashier operates. Create

Python 03 x6 Av 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 onePython

03 x6 Av 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 'Customer joined 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. # DEFINE YOUR CLASS HERE Fif __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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!