Imagine that you are asked to write code to support an automated system for taking fastfood restaurant orders, and to implement this for a particular fast-food restaurant of your chosing. The main class RestaurantProg runs a simple interactive interface for a user: to see menu items available to them at your fast food restaurant; to select one or more menu items and add them to their order; and to see a running total price of their order, which accounts for any discounts. Initially, RestaurantProg will only print a menu to screen. Until you complete Section 2, you do not need to edit RestaurantProg.
You have also been given a class Prices which gives you a simple way of converting int prices into Strings. You do not need to edit this class.
You should begin by completing the implementation of Menu, MenuItem and the subclasses of MenuItem, the requirements are described in more detail in Section 2. After which, you should attempt to implement Order, OrderEntry and the implementing classes of OrderEntry, the requirements are described in more detail in Section 3
A menu can contain different kinds of menu items, including main dishes, supplementary dishes and drinks. To capture this, you should complete the implementation of the Menu and MenuItem classes, as well as writing two additional classes MainDish and SupplementaryDish (each extends the MenuItemabstract class). The class Drink has already been implemented for you, and also extends the MenuItemabstract class.
You will need to write MainDish and SupplementaryDish from scratch. You can use Drink as an example of how to do so. However, you need to decide whether MainDish and SupplementaryDish are direct subclasses or whether you should structure the class hierarchy differently. Once you have implemented the classes in the section, you should be able to compile and run the code, and it will create an example menu then print it to the screen.
Look at the UML class diagram in Figure 1. This should the classes relevant to this part of the coursework. The green classes have already been implemented for you, but the yellow classes will require some implementation from you. In particular, you will need to implement MainDish and SupplementaryDish from scratch.
You do not have to make any changes to this class. MenuItem is an abstract class that represents items that can appear on the menu. Key methods in this class are:
Figure 1: A UML class diagram of the Menu class and its related classes and interfaces. see image.
The above methods are already implemented. Additionally, the standard getter methods, and the method getPaddedName have also been implemented for you. getPaddedName produces a fixed length string (24 characters) containing the MenuItems name, and is to help you write the toMenuLine method. There is no need to edit this class.
You will need to create this class and write all the specified methods. You may add any fields or additional methods you require. MainDish is a concrete subclass of MenuItem that represents main-dishes at the restaurant. As well as having an id, name and unit-price, a MainDish also records whether the dish is vegetarian or not. You must implement the constructor, an isVegi method, and the two abstract methods of MenuItem: getPrice and toMenuLine. The details of the required implementation are as follows:
MainDish main1 = MainDish("01", "Chicken Tikka", 450, false);
MainDish main2 = MainDish("07", "Mixed Vegetable Curry", 400, false);
should produce output similar to:
01: Chicken Tikka 1 at 4.50, 2 at 6.75, 3 at 9.00
07: Mixed Vegetable Curry v 1 at 4.00, 2 at 6.00, 3 at 8.00
You will need to create this class and write all the specified methods. You may add any fields or additional methods you require. SupplementaryDish is a concrete subclass of MenuItem that represents supplementary-dishes at the restaurant, such as rice and bread dishes. This is very similar to the MainDish class, having an id, name and unit-price, as well as recording whether the dish is vegetarian or not. As before, you must provide a constructor, an isVegi method, and implementations of the two abstract methods: getPrice and toMenuLine. The details of the required implementation are as follows:
A constructor that takes 4 arguments: id, name, unitPrice and vegetarian. All inputs have the same meaning as in MainDish.
SupplementaryDish supp1 = SupplementaryDish(
"12", "Plain Naan", 80, false);
SupplementaryDish supp2 = SupplementaryDish(
"13", "Keema Naan", 200, false);
12: Plain Naan v 0.80 for 1, then 0.64 each
13: Keema Naan 2.00 for 1, then 1.60 each
You do not have to make any changes to this class. Drink is a concrete subclass of MenuItem that represents drinks at the restaurant. As well as inheriting an id, name and unit-price, a Drink also records its volume as an int. Some details of the key methods are as follows:
This information is provided for information only. You do not need to edit this class. Look at the code or Figure 1 for more details.
You will need to edit this class. You may add any fields or additional methods you require.
Menu is a simple class for holding a collection of MenuItems, displaying them to screen, and selecting them based on their ids. Key methods that you will need to implement in this class are:
You will need to edit all the methods in the above list. A constructor and the toString method has been implemented for you.
Do not attempt this part until you have implemented the classes required by Section 2
You should now implement the classes that will allow customers to order items from the menu, and to keep track of these orders. Begin by looking at Figure 2. The classes in yellow will require some implementation from you. Those in green have been provided for you, and do not need any changes. To test your changes in this section you should uncomment the remaining code in RestaurantProg.
Figure 2: A UML class diagram of the Order class and its related classes and interfaces. see image.
This interface has been written for you and you should not make any changes to it
Any class that implements the OrderEntryinterface represents an entry in a customers order. As described below, this can be MenuItemOrder, which represents an order for one or more units of a given MenuItem. Alternatively, this can be a Voucher, which will give the customer money off their order if the total is high enough. You will need to implement MenuItemOrder from scratch, but Voucher has been written for you and may provide a useful example to help you.
You will need to create this class and write all the specified methods. You may add any fields or additional methods you require.
An object of type MenuItemOrder represents a customers desire to purchase one or more units of a particular MenuItem. This class implements the OrderEntryinterface
The menuItem field captures which MenuItem this order-entry corresponds to, and the quantity field captures the number of units desired. Key methods that you will need to implement in this class are:
You do not have to make any changes to this class. The Voucher class implements the OrderEntry class and represents a discount on the total price at the restaurant. A Voucher object has three fields:
Some details of the key methods are as follows:
This information is provided for information only. You do not need to edit this class. Look at the code or Figure 2 for more details.
Order is a simple class for holding a customers order in terms of a collection of OrderItems. It should display this order to screen, calculate the total price and do so taking account of any discounts. Key methods that you will need to implement in this class are:
A constructor and the toString method has been implemented for you.
You should use this code as a starting point for your system, but you will need to write additional files, e.g. classes etc, for your system. It is important that your final code compiles, and non-compiling code will be penalised.
There is more than one way to solve this problem, and where you meet the specification you will be given credit up to a maximum of 80%. Additional marks will be given for coding style and comments, up to a maximum of 20%. This includes, but is not limited to: good names for variables, appropriate use of control flow (e.g. for loops and if statements), meaningful and appropriate comments, minimising duplication of code, appropriate helper methods, and consistent formatting of code.