Programming and Algorithms II Degree in Bioinformatics Fall 2018 ***************************************************************** *** Lab 7: *** *** Classes, objects, and inheritance, 2 *** ***************************************************************** We want to help a restaurant to keep track of its dishes and recipes and the popularity of each. 1. create a class Dish. A Dish contains a list of the ingredients and their quantities, a string containing the recipe, and a price. For example, for making the "bacon and eggs" dish you need - 100 grams of potatoes - 2 eggs - 3 slices of bacon so one could represent it as the list [("potatoes",100),("eggs",2),("bacon",3)] plus a (longish) string that explains how to actually make the dish, and a price such as 6.25. The Dish class has - a constructor that takes the dish name, a list as above, and the recipe, - an opertion set or change the price of the dish (it is 0 until set), - and three operations to retrieve the list of ingredients, the recipe, and the price. Note that the price can be changed, but the list of ingredients and the recipe cannot be changed after a Dish is created. 2. Create a class Bill that represents a Bill to a customer or group of customers. Intuitively, a Bill contains - an identifier, supposed to be unique for all Bills, - the list of pairs (dish name,quantity served). For example, a Bill could say that ("bacon and eggs",2), ("big fat omelette",3), ("fish and chips",1) were served. - the date of the Bill. To simplify, suppose that the date is an int, say the number of days since the restaurant opened, - and the amount of the Bill. Note that the Bill only knows the names of the dishes, not the full information of the dishes, so it cannot compute the total amount itself. Class Bill should have: - an operation to create it, with an id, a date, the list of dishes and quantities served, and the amount, - operations that, given the id, retrieve the date, the list of dishes+quantities, and the amount of the bill. 3. Create a class Restaurant that keeps track of: - the Dishes that can be ordered at the restaurant, - the set of Bills that the restaurant has served. Dishes can be added and removed over time. Bills can only be added (the Restaurant remembers all the Bills it has served since the day it started). We want the class Restaurant to have operations 3.1 to 3.8 below. Operations 3.1 to 3.7 should take time independent of the number of dishes and bills in the restaurant. 3.8 of course depends on the number of dishes. Note that some operations return values (and print nothing), others print stuff to the screen (and return nothing), and others change the Restaurant object (but print nothing and return nothing). Even for operations that return nothing, you may want to make it return some code (0, -1, -2, True, False, ...) to indicate whether the operation went well or if something wrong happened and the operation could not be completed. In the previous lab, made this part for you, told you what can go wrong with an operation and tell you what codes to return. Now it is your turn to do this analysis and specify what the operation returns in strange cases. You may want to modify and use the Menu class that we used in the previous lab (the Hospital) to test your implementation of the Restaurant. 3.1- create a restaurant with no dishes and no bills. 3.2- add a new dish to the restaurant menu, with its price and all. 3.3- given a dish name, delete the dish with that name from the restaurant menu 3.4- given a dish name, print to screen its name, list of ingredients, and recipe in a "nice" format like in cookbooks. 3.5- change the price of a dish that is currently in the restaurant menu. 3.6- add a bill to the restaurant. The value of the bill is computed as the sum of the current prices of the dishes it contains - and remains fixed for the Bill, even if the restaurant changes the dish prices. 3.7- given a bill id, print the contents of the bill to the screen (id, date, dishes and quantities, and amount). 3.8- print the menu of the restaurant: a list of all the current dish names with their prices. 4. After a while, the restaurant realizes that there are several features that are needed and are not present in this Restaurant class. Let us build a Restaurant2 restaurant that solves this problem. - the menu printed by operation 3.8 does not look good. Dishes should be printed in categories, such as appetizers, entrees, fish, meat, vegetarian, house specialities, desserts, drinks, etc. Change the operation to print menus in this nicer way. To do that, the following are required: - Restaurant2 needs to associate dishes to categories. One can extend Dish to Dish2 and have Dish2 contains a category. Or we can add to the restaurant something that relates dish (or dish names) to categories. Some operation to add/change the categories of a dish in the menu are required. To simplify, say that a dish can only have a category at any given time. - The operation to print the menu needs to know the categories there are, and the order in which they must be printed. Make an operation that gives the restaurant a list with the desired category order, such as ["appetizers", "entrees", "vegetarian", "fish", "meat", "desserts"]. Applying the operation allows the restaurant order to add and remove categories as time passes, and to reorder their order in the menu. - The restaurant needs to plan its shopping for the next week. The planning is done by taking statistics of the last weeks, and extrapolating to the next week. Suppose we want to consider the last W weeks. Then we can compute how much of each ingredient it has used in the dishes served in the last W weeks, or in the last W*7 weeks before today. Then it divides that quantity by W to estimate how much of that ingredient it is going to be required this week. For example, if the only dishes using eggs are "bacon and eggs" (uses 2 eggs) and "big fat omelette" (uses 3 eggs), and in the last 5 weeks we have served 1000 "bacon and eggs" and 300 "big fat omelettes", then we have used 1000*2 + 300*3 = 2900 eggs in the last 5 weeks, so we estimate that we are going to use 2900/5 = 580 eggs next week (let's round up for safety). So we include "580 eggs" in our shopping plan. Add a function to Restaurant2 that prints to screen the list of ingredients and the estimated quantites for next week. - Sometimes, picky customers arrive and say "do you have any dishes with ginger? Ginger is so refresing!" or "With truffle? I love truffles!" or "with shrimp?". We need a function that receives an ingredient name (such as "ginger") and returns a list with the names of the dishes currently in the menu that contain that ingredient. This operation should be fast, because these picky customers usually have very little patience. - Given two dates d1, d2 (two ints, with d1 <= d2), print the total amount of the bills generated between d1 and d2, both included. This is not something we look at every minute, so the operation can be relatively slow.