Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this homework. Implement the following classes as represented in the class diagrams. Methods and constructors are explained below. Classes Appetizer, Entree,

I need help with this homework.

Implement the following classes as represented in the class diagrams. Methods and constructors are explained below.

Classes Appetizer, Entree, Side and Beer are all similar, representing the parts of a menu.

Appetizer

Entree

-name:String

-name:String

-description: String

-description: String

-calories:int

-calories:int

+Appetizer(name: String, desc:String, cal:int)

+Entree(name: String, desc:String, cal:int)

Side

Beer

-name:String

-name:String

-description: String

-description: String

-calories:int

-calories:int

+Side(name: String, desc:String, cal:int)

+Beer(name: String, desc:String, cal:int)

Class Menu contains one object of each of the previously defined classes (Appetizer, Entree, Side and Beer) and a name.

Menu

-name: String

-appetizer:Appetizer

-entree :Entree

-side: Side

-beer:Beer

+Menu(name: String)

+Menu(name:String, entree:Entree, side:Side)

+Menu(name:String, entree:Entree, side:Side, appetizer:Appetizer, beer:Beer)

+totalCalories() : int

+description(): String

Methods in class Menu:

totalCalories(): sums the calories of all the parts of the menu (Beer, Appetizer, Entree and Side)

description() : concatenates the descriptions of the parts of the menu in order. First Appetizer, then Entree, then Side and lastly, Beer. It has to separate the descriptions by new lines and add the type and the name of each part of the menu. A menu could lack some of the parts, in this case, it has to indicate as N/A. For example:

Appetizer: Nachos. Literally three pounds of chips cheese and meat.

Entree: Pizza Margherita. The best kind of pizza.

Side: N/A

Beer: Augustiner. Get some gemtlichkeit today!

TIP: you can check if an object is null :

if(side == null) { something here! }

There are 3 constructors in class Menu setting some of the parts of the menu. All of them need the name of the menu (the name is always required). All parts that are not passed in the constructors should be set to null. For example, the first constructor Menu(String name) sets the name and then sets all other fields to null:

appetizer = null;

entree = null;

side = null;

beer = null;

Add getters and setters for all fields in all classes. Getters and setters are not included in the diagram and they are assumed.

Create a class MenuTest with a main method to test the Menu class. Create, for example, 2 entrees, 1 appetizer, 2 side and 1 beer and 2 Menu objects. Then fill the first menu with an entree and a side. Fill the second menu with the remaining: 1 entree, 1 side, 1 appetizer and 1 beer. Print out both menus, including the menu name, the total amount of calories and the description. Note that this is only to test the classes, so just make sure you try all the functionalities of Menu and other classes here.

Add comments to your classes. Add a comment just above the class definition (top of the file, but after imports and package lines) including your name (author) and date when created (created). Look at this example showing the JavaDoc format:

/**

* Class Entree

* author : Bill

* created: 02/10/2017

*/

Make sure your code is correctly indented.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions