LoganBlackisle

DinerMenu

Jun 14th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. package prep_29_iteratorpattern;
  2.  
  3. public class DinerMenu {
  4. private static final int MAX_ITEMS = 6;
  5. private int numberOfItems = 0;
  6. private MenuItem[] menuItems;
  7.  
  8. public DinerMenu() {
  9. menuItems = new MenuItem[MAX_ITEMS];
  10. addItem("Vegetarian BLT", "(Fakin’) Bacon with lettuce & tomato on whole wheat", true, 2.99);
  11. addItem("BLT", "Bacon with lettuce & tomato on whole wheat", false, 2.99);
  12. addItem("Soup of the day", "Soup of the day, with a side of potato salad", false, 3.29);
  13. addItem("Hotdog", "A hot dog, with saurkraut, relish, onions, topped with cheese", false, 3.05);
  14. }
  15.  
  16. public void addItem(String name, String description, boolean vegetarian, double price) {
  17. MenuItem menuItem = new MenuItem(name, description, vegetarian, price);
  18. if (numberOfItems >= MAX_ITEMS) {
  19. System.err.println("Sorry, menu is full! Can’t add item to menu");
  20. } else {
  21. menuItems[numberOfItems] = menuItem;
  22. numberOfItems = numberOfItems + 1;
  23. }
  24. }
  25.  
  26. public Iterator createIterator() {
  27. return new DinerMenuIterator(menuItems);
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment