This repository has been archived on 2022-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
patterns/iterator/simpleiterator/waitress.d

80 lines
1.6 KiB
D
Raw Normal View History

2022-11-17 12:39:07 +00:00
module waitress;
import menu, iterator, menuitem;
import std.stdio : writeln, write;
class Waitress
{
private Menu dinerMenu;
this(Menu dinerMenu)
{
this.dinerMenu = dinerMenu;
}
void printMenu()
{
writeln("MENU\n----\nLUNCH");
printMenu(dinerMenu.createIterator());
}
private void printMenu(Iterator iterator)
{
while (iterator.hasNext())
{
MenuItem menuItem = iterator.next();
write(menuItem.getName(), ", ");
write(menuItem.getPrice(), " -- ");
writeln(menuItem.getDescription());
}
}
void printVegetarianMenu()
{
writeln("MENU\n----\nVEGETARIAN");
printVegetarianMenu(dinerMenu.createIterator());
}
// bool isItemVegetarian(string name)
// {
// Iterator dinnerIterator = dinerMenu.createIterator();
// if (isVegetarian(name, dinnerIterator))
// {
// return true;
// }
// return false;
// }
private void printVegetarianMenu(Iterator iterator)
{
while (iterator.hasNext())
{
MenuItem menuItem = iterator.next();
if (menuItem.isVegetarian())
{
write(menuItem.getName());
writeln("\t\t", menuItem.getPrice());
writeln("\t", menuItem.getDescription());
}
}
}
// private bool isVegetarian(string name, Iterator iterator)
// {
// while (iterator.hasNext())
// {
// MenuItem menuItem = iterator.next();
// if (menuItem.getName() == name)
// {
// if (menuItem.isVegetarian())
// {
// return true;
// }
// }
// }
// return false;
// }
}