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/teawithhook.d

46 lines
821 B
D
Raw Normal View History

2022-11-16 23:25:52 +00:00
module teawithhook;
import std.stdio : write, writeln, readln;
import std.uni : toLower;
import std.algorithm : startsWith;
import caffeinebeveragewithhook;
class TeaWithHook : CaffeineBeverageWithHook
{
override void brew()
{
writeln("Steeping the tea");
}
override void addCondiments()
{
writeln("Adding Lemon");
}
override bool customerWantsCondiments()
{
if (getUserInput().toLower().startsWith("y"))
{
return true;
}
else
{
return false;
}
}
string getUserInput()
{
string answer;
write("Would you like lemon with your tea (y/n)? ");
if ((answer = readln()) !is null)
{
return answer;
}
return "no";
}
}