-
Notifications
You must be signed in to change notification settings - Fork 23
/
Waitress.java
53 lines (44 loc) · 1.65 KB
/
Waitress.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package Cafe;
import DinerAndPancakeHouseIterator.MenuItem;
import java.util.Iterator;
public class Waitress {
Menu pancakeHouseMenu;
Menu dinerMenu;
// the menu is passed into the Waitress in the constructor with the other
// and we stash it in an instance variable
Menu cafeMenu;
public Waitress(Menu pancakeHouseMenu, Menu dinerMenu, Menu cafeMenu) {
this.pancakeHouseMenu = pancakeHouseMenu;
this.dinerMenu = dinerMenu;
this.cafeMenu = cafeMenu;
}
public void printMenu() {
// creates one iterator for each menu
Iterator pancakeIterator = pancakeHouseMenu.createIterator();
Iterator dinerIterator = dinerMenu.createIterator();
Iterator cafeIterator = cafeMenu.createIterator();
System.out.println("MENU\n----\nBREAKFAST");
// then calls the overloaded printMenu() with each iterator
printMenu(pancakeIterator);
System.out.println("\nLUNCH");
printMenu(dinerIterator);
System.out.println("\nDINNER");
printMenu(cafeIterator);
}
/**
* Nothing changes here
* @param iterator
*/
private void printMenu(Iterator iterator) {
// test if there are any more items
while (iterator.hasNext()) {
// get the next item
MenuItem menuItem = (MenuItem)iterator.next();
// use the item to get name, price, and description and print them
System.out.print(menuItem.getName() + ", ");
System.out.print(menuItem.getPrice() + " -- ");
System.out.println(menuItem.getDescription());
}
}
// other methods here
}