-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathUi.java
More file actions
59 lines (49 loc) · 1.75 KB
/
Ui.java
File metadata and controls
59 lines (49 loc) · 1.75 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
package duke;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
public class Ui {
private static final String INDENT = " ";
private static final String TEXT_INDENT = INDENT + "|" + " ";
private static final String RES_BOX_TOP = INDENT + "_______________________________________________\n";
private static final String RES_BOX_BOTTOM = INDENT + "|____________________________________________\n"
+ INDENT + " \\|\n";
private static Scanner sc = new Scanner(System.in);
private final Scanner in;
private final PrintStream out;
public Ui() {
this.in = new Scanner(System.in);
this.out = System.out;
}
private boolean hasCommand() {
return in.hasNext();
}
public String readCommand() {
assert hasCommand();
return in.nextLine();
}
public void close() {
in.close();
}
public void displayIntro() {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
String response = "Hello from\n"
+ logo + "\n"
+ "What can I do for you?\n";
respond(response);
}
public void respond(String response) {
String indentedResponse = Arrays.stream(response.split("\n"))
.map(line -> TEXT_INDENT + line)
.collect(Collectors.joining("\n")) + "\n";
String output = RES_BOX_TOP
+ indentedResponse
+ RES_BOX_BOTTOM;
System.out.println(output);
}
}