001package headfirst.templatemethod.barista;
002
003import java.io.BufferedReader;
004import java.io.IOException;
005import java.io.InputStreamReader;
006
007public class TeaWithHook extends CaffeineBeverageWithHook {
008
009        public void brew() {
010                System.out.println("Steeping the tea");
011        }
012
013        public void addCondiments() {
014                System.out.println("Adding Lemon");
015        }
016
017        public boolean customerWantsCondiments() {
018
019                String answer = getUserInput();
020
021                if (answer.toLowerCase().startsWith("y")) {
022                        return true;
023                } else {
024                        return false;
025                }
026        }
027
028        private String getUserInput() {
029                // get the user's response
030                String answer = null;
031
032                System.out.print("Would you like milk and sugar with your coffee (y/n)? ");
033
034                BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
035                try {
036                        answer = in.readLine();
037                } catch (IOException ioe) {
038                        System.err.println("IO error trying to read your answer");
039                }
040                if (answer == null) {
041                        return "no";
042                }
043                return answer;
044        }
045}