Design a menu class and associated iterator classes

Assignment Help JAVA Programming
Reference no: EM131434764

Assignment

PROBLEM

You are to design and implement a Menu class, and associated iterator classes, that maintains a collection of MenuItem objects. A MenuItem object contains the following information about each menu item of a particular restaurant.

• Item name (e.g., "prime rib", "key lime pie")
• Category (appetizer, main dish, dessert)
• Heart healthy
• Price

The Menu class must provide getter (factory) methods for producing the following types of iterators:

• AllItemsIterator
Iterates over all of the items on the menu

• ItemIterator
Iterates over a specified item type (appetizer, main dish, or dessert)

• HeartHealthyIterator
Iterates over the heart healthy items on the menu

• PriceIterator
Iterates over the main dishes that are under a specified price

In addition, the Menu class should provide the following static constants: public static final int APPETIZERS = 1;
public static final int MAIN_DISH = 2; public static final int DESSERT = 3;

These are to be passed as an argument when requesting an ItemIterator (see below). You might also include,
public static final boolean HEART_HEALTHY = true; public static final boolean NOT_HEART_HEALTHY = false;

passed when adding new items to the menu (through use of the add method).

APPROACH

You may implement the Menu class any way that you wish (array, ArrayList, LinkedList, etc.). The class should also provide methods for adding and deleting items on the menu. The add method is to be passed a MenuItem object to append to the end of the list of menu items. The delete method is to be passed an iterator pointing to the MenuItem to be deleted. (We do not care about adding menu items other than at the end.)

A natural way to handle the deletion of menu items is to request an AllItemsIterator from the menu and display each menu item one-by-one as the user hits return. When the menu item is displayed that is to be deleted, a response of 'd' (instead of hitting just the return key) can indicate to delete the current item displayed. The iterator object can then be passed to the delete method of the menu object, since it would be pointing to the menu item to delete.

Your client code should be written to first populate a menu with a number of menu items,

Menu eatAtJoesMenu = new Menu();

eatAtJoesMenu.add("Lobster Dinner", Menu.MAIN_DISH, Menu.NOT_HEART_HEALTHY, "24.99"); eatAtJoesMenu.add("Rice Pudding", Menu.DESSERT, Menu.NOT_HEART_HEALTHY, "3.50");
etc.

The Menu class must provide "getter" methods (factory methods) for each of the types of iterators. For example, the getter for obtaining a menu iterator that iterates over all of the menu items would have the following function signature,

public MenuIterator getAllItemsIterator()

And the function signature for obtaining an iterator that iterates over a specific item type would be, public MenuIterator getMenuItemIterator(int item_type)

which would be requested from the client code as follows (for Menu object menu),
MenuIterator itr = eatAtJoesMenu.getMenuItemIterator(Menu.APPETIZERS)

So for example, when the client code of the Menu class wants to iterate over all of the menu items, the iterator would be retrieved and used as follows,

MenuItem item;
MenuIterator itr = eatAtJoesMenu.getAllItemsIterator();
System.out.println("ALL MENU ITEMS"); while (itr.hasNext())
{
item = itr.next();
System.out.println(item.getName() + " $" + item.getPrice());
}

When the client code wants to iterate over just the main dishes, the iterator would be retrieved and used as follows,

MenuIterator itr = eatAtJoesMenu. getItemIterator(Menu.MAIN_DISH); System.out.println("MAIN DISHES");
while (itr.hasNext())
{
item = itr.next();
System.out.println(item.getName() + " $" + item.getPrice());
}

When client code wants to iterate only over heart healthy items,
MenuIterator itr = eatAtJoesMenu. getHeartHealthyIterator(); System.out.println("ALL HEART HEALTHY MENU ITEMS");
while (itr.hasNext())
{
item = itr.next();
System.out.println(item.getName() + " $" + item.getPrice());
}

When the client code wants to iterate over only dessert items,
MenuIterator itr = eatAtJoesMenu. getItermIterator(Menu.DESSERTS); System.out.println("ALL DESSERT MENU ITEMS");
while (itr.hasNext())
{
item = itr.next();
System.out.println(item.getName() + " $" + item.getPrice());
}

When the client code wants to iterate over only items under a certain price,
MenuIterator itr = eatAtJoesMenu. getPriceterator("15.00"); System.out.println("ALL ITEMS UNDER $15.00");
while (itr.hasNext())
{
item = itr.next();
System.out.println(item.getName() + " $" + item.getPrice());
}

Note that each of the while loops above are identical. The particular iterator that each is using is what is different.

Each of the Menu iterators should implement the following interface, which should also be defined,

public interface MenuIterator
{
// returns true if items of appropriate type left in list public boolean hasNext();

// returns current item and advances to next item public MenuItem next();
}

USE OF INNER CLASSES

The client code should not be given the ability to create MenuIterator objects on its own (but instead obtain such objects by use of the provided factory methods of the Menu class). One way to control access is by making the iterator classes private classes of the Menu class. (To do this, just declare each iterator class within the Menu class, with modifier private.) Such inner classes have access to the private data of the surrouding class (the Menu class). The surrounding class also has access to the private members of each of the inner classes.

PROGRAM TO CREATE

Create a program that will perform each of the following. Note that you may hard code menu items in the program so that you do not need to add menu items to an empty menu each time you execute the program.

1 - Display all menu items
2 - Display all appetizers
3 - Display all main dishes
4 - Display all desserts
5 - Display all hearty healthy items
6 - Display all main dishes under a specified price
7 - Add menu item
8 - Remove menu item

Each of the source files,must be in one zipped file.

Reference no: EM131434764

Questions Cloud

Future and consider possible trends in society-echnology : Look into the future and consider possible trends in society, technology, economics, environmentalism, and politics that could influence Proctor and Gamble. Be sure to look beyond this firm's current market, product, and geographic boundaries.
Write code to perform k-means clustering on the values : Write code to perform k-means clustering on the values in the matrix 'dat'. The true group labels are provided in the vector 'true_groups'. Of course, you can't use that until the very end where you will perform some verification
Inheritance to purchase four us treasury bonds : Having spent several years in the bank's investments department, he's well aware of the concept of duration and decides to apply it to his bond portfolio. In particular, Elliot intends to use $1 million of his inheritance to purchase four U.S. Tre..
Drive-through window for customer pickups : A pizza place is considering opening a drive-through window for customer pickups. It is estimated that at peak times (6-9pm and 1-3am), customers will arrive at a rate of 11 per hour. The clerk who will staff the window can serve customers at the rat..
Design a menu class and associated iterator classes : You are to design and implement a Menu class, and associated iterator classes, that maintains a collection of MenuItem objects. A MenuItem object contains the following information about each menu item of a particular restaura..
Field office or risk losing best customer : From the Steps in the Purchasing Procedure reading, imagine you are in a hurry to get the latest, expensive equipment for your field office or risk losing your best customer. Indicate which two of the eight steps you might expedite - but not overl..
Implications of the phrase from behind the veil : Though many Arab women wear veils, jacoby is not simply referring to their attire in his title. explain the metaphoric implications of the phrase from behind the veil
Payment on a house : Jeremy Denham plans to save $4,896 every year for the next eight years, starting today. At the end of eight years, Jeremy will turn 30 years old and plans to use his savings toward the down payment on a house.
What type of air mass will be created if a batch of air sits : What type of air mass will be created if a batch of air sits over the equatorial pacifc ocean for a few days?What is the symbol for this air mass.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd