Created
May 5, 2016 17:06
-
-
Save BobGu/e9535fac8b3feb7d59d66fd326cf75bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class KlinesIceCreamMenu implements Menu { | |
static final int MAX_ITEMS = 3; | |
int numberOfItems = 0; | |
private MenuItem[] menuItems; | |
public KlinesIceCreamMenu() { | |
menuItems = new MenuItem[MAX_ITEMS]; | |
addItem("Chocolate", "The gold standard, creamy and chocolatey", 3.99); | |
addItem("Vanilla", "Anything but boring", 3.99); | |
addItem("Mint Chocolate Chip", "Minty, green and amazing", 4.99); | |
} | |
private void addItem(String name, String description, double price) { | |
MenuItem menuItem = new MenuItem(name, description, price); | |
if (numberOfItems >= MAX_ITEMS) { | |
System.err.println("Sorry we only allow 3 flavors at Kllines"); | |
} else { | |
menuItems[numberOfItems] = menuItem; | |
numberOfItems += 1; | |
} | |
} | |
public Iterator createIterator() { | |
return new KlinesIceCreamMenuIterator(menuItems); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment