001package headfirst.iterator.dinermergercafe; 002 003import java.util.Iterator; 004 005@SuppressWarnings("rawtypes") 006public class DinerMenu implements Menu { 007 static final int MAX_ITEMS = 6; 008 int numberOfItems = 0; 009 MenuItem[] menuItems; 010 011 public DinerMenu() { 012 menuItems = new MenuItem[MAX_ITEMS]; 013 014 addItem("Vegetarian BLT", 015 "(Fakin') Bacon with lettuce & tomato on whole wheat", true, 2.99); 016 addItem("BLT", 017 "Bacon with lettuce & tomato on whole wheat", false, 2.99); 018 addItem("Soup of the day", 019 "Soup of the day, with a side of potato salad", false, 3.29); 020 addItem("Hotdog", 021 "A hot dog, with saurkraut, relish, onions, topped with cheese", 022 false, 3.05); 023 addItem("Steamed Veggies and Brown Rice", 024 "A medly of steamed vegetables over brown rice", true, 3.99); 025 addItem("Pasta", 026 "Spaghetti with Marinara Sauce, and a slice of sourdough bread", 027 true, 3.89); 028 } 029 030 public void addItem(String name, String description, 031 boolean vegetarian, double price) 032 { 033 MenuItem menuItem = new MenuItem(name, description, vegetarian, price); 034 if (numberOfItems >= MAX_ITEMS) { 035 System.err.println("Sorry, menu is full! Can't add item to menu"); 036 } else { 037 menuItems[numberOfItems] = menuItem; 038 numberOfItems = numberOfItems + 1; 039 } 040 } 041 042 public MenuItem[] getMenuItems() { 043 return menuItems; 044 } 045 046 public Iterator createIterator() { 047 return new DinerMenuIterator(menuItems); 048 //return new AlternatingDinerMenuIterator(menuItems); 049 } 050 051 // other menu methods here 052}