forked from nus-cs2103-AY1920S1/duke
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c450403
commit e1a34f1
Showing
4 changed files
with
159 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
||
public class InputParser { | ||
|
||
private ArrayList<Task> taskList; | ||
private ModifyTaskList modifyTaskList = new ModifyTaskList(); | ||
|
||
protected InputParser(ArrayList<Task> taskList) { | ||
this.taskList = taskList; | ||
} | ||
|
||
protected void actionDeterminer (String input) throws IOException { | ||
|
||
int taskNumber; | ||
String by; | ||
String desc; | ||
String at; | ||
String firstWord; | ||
|
||
firstWord = input.split(" ")[0]; | ||
switch (firstWord) { | ||
|
||
case "bye": | ||
break; | ||
|
||
case "todo": | ||
try { | ||
desc = input.split(" ", 2)[1]; | ||
} catch (IndexOutOfBoundsException err) { | ||
System.out.println("OOPS!!! The description of a todo cannot be empty.\n"); | ||
break; | ||
} | ||
ToDo toDo = new ToDo(desc); | ||
modifyTaskList.addToTaskList(taskList, toDo, Duke.Action.ADD); | ||
break; | ||
|
||
|
||
case "deadline": | ||
try { | ||
by = input.split(" /by ")[1]; | ||
desc = input.split(" /by ")[0].split(" ", 2)[1]; | ||
} catch (IndexOutOfBoundsException err) { | ||
System.out.println("OOPS!!! Incorrect description for event; remember to use the /by keyword.\n"); | ||
break; | ||
} | ||
Deadline d = new Deadline(desc, by); | ||
modifyTaskList.addToTaskList(taskList, d, Duke.Action.ADD); | ||
break; | ||
|
||
case "event": | ||
try { | ||
at = input.split(" /at ")[1]; | ||
desc = input.split(" /at ")[0].split(" ", 2)[1]; | ||
} catch (IndexOutOfBoundsException err) { | ||
System.out.println("OOPS!!! Incorrect description for event; remember to use the /at keyword.\n"); | ||
break; | ||
} | ||
Event e = new Event(desc, at); | ||
modifyTaskList.addToTaskList(taskList, e, Duke.Action.ADD); | ||
break; | ||
|
||
case "list": | ||
System.out.println("Here are the tasks in your list:"); | ||
for (int a = 0; a < taskList.size(); a++) { | ||
System.out.println((a + 1) + ". " + taskList.get(a).toString()); | ||
} | ||
System.out.println(); | ||
break; | ||
|
||
case "done": | ||
try { | ||
taskNumber = Integer.parseInt(input.split(" ")[1]); | ||
} catch (NumberFormatException err) { | ||
System.out.println("OOPS!!! Please enter a valid number\n"); | ||
break; | ||
} catch (IndexOutOfBoundsException err) { | ||
System.out.println("You only have " + taskList.size() + " tasks, please choose a number from that\n"); | ||
break; | ||
} | ||
modifyTaskList.changeTaskList(taskList, taskNumber - 1, Duke.Action.DONE); | ||
break; | ||
|
||
case "delete": | ||
try { | ||
taskNumber = Integer.parseInt(input.split(" ")[1]); | ||
} catch (NumberFormatException err) { | ||
System.out.println("OOPS!!! Please enter a valid number\n"); | ||
break; | ||
} catch (IndexOutOfBoundsException err) { | ||
System.out.println("You only have " + taskList.size() + " tasks, please choose a number from that\n"); | ||
break; | ||
} | ||
modifyTaskList.changeTaskList(taskList, taskNumber - 1, Duke.Action.REMOVE); | ||
break; | ||
|
||
default: | ||
System.out.println("OOPS!!! I'm sorry, but I don't know what that means\n"); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import java.util.ArrayList; | ||
|
||
public class Ui { | ||
|
||
public void ui() { | ||
|
||
} | ||
|
||
public void greeting(){ | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println(logo); | ||
System.out.println("Hello! I'm Duke \nWhat can I do for you?"); | ||
} | ||
|
||
public void goodbye(){ | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
|
||
public void taskAdded(ArrayList<Task> taskList){ | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(taskList.get(taskList.size() - 1).toString()); | ||
System.out.println("Now you have " + taskList.size() + " tasks in the list.\n"); | ||
} | ||
|
||
public void taskRemoved(ArrayList<Task> taskList, int taskNumber){ | ||
System.out.println("Noted. I've removed this task:\n" + taskList.get(taskNumber).toString()); | ||
System.out.println("Now you have " + (taskList.size()-1) + " tasks in the list.\n"); | ||
} | ||
|
||
public void taskDone(ArrayList<Task> taskList, int taskNumber){ | ||
System.out.println("Nice! I've marked this task as done:"); | ||
System.out.println(taskList.get(taskNumber).toString() + "\n"); | ||
} | ||
|
||
|
||
} |