public void printVegetarianMenu() { System.out.println("Vegetarian"); Iterator pancakeIterator = pancakeHouseMenu.createIterator(); Iterator dinerIterator = dinerMenu.createIterator(); while (pancakeIterator.hasNext()) { MenuItem menuItem = (MenuItem) pancakeIterator.next(); if (menuItem.isVegetarian()) menuItem.print(); } while (dinerIterator.hasNext()) { MenuItem menuItem = (MenuItem) dinerIterator.next(); if (menuItem.isVegetarian()) menuItem.print(); } }
public void printMenu(Iterator iterator) { while (iterator.hasNext()) { MenuItem menuItem = (MenuItem) iterator.next(); // object down casting to MenuItem menuItem.print(); } }