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

  Write an application that prompts a user for a month

Write an application that prompts a user for a month, day, and year. Display a message that specifies whether the entered date is not this year, in an earlier month this year, in a later month this year, or this month.

  1 securityimplement security so that all users can view the

1. security.implement security so that all users can view the information about the projects but only authenticated

  Design and implement a java program that will gather info

Design and implement a Java program that will gather a user's first name, middle initial, lastname, age in years, and 3 lucky numbers. The program should output the following based on the user's input

  Java class that represents your favorite musical instrument

Create your own Java class that represents your favorite musical instrument. Your musical instrument class should have at least 3 constants, 5 private data fields, getters and setters for each private data field, a to String() method, and three ad..

  Create an array of objects of the sub-class

Create an array of objects of the sub-class. Add two objects to the array. Loop through the array and print what each element is constructed from.

  Create an employee class.

Create an Employee class. Items to include as data members are employee number, name, date of hire, job description, department, and monthly salary.

  Comparator that compares point objects by their distance

write a comparator that compares point objects by their distance from the origin of (0,0). points that are closer to the origin are considered to come before those which are further from the origin

  Question 1when you use the mvc pattern the controller

question 1when you use the mvc pattern the controller directs the flow of control toa. the browser and the modelb. the

  Write an interrupt service routine to output brand name

Evaluate the form of the output depended on the coefficients being input - Consider you would like to use PSoC to display a different brand name on the LCD once every 15 s.

  Employeeexception class whose constructor receives string

Create an EmployeeException class whose constructor receives a String that consists of an employee's ID and pay rate. Save the file as EmployeeException.java.

  Program to convert fahrenheit to celsius

Layout the planned structure and steps to accomplish the individual programs. Ensure brief, accurate and complete detailed instructions in the form of pseudocode, not code. Construct two brief explanations for the pseudocode. Provide both programs..

  Program designs used in developing java applications

program designs used in developing Java applications

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