0% found this document useful (0 votes)
62 views2 pages

Pancakehousemenu Java

This document defines a MenuItem class with properties for name, description, vegetarian status, and price and getters for these properties. It also defines PancakeHouseMenu and DinerMenu classes that extend MenuItem and include methods for adding menu items to a list and retrieving the list of menu items. The document also specifies methods expected of a Java-enabled waitress class for printing full or filtered menus.

Uploaded by

api-251901021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views2 pages

Pancakehousemenu Java

This document defines a MenuItem class with properties for name, description, vegetarian status, and price and getters for these properties. It also defines PancakeHouseMenu and DinerMenu classes that extend MenuItem and include methods for adding menu items to a list and retrieving the list of menu items. The document also specifies methods expected of a Java-enabled waitress class for printing full or filtered menus.

Uploaded by

api-251901021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

public class MenuItem { String name; String description; boolean vegetarian; double price; public MenuItem(String name, String

description, boolean vegetarian, double price) { this.name = name; this.description = description; this.vegetarian = vegetarian; this.price = price; } public String getName() { return name; } public String getDescription() { return description; } public double getPrice() { return price; } public boolean isVegetarian() { return vegetarian; }

PancakeHouseMenu.java
import java.util.ArrayList; public class PancakeHouseMenu { ArrayList menuItems; public PancakeHouseMenu() { menuItems = new ArrayList(); addItem("K&B's Pancake Breakfast", "Pancakes with scrambled eggs, and toast", true, 2.99); addItem("Regular Pancake Breakfast", "Pancakes with fried eggs, sausage", false, 2.99); addItem("Blueberry Pancakes", "Pancakes made with fresh blueberries, and blueberry syrup", true, 3.49); addItem("Waffles", "Waffles, with your choice of blueberries or strawberries", true, 3.59);

public void addItem(String name, String description, boolean vegetarian, double price) {

MenuItem menuItem = new MenuItem(name, description, vegetarian, price); menuItems.add(menuItem);

public ArrayList getMenuItems() { return menuItems; } } // other menu methods here

DinerMenu.java
public class DinerMenu { static final int MAX_ITEMS = 6; int numberOfItems = 0; MenuItem[] menuItems; public DinerMenu() { menuItems = new MenuItem[MAX_ITEMS]; addItem("Vegetarian BLT", "(Fakin') Bacon with lettuce & tomato on whole wheat", true, 2.99); addItem("BLT", "Bacon with lettuce & tomato on whole wheat", false, 2.99); addItem("Soup of the day", "Soup of the day, with a side of potato salad", false, 3.29); addItem("Hotdog", "A hot dog, with saurkraut, relish, onions, topped with cheese", false, 3.05); addItem("Steamed Veggies and Brown Rice", "Steamed vegetables over brown rice", true, 3.99); addItem("Pasta", "Spaghetti with Marinara Sauce, and a slice of sourdough bread", true, 3.89);

public void addItem(String name, String description, boolean vegetarian, double price) { MenuItem menuItem = new MenuItem(name, description, vegetarian, price); if (numberOfItems >= MAX_ITEMS) { System.err.println("Sorry, menu is full! Can't add item to menu"); } else { menuItems[numberOfItems] = menuItem; numberOfItems = numberOfItems + 1; } } public MenuItem[] getMenuItems() { return menuItems; } } // other menu methods here

Java-Enabled Waitress Specification printMenu() prints every item on the menu printBreakfastMenu() prints just breakfast item printLunchMenu() prints just lunch items printVEgetarianMenu() prints all vegetarian menu items isItemVegetarian(name) given the name of an item, returns true if the items is vegetarian, otherwise, returns false

You might also like