SlideShare a Scribd company logo
1
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”)
The Menu class must provide getter (factory) methods for
producing the following types of iterators:
Iterates over all of the items on the menu
Iterates over a specified item type
(appetizer, main dish, or dessert)
Iterates over the heart healthy items on the menu
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).
2
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());
}
3
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.
4
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.

More Related Content

PDF
Lecture-10-Menus.pdf of Mobile Application Development
PDF
Android ui menu
DOCX
project_additionsCuisineType.javaproject_additionsCuisineType..docx
PDF
Intake 38 8
PDF
Intake 37 8
PPT
Menu bars and menus
PPT
android menus
DOCX
c programming 109.docx
Lecture-10-Menus.pdf of Mobile Application Development
Android ui menu
project_additionsCuisineType.javaproject_additionsCuisineType..docx
Intake 38 8
Intake 37 8
Menu bars and menus
android menus
c programming 109.docx

Similar to 1 PROBLEM You are to design and implement a Menu class.docx (20)

PPTX
Module iii part i
PPT
360 Flex Atlanta
DOCX
Android menus in android-chapter15
PPTX
Menu stripe
PPTX
Menu in Android (Define,Create,Inflate and Click Handler)
PPTX
Android Lab Test : Creating a menu dynamically (english)
PDF
Chapt 04 user interaction
PPSX
Aula 6 - 08/05 (Menu)
PDF
Android session 3
PPTX
DOC-20230724-WA0011..pptxyffhjingtrfhiijh
PPT
Drupal Menu System
PPT
DRUPAL Menu System
PDF
01 10 - graphical user interface - others
PPTX
Java me lab2-slides (gui programming)
DOCX
ObjectivesUse inheritance to create base and child classes.docx
PDF
Extracting ui Design - part 5 - transcript.pdf
PPT
engineeringdsgtnotesofunitfivesnists.ppt
PDF
INTRODUCTION The goal of this programming project is to entble studen.pdf
PPT
Unit 5.133333333333333333333333333333333.ppt
PDF
someone help Python programming After the loop ends, return the expe.pdf
Module iii part i
360 Flex Atlanta
Android menus in android-chapter15
Menu stripe
Menu in Android (Define,Create,Inflate and Click Handler)
Android Lab Test : Creating a menu dynamically (english)
Chapt 04 user interaction
Aula 6 - 08/05 (Menu)
Android session 3
DOC-20230724-WA0011..pptxyffhjingtrfhiijh
Drupal Menu System
DRUPAL Menu System
01 10 - graphical user interface - others
Java me lab2-slides (gui programming)
ObjectivesUse inheritance to create base and child classes.docx
Extracting ui Design - part 5 - transcript.pdf
engineeringdsgtnotesofunitfivesnists.ppt
INTRODUCTION The goal of this programming project is to entble studen.pdf
Unit 5.133333333333333333333333333333333.ppt
someone help Python programming After the loop ends, return the expe.pdf
Ad

More from honey725342 (20)

DOCX
NRS-493 Individual Success PlanREQUIRED PRACTICE HOURS 100 Direct.docx
DOCX
Now the Earth has had wide variations in atmospheric CO2-level throu.docx
DOCX
NR224 Fundamentals SkillsTopic Safety Goals BOOK P.docx
DOCX
Nurse Education Today 87 (2020) 104348Contents lists avail.docx
DOCX
Now that you’ve seen all of the elements contributing to the Devil’s.docx
DOCX
NR360 We Can But Dare We.docx Revised 5 ‐ 9 .docx
DOCX
Nurse Practitioner Diagnosis- Chest Pain.SOAPS-Subjective.docx
DOCX
NURS 6002 Foundations of Graduate StudyAcademic and P.docx
DOCX
Nurse workforce shortage are predicted to get worse as baby boomers .docx
DOCX
Now, for the exam itself. Below are 4 questions. You need to answer .docx
DOCX
Nur-501-AP4- Philosophical and Theoretical Evidence-Based research.docx
DOCX
NU32CH19-Foltz ARI 9 July 2012 1945Population-Level Inter.docx
DOCX
Nurse Working in the CommunityDescribe the community nurses.docx
DOCX
nursing diagnosis1. Decreased Cardiac Output  related to Alter.docx
DOCX
Nursing Documentation Is it valuable Discuss the value of nursin.docx
DOCX
NR631 Concluding Graduate Experience - Scope Project Managemen.docx
DOCX
Number 11. Describe at least five populations who are vulner.docx
DOCX
ntertainment, the media, and sometimes public leaders can perpetuate.docx
DOCX
Now that you have  completed Lesson 23 & 24 and have thought a.docx
DOCX
nothing wrong with the paper, my professor just wants it to be in an.docx
NRS-493 Individual Success PlanREQUIRED PRACTICE HOURS 100 Direct.docx
Now the Earth has had wide variations in atmospheric CO2-level throu.docx
NR224 Fundamentals SkillsTopic Safety Goals BOOK P.docx
Nurse Education Today 87 (2020) 104348Contents lists avail.docx
Now that you’ve seen all of the elements contributing to the Devil’s.docx
NR360 We Can But Dare We.docx Revised 5 ‐ 9 .docx
Nurse Practitioner Diagnosis- Chest Pain.SOAPS-Subjective.docx
NURS 6002 Foundations of Graduate StudyAcademic and P.docx
Nurse workforce shortage are predicted to get worse as baby boomers .docx
Now, for the exam itself. Below are 4 questions. You need to answer .docx
Nur-501-AP4- Philosophical and Theoretical Evidence-Based research.docx
NU32CH19-Foltz ARI 9 July 2012 1945Population-Level Inter.docx
Nurse Working in the CommunityDescribe the community nurses.docx
nursing diagnosis1. Decreased Cardiac Output  related to Alter.docx
Nursing Documentation Is it valuable Discuss the value of nursin.docx
NR631 Concluding Graduate Experience - Scope Project Managemen.docx
Number 11. Describe at least five populations who are vulner.docx
ntertainment, the media, and sometimes public leaders can perpetuate.docx
Now that you have  completed Lesson 23 & 24 and have thought a.docx
nothing wrong with the paper, my professor just wants it to be in an.docx
Ad

Recently uploaded (20)

PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Cell Types and Its function , kingdom of life
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
202450812 BayCHI UCSC-SV 20250812 v17.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Anesthesia in Laparoscopic Surgery in India
Cell Types and Its function , kingdom of life
102 student loan defaulters named and shamed – Is someone you know on the list?
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Final Presentation General Medicine 03-08-2024.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Microbial diseases, their pathogenesis and prophylaxis
Pharmacology of Heart Failure /Pharmacotherapy of CHF
human mycosis Human fungal infections are called human mycosis..pptx
O7-L3 Supply Chain Operations - ICLT Program
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Supply Chain Operations Speaking Notes -ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf

1 PROBLEM You are to design and implement a Menu class.docx

  • 1. 1 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”) The Menu class must provide getter (factory) methods for producing the following types of iterators: Iterates over all of the items on the menu Iterates over a specified item type (appetizer, main dish, or dessert)
  • 2. Iterates over the heart healthy items on the menu 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). 2 APPROACH You may implement the Menu class any way that you wish (array, ArrayList, LinkedList, etc.). The class
  • 3. 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()
  • 4. 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()); } 3 When the client code wants to iterate over just the main dishes, the iterator would be retrieved and used as follows,
  • 5. 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());
  • 6. } 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. 4 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
  • 7. 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
  • 8. 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.