-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCoffeeWithHook.java
More file actions
47 lines (39 loc) · 1008 Bytes
/
CoffeeWithHook.java
File metadata and controls
47 lines (39 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package template.impl;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import template.CaffeineBeverageWithHook;
/**
* Created by http://teachcourse.cn on 2018/03/22.
*/
public class CoffeeWithHook extends CaffeineBeverageWithHook {
@Override
public void brew() {
System.out.println("Dripping Coffee through filter");
}
@Override
public void addCondiments() {
System.out.println("Adding Sugar and Milk");
}
@Override
public boolean customerWantsCondiments() {
String answer = getUserInput();
if (answer.toLowerCase().startsWith("y"))
return true;
return false;
}
private String getUserInput() {
String answer = null;
System.out
.println("Would you like milk and sugar with your coffee (y/n)?");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
answer = in.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (answer == null)
return "no";
return answer;
}
}