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/templatemethod/barista/coffeewithhook.d

46 lines
862 B
D

module coffeewithhook;
import std.stdio : write, writeln, readln;
import std.uni : toLower;
import std.algorithm : startsWith;
import caffeinebeveragewithhook;
class CoffeeWithHook : CaffeineBeverageWithHook
{
override void brew()
{
writeln("Dripping Coffee through filter");
}
override void addCondiments()
{
writeln("Adding Sugar and Milk");
}
override bool customerWantsCondiments()
{
if (getUserInput().toLower().startsWith("y"))
{
return true;
}
else
{
return false;
}
}
string getUserInput()
{
string answer;
write("Would you like milk and sugar with your coffee (y/n)? ");
if ((answer = readln()) !is null)
{
return answer;
}
return "no";
}
}