⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dinermenu.java

📁 深入浅出设计模式书中的源代码
💻 JAVA
字号:
package headfirst.iterator.dinermergercafe;import java.util.Iterator;public class DinerMenu implements Menu {	static final int MAX_ITEMS = 6;	int numberOfItems = 0;	MenuItem[] menuItems;  	public DinerMenu() {		menuItems = new MenuItem[MAX_ITEMS]; 		addItem("Vegetarian BLT",			"(Fakin') Bacon with lettuce & tomato on whole wheat", true, 2.99);		addItem("BLT",			"Bacon with lettuce & tomato on whole wheat", false, 2.99);		addItem("Soup of the day",			"Soup of the day, with a side of potato salad", false, 3.29);		addItem("Hotdog",			"A hot dog, with saurkraut, relish, onions, topped with cheese",			false, 3.05);		addItem("Steamed Veggies and Brown Rice",			"A medly of steamed vegetables over brown rice", true, 3.99);		addItem("Pasta",			"Spaghetti with Marinara Sauce, and a slice of sourdough bread",			true, 3.89);	}  	public void addItem(String name, String description, 	                     boolean vegetarian, double price) 	{		MenuItem menuItem = new MenuItem(name, description, vegetarian, price);		if (numberOfItems >= MAX_ITEMS) {			System.err.println("Sorry, menu is full!  Can't add item to menu");		} else {			menuItems[numberOfItems] = menuItem;			numberOfItems = numberOfItems + 1;		}	} 	public MenuItem[] getMenuItems() {		return menuItems;	}  	public Iterator createIterator() {		return new DinerMenuIterator(menuItems);		//return new AlternatingDinerMenuIterator(menuItems);	} 	// other menu methods here}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -