Question: An automatic ham sandwich maker uses a set of programmed ingredients to make sandwiches. First, users select the size of the sandwich, then the machine
An automatic ham sandwich maker uses a set of programmed ingredients to make sandwiches. First, users select the size of the sandwich, then the machine determines how much resources are available before making it. The user receives a message if there are insufficient resources. Otherwise, the user must pay for sandwich by coins. The machine will indicate if insufficient coins are inserted or if there is an exchange amount when coins are inserted. Also, on the screen, users can view the remaining resources report and turn off the machine.
1- Prompt user "What would you like? (small/ medium/ large/ off/ report)" small, medium, large: Check the resources and decide what to do next. off: Turn off the machine, report: A report should be generated that shows the current resource values. After the sandwich is dispensed, the prompt should display again to serve the next customer once the order has been completed. 2- Check that the resources are sufficient. Program should check whether there are enough resources to make the sandwich when the user chooses it. For example, if a small size ham sandwich requires 4 slices of bread but there are only 2 slices left, the machine should stop the process and return the following message: Sorry there is not enough bread. Resources is a dictionary with these initial values: resources = { "bread": 12, ## slice "ham": 18, ## slice "cheese": 24 ## ounces } 3- Process the inserted coins: The machine accepts large dollar ($1), half dollar ($0.5), quarter ($0.25) and nickel ($0.05) coins. If there are sufficient resources to make the drink selected, then the program should prompt the user to insert coins. Using the coins inserted, calculate their monetary value. 4- Has the transaction been successful? Make sure the user has inserted enough money to purchase the sandwich they have selected. IF there is not enough money, machine returns Sorry, thats not enough money. Money refunded. The machine should offer change if the user has inserted too much money by returning the following message: Here is $x in change 5- Make sandwich: The ingredients for the sandwich should be deducted from machine resources if the transaction is successful.
Once all resources have been deducted, returns the following message: sandwich is ready. Bon appetit!. (You should include the size of ordered sandwich in this message)
THE PROVIDED CODE:
recipes = { "small": { "ingredients": { "bread": 2, ## slice "ham": 4, ## slice "cheese": 4, ## ounces }, "cost": 1.75, }, "medium": { "ingredients": { "bread": 4, ## slice "ham": 6, ## slice "cheese": 8, ## ounces }, "cost": 3.25, }, "large": { "ingredients": { "bread": 6, ## slice "ham": 8, ## slice "cheese": 12, ## ounces }, "cost": 5.5, } } resources = { "bread": 12, ## slice "ham": 18, ## slice "cheese": 24, ## ounces } ### Complete functions ### class SandwichMachine: def __init__(self, machine_resources): """Receives resources as input. Hint: bind input variable to self variable""" self.machine_resources = machine_resources def check_resources(self, ingredients): """Returns True when order can be made, False if ingredients are insufficient.""" def process_coins(self): """Returns the total calculated from coins inserted. Hint: include input() function here, e.g. input("how many quarters?: ")""" def transaction_result(self, coins, cost): """Return True when the payment is accepted, or False if money is insufficient. Hint: use the output of process_coins() function for cost input""" def make_sandwich(self, sandwich_size, order_ingredients): """Deduct the required ingredients from the resources. Hint: no output""" ### Make an instance of SandwichMachine class and write the rest of the codes ###
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
