Skip to main content

Section 14.1 Starter Level

Subsection 14.1.1 Overview

In this exercise, you will work with a Java program that simulates a restaurant menu. A 2D array stores multiple dishes, each of which are put in 3 different categories: appetizers, entrees, and desserts. You must implement displayMenu and displayCategory. These methods are responsible for displaying the entire menu and specific categories of the menu, respectively.

Subsection 14.1.2 Structure of the 2D Array

The menu 2D array is an array of String, where each sub-array represents a category of the menu. The first element of each sub-array is the name of the category.
  • menu[0][0] contains "Appetizers", menu[1][0] contains "Entrees" and menu[2][0] contains "Desserts "
The subsequent elements in each sub-array are the food items that belong to that category.
  • For example, in the Entrees category, menu[1][1] is "Steak", menu[1][2] is "Stir-Fry" and menu[1][3] is "Porkchops".
Here is a visual representation of the menu 2D array:
Table 14.1.1.
Appetizers menu[0][0] Deviled Eggs menu[1][1] Nachos menu[1][2] Salad menu[1][3]
Entrees menu[1][0] Steak menu[2][1] Stir-Fry menu[2][2] Porkchops menu[2][3]
Dessert menu[2][1] Key-Lime Pie menu[3][1] Raspberry Tarts menu[3][2] Sundae menu[3][3]

Subsection 14.1.3 Instructions

  1. Implement the displayMenu method
    • This method should iterate through the menu array and print all their categories along with their respective dishes
    • Each dish should be printed on a new line and each category should be visually separated in the output
  2. Implement the displayCategory method
    • This method accepts the menu 2D array and an integer category, which represents the index of the category to be displayed (0 for Appetizers, 1 for Entrees, 2 for Desserts).
    • displayCategory will display the chosen category and its dishes in the same format similar to displayMenu, but only for the specified category.
The expected output is:
-- Menu -- 
Category: Appetizers
Deviled Eggs
Nachos
Salad

Category: Entrees
Steak
Stir-Fry
Porkchops

Category: Desserts
Key-Lime Pie
Raspberry Tarts
Sundae

TEST: Printing entrees...
Category: Entrees
Steak
Stir-Fry
Porkchops
You have attempted of activities on this page.