public static function main($args) { $pancakeHouseMenu = new PancakeHouseMenu(); $dinerMenu = new DinerMenu(); $waitress = new Waitress($pancakeHouseMenu, $dinerMenu); $waitress->printMenu(); }
public static function main($args) { $pancakeHouseMenu = new Menu("PANCAKE HOUSE MENU", "Breakfast"); $dinerMenu = new Menu("DINER MENU", "Lunch"); $cafeMenu = new Menu("CAFE MENU", "Dinner"); $dessertMenu = new Menu("DESSERT MENU", "Dessert of course!"); $coffeeMenu = new Menu("COFFEE MENU", "Stuff to go with your afternoon coffee"); $allMenus = new Menu("ALL MENUS", "All menus combined"); $allMenus->add($pancakeHouseMenu); $allMenus->add($dinerMenu); $allMenus->add($cafeMenu); $pancakeHouseMenu->add(new MenuItem("K&B's Pancake Breakfast", "Pancakes with scrambled eggs, and toast", TRUE, 2.99)); $pancakeHouseMenu->add(new MenuItem("Regular Pancake Breakfast", "Pancakes with fried eggs, sausage", FALSE, 2.99)); $pancakeHouseMenu->add(new MenuItem("Blueberry Pancakes", "Pancakes made with fresh blueberries, and blueberry syrup", TRUE, 3.49)); $pancakeHouseMenu->add(new MenuItem("Waffles", "Waffles, with your choice of blueberries or strawberries", TRUE, 3.59)); $dinerMenu->add(new MenuItem("Vegetarian BLT", "(Fakin') Bacon with lettuce & tomato on whole wheat", TRUE, 2.99)); $dinerMenu->add(new MenuItem("BLT", "Bacon with lettuce & tomato on whole wheat", FALSE, 2.99)); $dinerMenu->add(new MenuItem("Soup of the day", "A bowl of the soup of the day, with a side of potato salad", FALSE, 3.29)); $dinerMenu->add(new MenuItem("Hotdog", "A hot dog, with saurkraut, relish, onions, topped with cheese", FALSE, 3.05)); $dinerMenu->add(new MenuItem("Steamed Veggies and Brown Rice", "Steamed vegetables over brown rice", TRUE, 3.99)); $dinerMenu->add(new MenuItem("Pasta", "Spaghetti with Marinara Sauce, and a slice of sourdough bread", TRUE, 3.89)); $dinerMenu->add($dessertMenu); $dessertMenu->add(new MenuItem("Apple Pie", "Apple pie with a flakey crust, topped with vanilla icecream", TRUE, 1.59)); $dessertMenu->add(new MenuItem("Cheesecake", "Creamy New York cheesecake, with a chocolate graham crust", TRUE, 1.99)); $dessertMenu->add(new MenuItem("Sorbet", "A scoop of raspberry and a scoop of lime", TRUE, 1.89)); $cafeMenu->add(new MenuItem("Veggie Burger and Air Fries", "Veggie burger on a whole wheat bun, lettuce, tomato, and fries", TRUE, 3.99)); $cafeMenu->add(new MenuItem("Soup of the day", "A cup of the soup of the day, with a side salad", FALSE, 3.69)); $cafeMenu->add(new MenuItem("Burrito", "A large burrito, with whole pinto beans, salsa, guacamole", TRUE, 4.29)); $cafeMenu->add($coffeeMenu); $coffeeMenu->add(new MenuItem("Coffee Cake", "Crumbly cake topped with cinnamon and walnuts", TRUE, 1.59)); $coffeeMenu->add(new MenuItem("Bagel", "Flavors include sesame, poppyseed, cinnamon raisin, pumpkin", FALSE, 0.6899999999999999)); $coffeeMenu->add(new MenuItem("Biscotti", "Three almond or hazelnut biscotti cookies", TRUE, 0.89)); $waitress = new Waitress($allMenus); $waitress->printMenu(); }
public static function main($args) { $pancakeHouseMenu = new PancakeHouseMenu(); $dinerMenu = new DinerMenu(); $waitress = new Waitress($pancakeHouseMenu, $dinerMenu); $waitress->printMenu(); $waitress->printVegetarianMenu(); println("\nCustomer asks, is the Hotdog vegetarian?"); print "Waitress says: "; if ($waitress->isItemVegetarian("Hotdog")) { println("Yes"); } else { println("No"); } println("\nCustomer asks, are the Waffles vegetarian?"); print "Waitress says: "; if ($waitress->isItemVegetarian("Waffles")) { println("Yes"); } else { println("No"); } }
$dinerMenu = new Menu("DINER MENU", "午餐"); $cafeMenu = new Menu("CAFE MENU", "晚餐"); $dessertMenu = new Menu("DESSERT MENU", "甜点!"); $allMenus = new Menu("ALL MENUS", "All menus combined"); $allMenus->add($pancakeHouseMenu); $allMenus->add($dinerMenu); $allMenus->add($cafeMenu); //早餐菜单项 $pancakeHouseMenu->add(new MenuItem("K&B's Pancake Breakfast", "Pancakes with scrambled eggs, and toast", true, 2.99)); $pancakeHouseMenu->add(new MenuItem("Regular Pancake Breakfast", "Pancakes with fried eggs,sausage", false, 2.99)); $pancakeHouseMenu->add(new MenuItem("Blueberry Pancakes", "Pancakes made with fresh blueberries", true, 3.49)); $pancakeHouseMenu->add(new MenuItem("Waffles", "Waffles, with your choice of blueberries or strawberries", true, 3.59)); //午餐菜单项 $dinerMenu->add(new MenuItem("Pasta", "Spaghetti with Marinara Sauce,and a slice of sourdough bread", true, 3.89)); $dinerMenu->add(new MenuItem("Vegetarian BLT", "(Fakin') Bacon with lettuce & tomato on whole wheat", true, 2.99)); $dinerMenu->add(new MenuItem("BLT", "Bacon with lettuce & tomato on whole wheat", false, 2.99)); $dinerMenu->add(new MenuItem("Soup of the day", "Soup of the day, with a side of potato salad", false, 3.29)); $dinerMenu->add(new MenuItem("Hotdog", "A hot dog,with saurkraut relish, onions, topped with cheese", false, 3.05)); $dinerMenu->add($dessertMenu); //甜点 $dessertMenu->add(new MenuItem("Apple Pie", "Apple pie with a flakey crust,toppen with vanilla ice cream", true, 1.59)); $dessertMenu->add(new MenuItem("Cheesecake", "Apple pie with a flakey crust,toppen with vanilla ice cream", true, 1.99)); $dessertMenu->add(new MenuItem("Sorbet", "Apple pie with a flakey crust,toppen with vanilla ice cream", true, 1.89)); //晚餐 $cafeMenu->add(new MenuItem("辣椒炒肉", "很好吃的辣椒炒肉", false, 12.05)); $cafeMenu->add(new MenuItem("跺脚鱼头", "新鲜的鱼头,香喷喷的剁辣椒", false, 23.7)); $waitress = new Waitress($allMenus); //$waitress->printMenu(); $waitress->printVegetarianMenu(); echo '<hr>'; echo file_get_contents('./read.txt');
<?php include_once __DIR__ . "/waitress.php"; $menu1 = new PancakeHouseMenu(); $menu2 = new DinerMenu(); $waitress = new Waitress($menu1, $menu2); $waitress->printAllMenus();
$dinerMenu = new Menu('Diner Menu', 'Lunch'); #餐厅菜单 $dessertMenu = new Menu('Dessert Menu', 'Dessert of Course!'); #甜品 餐厅子菜单 #根菜单组合 $allMenu = new Menu('All Menu', 'All Menu Combined'); $allMenu->add($pancakeHouseMenu); $allMenu->add($dinerMenu); $dessertMenu->add(new MenuItem('Apple Pie', 'Pie with Apple', 3.98, true)); #添加菜单项 苹果派 $dinerMenu->add(new MenuItem('steak', 'delicious steak', 60, false)); #添加菜单项 牛排 $dinerMenu->add($dessertMenu); #添加子菜单 #打印所有菜单 $waitress = new Waitress($allMenu); $waitress->printMenu(); println(); #打印出素食菜单 println('Vegetarian Menu:'); $waitress->printVegetarian(); println(SEPARATE, 'END', SEPARATE); /** * 输出: All Menu,All Menu Combined: Pancake House Menu,Breakfast: Diner Menu,Lunch: steak , 60--delicious steak Dessert Menu,Dessert of Course!: Apple Pie (v), 3.98--Pie with Apple
<?php ini_set('display_errors', "On"); error_reporting(E_ALL | E_STRICT); //自动加载类 set_include_path(get_include_path() . PATH_SEPARATOR . 'class/'); //设置加载路径 spl_autoload_extensions('.php'); //设置加载后缀名 function myAutoload($className) { require_once $className . '.php'; //直接根据类名跟文件关系包含文件 } spl_autoload_register("myAutoload"); //注册自动加载函数 //测试代码开始 $pancakeHouseMenu = new PancakeHouseMenu(); $dinerMenu = new DinerMenu(); $waitress = new Waitress($pancakeHouseMenu, $dinerMenu); $waitress->printMenu(); echo '<hr>'; echo file_get_contents('./read.txt');