QuestionQuestion

Part 1
Design and implement a class Menu which uses doubly linked lists as main data structures. A menu consists of main menu items, organized as a doubly linked list, each main menu item having associated a submenu, organized as a doubly linked list of submenu items (see an example of a Menu object in the file MenuExample.pdf posted below).

The class Menu should define a default constructor which builds an empty menu and the following methods:

addMainMenuItem, for adding a new main menu item with empty submenu. The method should have the following signature:
   
public boolean addMainMenuItem(String newItem, String existingItem, int position)

This method works in the following way:
(i) if parameter existingItem is null, the newItem will be added at the end of the list;
(ii) if the parameter existingItem is not null, the newItem will be added before existingItem if parameter position is -1 and after the existinItem if parameter position is 1;

deleteMainMenuItem, deletes the main menu item specified by name (supplied as method parameter);

addSubMenuItem, adds a submenu item specified by name to a main menu item specified by name (both names should be supplied as method parameters);


toString, traverses the linked lists data structures and generates the string representation of a menu object, organized on lines. Each line should include the main menu item followed by its submenu items. The items should be separated by a semicolon character. The toString method will be invoked from other programs (such as the driver of Part 2) to display the menu.

Notes.
1. For implementing the class Menu you may use either an appropriate data structure designed by you from scratch or the LinkedList data structure defined by JCF (Java Collection Framework).
2. If necessary, additionally methods may be defined for the class Menu. Give reasons for the new added methods. The class Menu.java should compile without errors.

Part 2
Write a driver program MenuTest.java to test the Menu class. In the driver program, do the following tasks:

a) Read menu items from the input file Menu.txt and build a menu object which includes the specified items. Each file line contains a main menu item followed by its submenu items, all items being separated by the semicolon character. After reading the file and building the menu, display the menu.

Example of the content of the input file Menu.txt:

File;New;Open;Save;SaveAs;Close;
View;Color;Gray;Zoom;Ruler;Grid;
Process;Select;Move;Rotate;Scale;Delete;Group;
About;Release;Version;Contact;Description;

In the example above, File, View, Process and About are the main menu items. In the example, the main menu item File has New, Open, Save, SaveAs and Close as its submenu items.

b) Add a new main menu item and its associated submenu before a main menu item specified by the user from the keyboard. Read the new main menu item and its submenu from the input file MenuAdd.txt. Using the toString method, display the menu after adding the new main menu item.

c) Delete a main menu item specified by the user. Using the toString method, display the menu after deleting the menu item.

d) Add a new main menu item and its associated submenu after a main menu item specified by the user from the keyboard. Read the main menu item and its submenu from the input file MenuAdd.txt. Using the toString method, display the menu after adding the new main menu item.

The input file MenuAdd.txt contains one line specifying the new main menu item and its submenu items.
Example of the content of the input file MenuAdd.txt for adding a new menu item

Layout;Margins;Orientation;Size;

The example above indicates that the main menu item Layout has the submenu items Margins, Orientation and Size.

Note. 1. The input files Menu.txt and MenuAdd.txt will be created by the students using a simple text editor (such as Notepad).2. Where appropriate, Part 2 tasks a – d should be accomplished by invoking the Menu class methods defined in Part 1.

Submission requirements

Submit the following before the due date listed in the Calendar:
1. Source files Menu.java and MenuTest.java and input files Menu.txt and MenuAdd.txt.
2. A document file (.pdf or .doc / .docx) containing: (2.1) a short question(s) analysis, (2.2) design decisions and assumptions, (2.3) test cases and two relevant screenshots, (2.4) error handling, (2.5) lessons learned and (2.6) possible improvements. The size of the document file (including the screenshots) should be of two pages, single spaced, font size 12.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class Menu {
   
    private Item root;
   
    /**
    * default constructor which builds an empty menu
    */
    public Menu() {
       root = null;
    }// end constructor
   
    /**
    * for adding a new main menu item with empty submenu
    * (i) if parameter existingItem is null, the newItem will be added at the end of the list;
    * (ii) if the parameter existingItem is not null, the newItem will be added before existingItem if parameter position is -1 and after the existinItem if parameter position is 1;
    * @param newItem
    * @param existingItem
    * @param position
    * @return
    */
    public boolean addMainMenuItem(String newItem, String existingItem, int position){
       Item t = null;
       // allocate new space
       t = new Item(newItem);
       if (t == null) {
            return false;
       }...
$70.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats