Question: Can you do Question 2 in Java for me please. Implement the FileManager class. Methods in this class are static and the class has no

Can you do Question 2 in Java for me please.

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.

FileManager class UML diagram

+readItems(fileName:String):ArrayList,MenuItem>

+writeMenus(filename:String, menus:ArrayList

)

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, entre, side, or beer. The format of a line in file, dishes.txt, is:

name of dish@@type of dish@@description of the dish@@calories@@price

Where the type of the dish is an appetizer, entre, side, or beer (Look at the file, dishes.txt). The type of dish determines what kind object to create, which class to use: Appetizer, Entre, 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 ArrayListmenus. You are free of choosing the format in which the data is written, but for each Menu in the ArrayList, all info 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.

Class MenuItem is defined as the superclass for Appetizer, Entre, Side, and Beer (All 4 classes extend MenuItem). As a result, the fields and getters/setters previously defined are moved to MenuItem. Implement the class MenuItem.

UML class diagram:

MenuItem

-name:String

-description:String

-calories:int

-price:double

+MenuItem(name:String, desc:String, cal:int, price:double)

Make Appetizer, Entre, Side, and Beer classes extend MenuItem 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, Entre, 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 in order to return the name of the menu.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!