-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathDuke.java
More file actions
76 lines (67 loc) · 2.19 KB
/
Duke.java
File metadata and controls
76 lines (67 loc) · 2.19 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.util.Scanner;
public class Duke {
static WordList wordList;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
wordList = new WordList();
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
replyWelcomeMessage();
String input;
while (true) {
input = sc.nextLine();
if (input.isEmpty()) {
warnEmpty();
continue;
}
Object[] parseResult = InputParser.parseInput(input);
InputType inputType = (InputType) parseResult[0];
String[] value = (String[]) parseResult[1];
processInput(inputType, value);
if (inputType == InputType.BYE) {
break;
}
}
}
public static void processInput(InputType inputType, String[] value) {
switch(inputType) {
case LIST:
wordList.printList();
break;
case MARK:
wordList.markItem(Integer.parseInt(value[0]));
break;
case UNMARK:
wordList.unmarkItem(Integer.parseInt(value[0]));
break;
case TODO:
wordList.storeTodo(value[0]);
break;
case DEADLINE:
wordList.storeDeadline(value[0], value[1]);
break;
case EVENT:
wordList.storeEvent(value[0], value[1]);
break;
case BYE:
replyBye();
break;
case NONE:
break;
}
}
public static void replyWelcomeMessage() {
System.out.println("Hello! I'm Duke");
System.out.println("What can I do for you?");
}
public static void warnEmpty() {
System.out.println("input is Empty!");
}
public static void replyBye() {
System.out.println("Bye. Hope to see you again soon!");
}
}