Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. [12 points] Implement the FileManager class. Methods in this class are static and the class has no fields. We will not create objects of

2. [12 points] Implement the FileManager class. Methods in this class are static and the class has no fields. We will not create objects of this class, but use its static methods. In UML diagrams, static methods (and static variables) are underlined. FileManager class has methods for reading and writing files. See the figure below. The following method public static ArrayList readItems(String fileName) reads all types of dishes from a single file in which each line can be an appetizer, entree, side, or beer. The format of a line in file dishes.txt is name of dish@@type of the dish@@description of the dish@@calories@@price Where "type of the dish" is either appetizer, "entree", "side", or "beer" (Take a look to the file included dishes.txt). This "type of the dish" determines what kind of object to create, which class to use: Appetizer, Entree, Side, or Beer. Then the object is added to an ArrayList. Since all these classes extend MenuItem, objects of them can be "treated" generically as MenuItem objects. The method public static void writeMenu( String fileName, ArrayList

menus ) writes a file (use String fileName parameter) with the information of all the menus in the ArrayList menus. You are free of choosing the format in which the data is written, but for each Menu in the ArrayList, all information should be included: name of the menu, name of each dish, description of each dish, calories and price of each dish, plus the sum of all calories, and the total price.

3. [18 points] Class MenuItem is defined as the superclass for Appetizer, Entree, Side, and Beer (all these 4 classes extend MenuItem). As a result, the fields and getters/setters previously defined are moved to MenuItem. See the following diagram. Implement the class MenuItem. Make Appetizer, Entree, Side, and Beer classes extend MenuItem (as indicated in the figure) and remove from them all fields and Getters/Setters. The fields name, description, calories are now inherited. Add the field price and the corresponding getter and setter in the class MenuItem. Now all other classes extending MenuItem also inherit price. In all classes Appetizer, Entree, Side, and Beer make constructors to receive all field values and to call the super constructor. Override toString() in MenuItem in order to return the name attribute. Also, override toString() in class Menu (this class is defined in previous Assignment 4) in order to return the name of the menu. 4. [15 points] Implement the class MenuManager. A MenuManager object has an ArrayList of each of the type of dishes.

The constructor, as you can see in the following figure, receives a fileName. Read this file using the method readItems of the class FileManager and fill a single ArrayList of MenuItem. Now we need to separate the single ArrayList containing MenuItem objects into the four ArrayList of different types. To solve this, create the four ArrayList and implement a loop go through the single ArrayList and take every dish and put it in the right ArrayList. Hint: user instanceof operator. You can implement this task in a separate method and call it in the constructor. Implement the method randomMenu. The method creates a Menu object taking randomly one appetizer, one entree, one side, and one beer. The name of the menu is passed in the parameter String name.

[Optional: extra credit] Methods minCaloriesMenu() and maxCaloriesMenu() generates the lowest and highest calories menus, respectively. To do the minimum, you have to pick the Entree with the lowest calorie value among entrees. Same for appetizer, side and beer. The method maxCaloriesMenu() do similarly, but selecting highest calories dishes. Add getters and setters to all fields in MenuManager.

5. [45 points] Graphical User Interface. Build the following GUI. FIGURE 1. Main window implemented in class MenuManagerGUI

FIGURE 2. Secondary window for displaying the details of a Menu, also implemented in MenuManagerGUI class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions