MenuTester.java public class MenuTester { public static void main(String[] args) { Menu menu = new Menu(); menu.addOption(Lasagna);
Question:
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
Principles of Accounting
ISBN: 978-0618736614
10th edition
Authors: Belverd Needles, Marian Powers, Susan Crosson