Skip to content

Instantly share code, notes, and snippets.

@BobGu
Created May 5, 2016 17:06
Show Gist options
  • Save BobGu/e9535fac8b3feb7d59d66fd326cf75bb to your computer and use it in GitHub Desktop.
Save BobGu/e9535fac8b3feb7d59d66fd326cf75bb to your computer and use it in GitHub Desktop.
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