Skip to content

Commit

Permalink
Use Enums for the different types of task
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowezz committed Aug 19, 2020
1 parent 7a81bca commit ac88dd7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public static void main(String[] args) {
} else if (command.equals("done") || command.equals("delete")) {
handleCompleteStatus(command, commandArr);
} else if (command.equals("todo")) {
handleTask("todo", commandArr);
handleTask(TaskType.TODO, commandArr);
} else if (command.equals("deadline")) {
handleTask("deadline", commandArr);
handleTask(TaskType.DEADLINE, commandArr);
} else if (command.equals("event")) {
handleTask("event", commandArr);
handleTask(TaskType.EVENT, commandArr);
} else {
throw new DukeException("I am sorry, I don't know what that means :(");
}
Expand All @@ -39,15 +39,15 @@ public static void main(String[] args) {
}
}

public static void handleTask(String taskType, String[] commandArr) {
public static void handleTask(TaskType taskType, String[] commandArr) {
try {
if (commandArr.length < 2 || commandArr[1].isBlank()) {
throw new MissingInformationException(String.format("The description of a %s cannot be empty.", taskType));
throw new MissingInformationException(String.format("The description of a %s cannot be empty.", taskType.name().toLowerCase()));
}
if (taskType.equals("todo")) {
if (taskType == TaskType.TODO) {
String name = commandArr[1];
addTodo(name);
} else if (taskType.equals("deadline")) {
} else if (taskType == TaskType.DEADLINE) {
String details = commandArr[1];
String[] detailArr = details.split(" /by ", 2);
if (detailArr.length < 2 || detailArr[1].isBlank()) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/TaskType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public enum TaskType {
TODO,
DEADLINE,
EVENT;
}
1 change: 1 addition & 0 deletions text-ui-test/sources.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
../src/main/java/TaskType.java
../src/main/java/Event.java
../src/main/java/Task.java
../src/main/java/MissingInformationException.java
Expand Down

0 comments on commit ac88dd7

Please sign in to comment.