-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathParser.java
More file actions
50 lines (47 loc) · 1.56 KB
/
Parser.java
File metadata and controls
50 lines (47 loc) · 1.56 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
package duke;
import duke.task.*;
/**
* Formats the inputs to pass to different methods.
*/
public class Parser {
/**
* Formats the input sent from the user and pass it to different methods accordingly.
*
* @param lineInput The line input from the user.
*/
public static void parseInput(String lineInput) {
boolean printMessage = true;
String[] arrayInput = lineInput.split(" ");
String userCommand = arrayInput[0];
try {
switch (userCommand) {
case "list":
TaskList.showTask();
break;
case "done":
int doneIndex = Integer.parseInt(arrayInput[1]);
TaskList.doneTask(doneIndex, printMessage);
break;
case "find":
TaskList.searchTask(arrayInput);
break;
case "event":
case "todo":
case "deadline":
TaskList.recordTask(userCommand, lineInput, printMessage);
break;
case "delete":
String deleteIndex = arrayInput[1];
TaskList.deleteTask(deleteIndex);
break;
case "bye":
break;
default:
System.out.println("OOPS!!! Sorry, but I do not understand:(");
break;
}
} catch (ArrayIndexOutOfBoundsException | NumberFormatException | StringIndexOutOfBoundsException e) {
System.out.println("OOPS!!! Please enter a valid input:(");
}
}
}