Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MenuTester.java public class MenuTester { public static void main(String[] args) { Menu menu = new Menu(); menu.addOption(Lasagna); menu.addOption(Pizza Diavolo); menu.addOption(Pizza Magherita); menu.addOption(Pizza Sicilian); menu.addOption(Chicken Parmigiana);


MenuTester.java


public class MenuTester
{
public static void main(String[] args)
{
 Menu menu = new Menu();
 
 menu.addOption("Lasagna");
 menu.addOption("Pizza Diavolo");
 menu.addOption("Pizza Magherita");
 menu.addOption("Pizza Sicilian");
 menu.addOption("Chicken Parmigiana");
 menu.addOption("Chicken Linguine");
 
 menu.print();
 System.out.println("Expected:1. Lasagna2. Pizza Diavolo3. Pizza Magherita4. Pizza Sicilian5. Chicken Parmigiana6. Chicken Linguine");
 
 
 System.out.println(menu.getOption(2));
 System.out.println("Expected:Pizza Diavolo");
 
 System.out.println(menu.getOption(8));
 System.out.println("Expected:");
 
}
}


Menu.java

import java.util.ArrayList;

/**
A class that keeps track of a dynamic menu.
*/
public class Menu
{
private ArrayList menuItems;


/**
Constructs a menu with no options.
 */
public Menu()
{
//-----------Start below here. To do: approximate lines of code = 1
// initialize menuItems to an empty array list of Strings

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

/**
Adds a new menu item to the end of this menu.
@param item the menu item to add
 */
public void addOption(String item)
{
//-----------Start below here. To do: approximate lines of code = 1
// simply add the given item to the end of the array list

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

/**
Displays the menu, with options numbered starting with 1. (i.e. not 0)

@return the number that the user supplied
 */
public void print()
{
//-----------Start below here. To do: approximate lines of code = 3
// for each item in the menu, print the menu item number (add 1 to the item number index in the array list)
// followed by a ". " followed by the item name.





//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

public String getOption(int itemNum)
{
//-----------Start below here. To do: approximate lines of code = 3
// given an item number (indexed from 1) if it is a valid item number,
// return the item in the menu corresponding to this item number.
// If the item number is not valid, return a ""




//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
}


P.s: include screenshots of outputs to double-check that the program runs smoothly

A class that keeps track of a changing menu. See the following files: * MenuTester.java * Menu.java (has todo) Approximate total lines of code required: 8

Step by Step Solution

3.41 Rating (145 Votes )

There are 3 Steps involved in it

Step: 1

MenuTesterjava public class MenuTester public static void mainString args Menu menu new Menu menuaddOptionLasagna menuaddOptionPizza Diavolo menuaddOp... 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_2

Step: 3

blur-text-image_3

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

Principles of Accounting

Authors: Belverd Needles, Marian Powers, Susan Crosson

10th edition

618736611, 978-1111809508, 111180950X, 978-0618736614

More Books

Students also viewed these Programming questions

Question

=+b) Cut the runs to 8 by testing only in hot water.

Answered: 1 week ago