diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java deleted file mode 100644 index 5f748f4f..00000000 --- a/src/main/java/Todo.java +++ /dev/null @@ -1,11 +0,0 @@ -class Todo extends Task{ - - Todo(String input) { - super(input); - } - - Todo(String input, boolean isDone) { - super(input); - setDone(isDone); - } -} diff --git a/src/main/java/Duke.java b/src/main/java/duke/Duke.java similarity index 89% rename from src/main/java/Duke.java rename to src/main/java/duke/Duke.java index 509ed277..dea9346c 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,10 +1,16 @@ +package duke; + +import duke.ui.UI; +import duke.parser.Parser; +import duke.task.TaskList; + import java.util.Scanner; /** * A Personal Assistant Chatbot that helps a person to keep track of various things. * * @author Wang Zhenquan - * @version Level 3 + * @version Level 5 * @since 20/08/2020 */ diff --git a/src/main/java/DukeException.java b/src/main/java/duke/exception/DukeException.java similarity index 87% rename from src/main/java/DukeException.java rename to src/main/java/duke/exception/DukeException.java index d4d36b8f..c11c3988 100644 --- a/src/main/java/DukeException.java +++ b/src/main/java/duke/exception/DukeException.java @@ -1,3 +1,4 @@ +package duke.exception; /** * Inherits the Exception class.

* Overrides the constructor that takes a String parameter with custom error information @@ -7,7 +8,7 @@ * Catch that exception somewhere else and print the message inside the exception object. */ public class DukeException extends Exception { - DukeException(String input) { + public DukeException(String input) { super(input); } } \ No newline at end of file diff --git a/src/main/java/Parser.java b/src/main/java/duke/parser/Parser.java similarity index 79% rename from src/main/java/Parser.java rename to src/main/java/duke/parser/Parser.java index 302fe0f8..e99d0de4 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/duke/parser/Parser.java @@ -1,4 +1,9 @@ -class Parser { +package duke.parser; + +import duke.task.TaskList; +import duke.ui.UI; + +public class Parser { /** * @param line The entire user input. */ @@ -7,11 +12,11 @@ String getCommandWord(String line) { } /** - * @param line The entire user input. - * @param ui The UI created in the Duke class. - * @param tasks The TaskList created in the Duke class. + * @param line The entire user input. + * @param ui The UI created in the Duke class. + * @param tasks The TaskList created in the Duke class. */ - boolean parseInput(String line, UI ui, TaskList tasks) { + public boolean parseInput(String line, UI ui, TaskList tasks) { String command = getCommandWord(line); switch (command) { diff --git a/src/main/java/Deadline.java b/src/main/java/duke/task/Deadline.java similarity index 71% rename from src/main/java/Deadline.java rename to src/main/java/duke/task/Deadline.java index 178f7b3c..1ed6b70f 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,4 +1,6 @@ -class Deadline extends Todo{ +package duke.task; + +class Deadline extends Todo { private String[] split; Deadline(String input) { diff --git a/src/main/java/Event.java b/src/main/java/duke/task/Event.java similarity index 72% rename from src/main/java/Event.java rename to src/main/java/duke/task/Event.java index 1b30a418..38998b43 100644 --- a/src/main/java/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,4 +1,6 @@ -class Event extends Todo{ +package duke.task; + +class Event extends Todo { private String[] split; Event(String input) { diff --git a/src/main/java/Task.java b/src/main/java/duke/task/Task.java similarity index 71% rename from src/main/java/Task.java rename to src/main/java/duke/task/Task.java index 6f6f47f5..eb75419e 100644 --- a/src/main/java/Task.java +++ b/src/main/java/duke/task/Task.java @@ -1,7 +1,10 @@ +package duke.task; + /** - * A class for tasks. + * An abstract class that is inherited by the Todo, Deadline and Event classes. */ -class Task { + +public abstract class Task { String task; private boolean isDone; @@ -20,7 +23,8 @@ boolean getDone() { String getTaskStatus(Boolean isDone) { return "[" + (isDone ? "\u2713" : "\u2718") + "] "; //return tick or X symbols } - String getDescription() { + + public String getDescription() { return getTaskStatus(isDone) + task; } } \ No newline at end of file diff --git a/src/main/java/TaskList.java b/src/main/java/duke/task/TaskList.java similarity index 90% rename from src/main/java/TaskList.java rename to src/main/java/duke/task/TaskList.java index cbdc0c95..711d99b1 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/duke/task/TaskList.java @@ -1,20 +1,25 @@ +package duke.task; + +import duke.exception.DukeException; +import duke.ui.UI; + import java.util.ArrayList; /** * Responsible for managing all the tasks in the list. This class will use an ArrayList inside it. */ -class TaskList { +public class TaskList { private ArrayList tasks; TaskList(ArrayList tasks) { this.tasks = tasks; } - TaskList() { + public TaskList() { tasks = new ArrayList<>(); } - int size() { + public int size() { return tasks.size(); } @@ -22,11 +27,11 @@ void add(Task task) { tasks.add(task); } - Task get(int index) { + public Task get(int index) { return tasks.get(index); } - void changeDone(String line, UI ui, TaskList tasks) { + public void changeDone(String line, UI ui, TaskList tasks) { line = line.substring("done".length()).trim(); try { if (!line.isEmpty()) { @@ -55,7 +60,7 @@ private void markAsDone(String line, UI ui, TaskList tasks) { } } - void createTodo(String line, UI ui, TaskList tasks) { + public void createTodo(String line, UI ui, TaskList tasks) { try { if (line.substring("todo".length()).trim().isEmpty()) { throw new DukeException @@ -70,7 +75,7 @@ void createTodo(String line, UI ui, TaskList tasks) { } } - void createDeadline(String line, UI ui, TaskList tasks) { + public void createDeadline(String line, UI ui, TaskList tasks) { try { if (line.substring("deadline".length()).trim().isEmpty() || !line.contains("/by")) { throw new DukeException @@ -97,7 +102,7 @@ void createDeadline(String line, UI ui, TaskList tasks) { } } - void createEvent(String line, UI ui, TaskList tasks) { + public void createEvent(String line, UI ui, TaskList tasks) { try { if (line.substring("event".length()).trim().isEmpty() || !line.contains("/at")) { throw new DukeException diff --git a/src/main/java/duke/task/Todo.java b/src/main/java/duke/task/Todo.java new file mode 100644 index 00000000..59b29fc0 --- /dev/null +++ b/src/main/java/duke/task/Todo.java @@ -0,0 +1,9 @@ +package duke.task; + +class Todo extends Task { + + Todo(String input) { + super(input); + } + +} diff --git a/src/main/java/UI.java b/src/main/java/duke/ui/UI.java similarity index 84% rename from src/main/java/UI.java rename to src/main/java/duke/ui/UI.java index 0beb7b4d..5513c1ac 100644 --- a/src/main/java/UI.java +++ b/src/main/java/duke/ui/UI.java @@ -1,6 +1,10 @@ -class UI { +package duke.ui; - void greet() { +import duke.task.TaskList; + +public class UI { + + public void greet() { String greeting = "____________________________________________________________\n" + "Hello! I'm Duke\n" + "What can I do for you?\n" @@ -8,13 +12,13 @@ void greet() { System.out.println(greeting); } - void farewell() { + public void farewell() { String farewell = "Bye. Hope to see you again soon!\n" + "____________________________________________________________\n"; System.out.println(farewell); } - void markedAsDone(int index, TaskList tasks) { + public void markedAsDone(int index, TaskList tasks) { String done = "____________________________________________________________\n" + "\033[33mTask [" + index + "] " + tasks.get(index - 1).getDescription() + " has been set as completed.\033[0m" @@ -29,15 +33,15 @@ void showTotal(TaskList tasks) { System.out.println(total); } - void printError(String s) { + public void printError(String s) { System.out.println(colorRed(s)); } - String colorRed(String input) { + public String colorRed(String input) { return "\033[31m" + input + "\033[0m"; } - void invalidCommand() { + public void invalidCommand() { printError("Please enter a valid command."); } diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6..51f3e5b9 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -5,3 +5,7 @@ Hello from | |_| | |_| | < __/ |____/ \__,_|_|\_\___| +____________________________________________________________ +Hello! I'm Duke +What can I do for you? +____________________________________________________________ \ No newline at end of file diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index d0facc63..4e1f6bb5 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -4,10 +4,10 @@ REM create bin directory if it doesn't exist if not exist ..\bin mkdir ..\bin REM delete output from previous run -del ACTUAL.TXT +//del ACTUAL.TXT REM compile the code into the bin folder -javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\Duke.java +javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\duke\Duke.java IF ERRORLEVEL 1 ( echo ********** BUILD FAILURE ********** exit /b 1