You are to create a software design that simulates a fast food restaurant. You w
ID: 3840033 • Letter: Y
Question
You are to create a software design that simulates a fast food restaurant. You will have food items (hamburgers, hot dogs, chicken sandwiches) and drink items (Coke, sprite, root beer). The drinks come in various sizes given in ounces (for example: 12, 24, 48). Food items will be assigned a price when they are created but this price can be changed by the employee taking the items will be assigned according to the size of the drink. Which of the following would be the best choice for the design of this system? Why? a. The design should include the following classes: Hamburger, HotDog, Chicken, Coke, sprite, and RootBeer. b. The design should include the following classes: FoodItem with Hamburger, HotDog, and Chicken extending FoodItem and DrinkItem with Coke, sprite, and RootBeer extending DrinkItem. c. The design should include the following classes: Item with FoodItem and DrinkItem extending Item: Hamburger, HotDog, and chicken extending FoodItem; and DrinkItem with Coke, sprite, and RootBeer extending DrinkItem. d. The design should include the following classes: FoodItem and DrinkItem. The individual types of food and drink are only description of the food or drink and should not be separate classes. e. The design should include the following classes: Item with FoodItem and DrinkItem extending them. The individual types of food and drink are objects that are instances of these classes, not separate classes.Explanation / Answer
15 . The best choice of design will be e) The design should include the following classes: -
Item: - The parent class of all the items having common feature like a method for calculating price which can be overridden by the ItemType classes.
FoodItem: - The class extending item which have attribute itemType which can have value corresponding to Hamburger,sandwiches and hot dogs. They can override the method calculatePrice of Item and can have method to set the price also.
DrinkItem: - The class extending item which have attribute itemType which can be coke , sprite and root bear. It also has one atribute of size in ounces and cn override calculatePrice function of Item also.
The individual type of foods and drinks are not classes itself but the objects of these classes. As they are real world specific entities and can be generalized as FoodItem and DrinkItem. In the program individual objects of FoodItem and DrinkItem can be created with hamburger,hot dog, sandwiches and coke,sprite,root beer respectively.
This design will be best because it follows the main prinicipal of Object Oriented Programming and differentiate clearly between classes and objects.
Having classes for individual types of food is not favourable as it makes the system complex and suppose in future if restaurant wants to add more foodItems or drinkitems , they dont need to create classes for that , just modify the existing classes and it will work.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.