From be01343ffd530a87fcfde5536b0a956d88c727bd Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Tue, 21 Jan 2020 17:48:45 +0800 Subject: [PATCH 01/29] Change duke to greet --- src/main/java/Duke.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334cc..e49fe36d3b 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,6 @@ public class Duke { public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + System.out.println("Hello! I'm Duke\nWhat can I do for you?" + + "\n\nBye. Hope to see you again soon!"); } } From fbf3a39d8c27f36a20b975d1598993ed6855abe0 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Thu, 30 Jan 2020 16:18:06 +0800 Subject: [PATCH 02/29] Add String "Duke" --- src/main/java/Duke.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e49fe36d3b..fb06222b96 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,5 +1,11 @@ public class Duke { public static void main(String[] args) { + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke\nWhat can I do for you?" + "\n\nBye. Hope to see you again soon!"); } From 1c2741619975f5f04e7b1ff2ee75966c1bc695d0 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Fri, 31 Jan 2020 22:54:04 +0800 Subject: [PATCH 03/29] Add checked items on list --- src/main/java/Duke.java | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index fb06222b96..b463d79ab2 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,4 +1,17 @@ +import java.util.Scanner; +import java.util.ArrayList; + public class Duke { + static ArrayList list = new ArrayList(); + + public static void printTasks() { + System.out.println("Here are the tasks in your list:"); + for (Task task : list) { + System.out.println(String.format("%d. [%c] %s", task.getTaskId(), + task.isDone() ? '✓' : '✗', task.getTaskName())); + } + } + public static void main(String[] args) { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -6,7 +19,22 @@ public static void main(String[] args) { + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); - System.out.println("Hello! I'm Duke\nWhat can I do for you?" + - "\n\nBye. Hope to see you again soon!"); + System.out.println("Hello! I'm Duke\nWhat can I do for you?"); + Scanner scan = new Scanner(System.in); + String userInput = scan.nextLine(); + while (!userInput.equals("bye")) { + if (userInput.equals("list")) { + printTasks(); + } else if (userInput.length() > 4 && userInput.substring(0, 5).equals("done ")) { + list.get(Integer.parseInt(Character.toString( + userInput.charAt(userInput.length() - 1))) - 1).setDone(); + } else { + System.out.println("added: " + userInput); + Task task = new Task(userInput); + list.add(task); + } + userInput = scan.nextLine(); + } + System.out.println("Bye. Hope to see you again soon!"); } } From a33dfcdbab0e149727bb24d9d2a4eed9979e618e Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Mon, 3 Feb 2020 22:41:18 +0800 Subject: [PATCH 04/29] Add Level 4 increment --- src/.idea/modules.xml | 8 ++++++++ src/.idea/vcs.xml | 6 ++++++ src/main/java/Deadline.java | 13 ++++++++++++ src/main/java/Duke.java | 24 ++++++++++++++++++---- src/main/java/Event.java | 13 ++++++++++++ src/main/java/Task.java | 40 +++++++++++++++++++++++++++++++++++++ src/main/java/ToDo.java | 10 ++++++++++ 7 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 src/.idea/modules.xml create mode 100644 src/.idea/vcs.xml create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/Task.java create mode 100644 src/main/java/ToDo.java diff --git a/src/.idea/modules.xml b/src/.idea/modules.xml new file mode 100644 index 0000000000..f669a0e594 --- /dev/null +++ b/src/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/.idea/vcs.xml b/src/.idea/vcs.xml new file mode 100644 index 0000000000..6c0b863585 --- /dev/null +++ b/src/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 0000000000..2a26c8072e --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,13 @@ +public class Deadline extends Task { + private String latestDate; + + public Deadline(String userInput) { + super(userInput.substring(0, userInput.indexOf(" /"))); + this.latestDate = userInput.substring(userInput.indexOf("/") + 4); + } + + @Override + public String toString() { + return String.format("[D][%c] %s (by: %s)", isDone() ? '✓' : '✗', taskName, latestDate); + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index b463d79ab2..cb538d215a 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -7,8 +7,7 @@ public class Duke { public static void printTasks() { System.out.println("Here are the tasks in your list:"); for (Task task : list) { - System.out.println(String.format("%d. [%c] %s", task.getTaskId(), - task.isDone() ? '✓' : '✗', task.getTaskName())); + System.out.println(String.format("%d. %s", task.getTaskId(), task.toString())); } } @@ -28,10 +27,27 @@ public static void main(String[] args) { } else if (userInput.length() > 4 && userInput.substring(0, 5).equals("done ")) { list.get(Integer.parseInt(Character.toString( userInput.charAt(userInput.length() - 1))) - 1).setDone(); + } else if (userInput.length() > 4 && userInput.substring(0, 5).equals("todo ")) { + Task task = new ToDo(userInput.substring(5)); + list.add(task); + System.out.println("Got it. I've added this task:\n " + task.toString() + + String.format("\nNow you have %d tasks in the list.", Task.getTaskCounter())); + } else if (userInput.length() > 8 && userInput.substring(0, 9).equals("deadline ")) { + Task task = new Deadline(userInput.substring(9)); + list.add(task); + System.out.println("Got it. I've added this task:\n " + task.toString() + + String.format("\nNow you have %d tasks in the list.", Task.getTaskCounter())); + } else if (userInput.length() > 5 && userInput.substring(0, 6).equals("event ")) { + Task task = new Event(userInput.substring(6)); + list.add(task); + System.out.println("Got it. I've added this task:\n " + task.toString() + + String.format("\nNow you have %d tasks in the list.", Task.getTaskCounter())); } else { - System.out.println("added: " + userInput); - Task task = new Task(userInput); + /*Task task = new Task(userInput); list.add(task); + System.out.println("Got it. I've added this task:\n " + userInput + + String.format("\nNow you have %d tasks in the list.", Task.getTaskCounter())); + */ } userInput = scan.nextLine(); } diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 0000000000..a2e84d46a4 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,13 @@ +public class Event extends Task { + private String eventDetails; + + public Event(String userInput) { + super(userInput.substring(0, userInput.indexOf(" /"))); + this.eventDetails = userInput.substring(userInput.indexOf("/") + 4); + } + + @Override + public String toString() { + return String.format("[E][%c] %s (at: %s)", isDone() ? '✓' : '✗', taskName, eventDetails); + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 0000000000..f3d6eb12da --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,40 @@ +public class Task { + protected String taskName; + protected boolean isDone; + protected int taskId; + protected static int taskCounter = 0; + + public Task(String taskName) { + this.taskName = taskName; + this.isDone = false; + this.taskId = ++this.taskCounter; + } + + public void setDone() { + this.isDone = true; + System.out.println("Nice! I've marked this task as done:\n" + + String.format("[✓] %s", this.taskName)); + } + + public int getTaskId() { + return taskId; + } + + public boolean isDone() { + return isDone; + } + + public String getTaskName() { + return taskName; + } + + public static int getTaskCounter() { + return taskCounter; + } +/* + @Override + public String toString() { + return taskName; + } + */ +} diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java new file mode 100644 index 0000000000..243e1b2fa4 --- /dev/null +++ b/src/main/java/ToDo.java @@ -0,0 +1,10 @@ +public class ToDo extends Task { + public ToDo(String taskName) { + super(taskName); + } + + @Override + public String toString() { + return String.format("[T][%c] %s", isDone() ? '✓' : '✗', taskName); + } +} From a542137c244b99935d2837c30379f70b4a971117 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Thu, 6 Feb 2020 14:13:49 +0800 Subject: [PATCH 05/29] Touch up Level 4 increment --- src/main/java/Duke.java | 18 +++++++++--------- src/main/java/Task.java | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index cb538d215a..8036cb0e8d 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,11 +2,11 @@ import java.util.ArrayList; public class Duke { - static ArrayList list = new ArrayList(); + static ArrayList tasks = new ArrayList(); public static void printTasks() { System.out.println("Here are the tasks in your list:"); - for (Task task : list) { + for (Task task : tasks) { System.out.println(String.format("%d. %s", task.getTaskId(), task.toString())); } } @@ -25,23 +25,23 @@ public static void main(String[] args) { if (userInput.equals("list")) { printTasks(); } else if (userInput.length() > 4 && userInput.substring(0, 5).equals("done ")) { - list.get(Integer.parseInt(Character.toString( + tasks.get(Integer.parseInt(Character.toString( userInput.charAt(userInput.length() - 1))) - 1).setDone(); } else if (userInput.length() > 4 && userInput.substring(0, 5).equals("todo ")) { Task task = new ToDo(userInput.substring(5)); - list.add(task); + tasks.add(task); System.out.println("Got it. I've added this task:\n " + task.toString() - + String.format("\nNow you have %d tasks in the list.", Task.getTaskCounter())); + + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); } else if (userInput.length() > 8 && userInput.substring(0, 9).equals("deadline ")) { Task task = new Deadline(userInput.substring(9)); - list.add(task); + tasks.add(task); System.out.println("Got it. I've added this task:\n " + task.toString() - + String.format("\nNow you have %d tasks in the list.", Task.getTaskCounter())); + + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); } else if (userInput.length() > 5 && userInput.substring(0, 6).equals("event ")) { Task task = new Event(userInput.substring(6)); - list.add(task); + tasks.add(task); System.out.println("Got it. I've added this task:\n " + task.toString() - + String.format("\nNow you have %d tasks in the list.", Task.getTaskCounter())); + + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); } else { /*Task task = new Task(userInput); list.add(task); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index f3d6eb12da..38e890182b 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -2,12 +2,12 @@ public class Task { protected String taskName; protected boolean isDone; protected int taskId; - protected static int taskCounter = 0; + protected static int totalNumOfTasks = 0; public Task(String taskName) { this.taskName = taskName; this.isDone = false; - this.taskId = ++this.taskCounter; + this.taskId = ++this.totalNumOfTasks; } public void setDone() { @@ -28,8 +28,8 @@ public String getTaskName() { return taskName; } - public static int getTaskCounter() { - return taskCounter; + public static int getTotalNumOfTasks() { + return totalNumOfTasks; } /* @Override From 26b35eb2087c99f2ac0be6ebaec5d5a10f5eca5f Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Thu, 6 Feb 2020 14:22:06 +0800 Subject: [PATCH 06/29] Neaten "if else" conditions --- src/main/java/Duke.java | 29 ++++++++++++++--------------- src/main/java/Task.java | 6 ------ 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 8036cb0e8d..7647cc0ad8 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,7 +2,7 @@ import java.util.ArrayList; public class Duke { - static ArrayList tasks = new ArrayList(); + static ArrayList tasks = new ArrayList<>(); public static void printTasks() { System.out.println("Here are the tasks in your list:"); @@ -11,43 +11,42 @@ public static void printTasks() { } } - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" + public static void printLogo() { + String logo = " ____ _ \n" + + "| _ \\ _ _| | __ __ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke\nWhat can I do for you?"); + } + + public static void main(String[] args) { + printLogo(); Scanner scan = new Scanner(System.in); String userInput = scan.nextLine(); while (!userInput.equals("bye")) { - if (userInput.equals("list")) { + String[] splitUpInput = userInput.split(" "); + if (splitUpInput[0].equals("list")) { printTasks(); - } else if (userInput.length() > 4 && userInput.substring(0, 5).equals("done ")) { + } else if (splitUpInput[0].equals("done")) { tasks.get(Integer.parseInt(Character.toString( userInput.charAt(userInput.length() - 1))) - 1).setDone(); - } else if (userInput.length() > 4 && userInput.substring(0, 5).equals("todo ")) { + } else if (splitUpInput[0].equals("todo")) { Task task = new ToDo(userInput.substring(5)); tasks.add(task); System.out.println("Got it. I've added this task:\n " + task.toString() + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); - } else if (userInput.length() > 8 && userInput.substring(0, 9).equals("deadline ")) { + } else if (splitUpInput[0].equals("deadline")) { Task task = new Deadline(userInput.substring(9)); tasks.add(task); System.out.println("Got it. I've added this task:\n " + task.toString() + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); - } else if (userInput.length() > 5 && userInput.substring(0, 6).equals("event ")) { + } else if (splitUpInput[0].equals("event")) { Task task = new Event(userInput.substring(6)); tasks.add(task); System.out.println("Got it. I've added this task:\n " + task.toString() + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); - } else { - /*Task task = new Task(userInput); - list.add(task); - System.out.println("Got it. I've added this task:\n " + userInput - + String.format("\nNow you have %d tasks in the list.", Task.getTaskCounter())); - */ } userInput = scan.nextLine(); } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 38e890182b..72c585f80c 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -31,10 +31,4 @@ public String getTaskName() { public static int getTotalNumOfTasks() { return totalNumOfTasks; } -/* - @Override - public String toString() { - return taskName; - } - */ } From dad0e8ac66349f33b7b8248d6542fbaed8b859e2 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Sun, 9 Feb 2020 21:53:58 +0800 Subject: [PATCH 07/29] Change conditional statements to "startsWith" string method --- src/main/java/Duke.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 7647cc0ad8..25301ff2b6 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -26,23 +26,23 @@ public static void main(String[] args) { Scanner scan = new Scanner(System.in); String userInput = scan.nextLine(); while (!userInput.equals("bye")) { - String[] splitUpInput = userInput.split(" "); - if (splitUpInput[0].equals("list")) { + //String[] splitUpInput = userInput.split(" "); + if (userInput.startsWith("list")) { printTasks(); - } else if (splitUpInput[0].equals("done")) { + } else if (userInput.startsWith("done")) { tasks.get(Integer.parseInt(Character.toString( userInput.charAt(userInput.length() - 1))) - 1).setDone(); - } else if (splitUpInput[0].equals("todo")) { + } else if (userInput.startsWith("todo")) { Task task = new ToDo(userInput.substring(5)); tasks.add(task); System.out.println("Got it. I've added this task:\n " + task.toString() + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); - } else if (splitUpInput[0].equals("deadline")) { + } else if (userInput.startsWith("deadline")) { Task task = new Deadline(userInput.substring(9)); tasks.add(task); System.out.println("Got it. I've added this task:\n " + task.toString() + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); - } else if (splitUpInput[0].equals("event")) { + } else if (userInput.startsWith("event")) { Task task = new Event(userInput.substring(6)); tasks.add(task); System.out.println("Got it. I've added this task:\n " + task.toString() From da534c2e93eca9d5f61331ae30d921b51b916a98 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Tue, 11 Feb 2020 16:55:07 +0800 Subject: [PATCH 08/29] Throw exceptions --- src/main/java/Duke.java | 64 +++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 25301ff2b6..2c971f4b0d 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -11,6 +11,32 @@ public static void printTasks() { } } + public static void inputChecker(String userInput) throws IndexOutOfBoundsException, IllegalArgumentException { + if (userInput.startsWith("list")) { + printTasks(); + } else if (userInput.startsWith("done")) { + tasks.get(Integer.parseInt(Character.toString( + userInput.charAt(userInput.length() - 1))) - 1).setDone(); + } else if (userInput.startsWith("todo")) { + Task task = new ToDo(userInput.substring(5)); + tasks.add(task); + System.out.println("Got it. I've added this task:\n " + task.toString() + + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); + } else if (userInput.startsWith("deadline")) { + Task task = new Deadline(userInput.substring(9)); + tasks.add(task); + System.out.println("Got it. I've added this task:\n " + task.toString() + + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); + } else if (userInput.startsWith("event")) { + Task task = new Event(userInput.substring(6)); + tasks.add(task); + System.out.println("Got it. I've added this task:\n " + task.toString() + + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); + } else { + throw new IllegalArgumentException(); + } + } + public static void printLogo() { String logo = " ____ _ \n" + "| _ \\ _ _| | __ __ \n" @@ -26,30 +52,24 @@ public static void main(String[] args) { Scanner scan = new Scanner(System.in); String userInput = scan.nextLine(); while (!userInput.equals("bye")) { - //String[] splitUpInput = userInput.split(" "); - if (userInput.startsWith("list")) { - printTasks(); - } else if (userInput.startsWith("done")) { - tasks.get(Integer.parseInt(Character.toString( - userInput.charAt(userInput.length() - 1))) - 1).setDone(); - } else if (userInput.startsWith("todo")) { - Task task = new ToDo(userInput.substring(5)); - tasks.add(task); - System.out.println("Got it. I've added this task:\n " + task.toString() - + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); - } else if (userInput.startsWith("deadline")) { - Task task = new Deadline(userInput.substring(9)); - tasks.add(task); - System.out.println("Got it. I've added this task:\n " + task.toString() - + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); - } else if (userInput.startsWith("event")) { - Task task = new Event(userInput.substring(6)); - tasks.add(task); - System.out.println("Got it. I've added this task:\n " + task.toString() - + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); + try { + inputChecker(userInput); + } catch (IndexOutOfBoundsException e) { + System.out.println("You have given the wrong number of arguments\n" + + "Please try again or input \"bye\" to exit"); + } catch (IllegalArgumentException e) { + System.out.println("Sorry I don't understand that command. Here is the list of commands available\n" + + "\"bye\": to exit\n\"list\": to show the list of all your tasks\n\"todo\": add a todo\n" + + "\"deadline\": add a deadline\n\"event\': add an event\n" + + "\"done\": check off a task on your list"); } - userInput = scan.nextLine(); + userInput = scan.nextLine(); } System.out.println("Bye. Hope to see you again soon!"); } } + +// should have: +// invalid command, like no such starting word +// too few arguments +// incorrect format like "/by" -> "by" or sth \ No newline at end of file From cdaf1d1050b584758f0c5fd718d846f6ff6abc81 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Thu, 13 Feb 2020 14:10:00 +0800 Subject: [PATCH 09/29] Add idk what --- src/main/java/Duke.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 2c971f4b0d..3d258852ad 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -60,7 +60,7 @@ public static void main(String[] args) { } catch (IllegalArgumentException e) { System.out.println("Sorry I don't understand that command. Here is the list of commands available\n" + "\"bye\": to exit\n\"list\": to show the list of all your tasks\n\"todo\": add a todo\n" + - "\"deadline\": add a deadline\n\"event\': add an event\n" + + "\"deadline\": add a deadline\n\"event\": add an event\n" + "\"done\": check off a task on your list"); } userInput = scan.nextLine(); @@ -68,8 +68,3 @@ public static void main(String[] args) { System.out.println("Bye. Hope to see you again soon!"); } } - -// should have: -// invalid command, like no such starting word -// too few arguments -// incorrect format like "/by" -> "by" or sth \ No newline at end of file From 016a60c306d39d18cd644e10ca2ebb8735f93bd5 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Thu, 13 Feb 2020 16:12:20 +0800 Subject: [PATCH 10/29] Attempt to add TextUiTesting but failed --- text-ui-test/runtest.bat | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 text-ui-test/runtest.bat diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat new file mode 100644 index 0000000000..cce4731c3b --- /dev/null +++ b/text-ui-test/runtest.bat @@ -0,0 +1,21 @@ +@ECHO OFF + +REM create bin directory if it doesn't exist +if not exist ..\bin mkdir ..\bin + +REM delete output from previous run +del ACTUAL.TXT + +REM compile the code into the bin folder +javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\Duke.java +IF ERRORLEVEL 1 ( + echo ********** BUILD FAILURE ********** + exit /b 1 +) +REM no error here, errorlevel == 0 + +REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT +java -classpath ..\bin Duke < input.txt > ACTUAL.TXT + +REM compare the output to the expected output +FC ACTUAL.TXT EXPECTED.TXT \ No newline at end of file From 8e898b31e84b3dd345242c80adba563a3bdbb870 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Thu, 13 Feb 2020 16:33:47 +0800 Subject: [PATCH 11/29] Change "Duke" logo to "Hi" --- src/main/java/Duke.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 3d258852ad..8f009cae5f 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -38,11 +38,16 @@ public static void inputChecker(String userInput) throws IndexOutOfBoundsExcepti } public static void printLogo() { - String logo = " ____ _ \n" + /*String logo = " ____ _ \n" + "| _ \\ _ _| | __ __ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; + + */ + String logo = "| | \n" + + "|--| .\n" + + "| | |\n"; System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke\nWhat can I do for you?"); } From a2017c207b89271f0e3e444835837ca46c8a46d9 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Thu, 13 Feb 2020 16:40:35 +0800 Subject: [PATCH 12/29] Add "OIOIOIO" --- src/main/java/Duke.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 3d258852ad..f7be227fad 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -45,6 +45,7 @@ public static void printLogo() { + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke\nWhat can I do for you?"); + System.out.println("OIOIOIO"); } public static void main(String[] args) { From 2c7f3448758c6caf95bdfbb6f86680b0a9eb84f6 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Thu, 13 Feb 2020 16:45:26 +0800 Subject: [PATCH 13/29] Add list of commands to greeting --- src/main/java/Duke.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 2a79ea3805..a54f47347d 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -50,6 +50,10 @@ public static void printLogo() { "| | |\n"; System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke\nWhat can I do for you?"); + System.out.println("Sorry I don't understand that command. Here is the list of commands available\n" + + "\"bye\": to exit\n\"list\": to show the list of all your tasks\n\"todo\": add a todo\n" + + "\"deadline\": add a deadline\n\"event\": add an event\n" + + "\"done\": check off a task on your list"); System.out.println("OIOIOIO"); } From 447777df05ffe425cbd26f713f4c94e50269de7e Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Thu, 13 Feb 2020 16:47:08 +0800 Subject: [PATCH 14/29] Edit last statement --- src/main/java/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index f7be227fad..2e17b37911 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -66,6 +66,6 @@ public static void main(String[] args) { } userInput = scan.nextLine(); } - System.out.println("Bye. Hope to see you again soon!"); + System.out.println("Bye!"); } } From 8607dbf64c104d21bf3a543043061bc182d1a44e Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Thu, 13 Feb 2020 16:51:02 +0800 Subject: [PATCH 15/29] Add "Singapore" --- src/main/java/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 65e8507233..ba5517b3bf 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -75,6 +75,6 @@ public static void main(String[] args) { } userInput = scan.nextLine(); } - System.out.println("Bye!"); + System.out.println("Bye from Singapore!"); } } From 35a5861e6876cc35bc5c912bc81c30b0357069a4 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Thu, 13 Feb 2020 16:52:20 +0800 Subject: [PATCH 16/29] Add "Jurong" --- src/main/java/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index ba5517b3bf..411a160278 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -75,6 +75,6 @@ public static void main(String[] args) { } userInput = scan.nextLine(); } - System.out.println("Bye from Singapore!"); + System.out.println("Bye from Singapore, Jurong!"); } } From feb25686717c48e8322bcee53801238401135c54 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Thu, 13 Feb 2020 16:55:16 +0800 Subject: [PATCH 17/29] Delete "Jurong" --- src/main/java/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 411a160278..ba5517b3bf 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -75,6 +75,6 @@ public static void main(String[] args) { } userInput = scan.nextLine(); } - System.out.println("Bye from Singapore, Jurong!"); + System.out.println("Bye from Singapore!"); } } From eaa4979639798cbf8135801c896d7fef4ca5fe59 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Tue, 18 Feb 2020 16:16:26 +0800 Subject: [PATCH 18/29] Chang back to Duke --- src/main/java/Duke.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index ba5517b3bf..e5ff4566ef 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -38,16 +38,17 @@ public static void inputChecker(String userInput) throws IndexOutOfBoundsExcepti } public static void printLogo() { - /*String logo = " ____ _ \n" + String logo = " ____ _ \n" + "| _ \\ _ _| | __ __ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - */ - String logo = "| | \n" + + + /*String logo = "| | \n" + "|--| .\n" + "| | |\n"; + */ System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke\nWhat can I do for you?"); System.out.println("Sorry I don't understand that command. Here is the list of commands available\n" From b602d58a13d319521060b782ab32732c8bf39f0f Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Mon, 24 Feb 2020 21:20:48 +0800 Subject: [PATCH 19/29] Attempt at adding level 6 increment (but it fails on me) --- src/main/java/Duke.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e5ff4566ef..8bfc51b2b9 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -32,6 +32,14 @@ public static void inputChecker(String userInput) throws IndexOutOfBoundsExcepti tasks.add(task); System.out.println("Got it. I've added this task:\n " + task.toString() + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); + } else if (userInput.startsWith("delete")) { + //deleteTask(userInput.charAt(7)); + System.out.println("hello mewo"); + try { + System.out.println(userInput.charAt(7)); + } catch (Exception e) { + System.out.println(e.getMessage()); + } } else { throw new IllegalArgumentException(); } @@ -51,13 +59,17 @@ public static void printLogo() { */ System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke\nWhat can I do for you?"); - System.out.println("Sorry I don't understand that command. Here is the list of commands available\n" + System.out.println("Here is the list of commands available\n" + "\"bye\": to exit\n\"list\": to show the list of all your tasks\n\"todo\": add a todo\n" + "\"deadline\": add a deadline\n\"event\": add an event\n" + "\"done\": check off a task on your list"); System.out.println("OIOIOIO"); } + public static void deleteTask(int taskId) { + + } + public static void main(String[] args) { printLogo(); Scanner scan = new Scanner(System.in); From 2685652ac3a2a75f5d50503c67eb15c98d6fc915 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Sat, 29 Feb 2020 13:47:00 +0800 Subject: [PATCH 20/29] Add incomplete Level 6 increment --- src/main/java/Duke.java | 42 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 8bfc51b2b9..74d27d8865 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,6 +3,10 @@ public class Duke { static ArrayList tasks = new ArrayList<>(); + static String options = "Here is the list of commands available\n" + + "\"bye\": to exit\n\"list\": to show the list of all your tasks\n\"todo\": add a todo\n" + + "\"deadline\": add a deadline\n\"event\": add an event\n" + + "\"done\": check off a task on your list"; public static void printTasks() { System.out.println("Here are the tasks in your list:"); @@ -32,14 +36,12 @@ public static void inputChecker(String userInput) throws IndexOutOfBoundsExcepti tasks.add(task); System.out.println("Got it. I've added this task:\n " + task.toString() + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); - } else if (userInput.startsWith("delete")) { - //deleteTask(userInput.charAt(7)); - System.out.println("hello mewo"); - try { - System.out.println(userInput.charAt(7)); - } catch (Exception e) { - System.out.println(e.getMessage()); - } + } else if (userInput.startsWith("delete")) { // output is wrong once we have double digits. like i fI input 21, it actually works and won't give error + int taskId = Integer.parseInt(Character.toString(userInput.charAt(7))); + Task task = tasks.get(taskId - 1); + tasks.remove(task); + System.out.println("I have removed this task:\n" + task.toString() + + String.format("\nYou only have %d tasks left to do. 加油!", tasks.size())); } else { throw new IllegalArgumentException(); } @@ -51,23 +53,8 @@ public static void printLogo() { + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - - - /*String logo = "| | \n" + - "|--| .\n" + - "| | |\n"; - */ System.out.println("Hello from\n" + logo); - System.out.println("Hello! I'm Duke\nWhat can I do for you?"); - System.out.println("Here is the list of commands available\n" - + "\"bye\": to exit\n\"list\": to show the list of all your tasks\n\"todo\": add a todo\n" + - "\"deadline\": add a deadline\n\"event\": add an event\n" + - "\"done\": check off a task on your list"); - System.out.println("OIOIOIO"); - } - - public static void deleteTask(int taskId) { - + System.out.println(options); } public static void main(String[] args) { @@ -80,11 +67,10 @@ public static void main(String[] args) { } catch (IndexOutOfBoundsException e) { System.out.println("You have given the wrong number of arguments\n" + "Please try again or input \"bye\" to exit"); + System.out.println(e.getMessage()); } catch (IllegalArgumentException e) { - System.out.println("Sorry I don't understand that command. Here is the list of commands available\n" - + "\"bye\": to exit\n\"list\": to show the list of all your tasks\n\"todo\": add a todo\n" + - "\"deadline\": add a deadline\n\"event\": add an event\n" + - "\"done\": check off a task on your list"); + System.out.println("Sorry I don't understand that command.\n" + options); + System.out.println(e.getMessage()); } userInput = scan.nextLine(); } From a29ddcf78d26031e2550730ca23eac2edc8d039d Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Sat, 29 Feb 2020 21:40:14 +0800 Subject: [PATCH 21/29] Add Level 7 increment through PrintWriter --- src/main/java/Duke.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e5ff4566ef..fea5ee6b4b 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,3 +1,5 @@ +import java.io.FileNotFoundException; +import java.io.PrintWriter; import java.util.Scanner; import java.util.ArrayList; @@ -6,8 +8,15 @@ public class Duke { public static void printTasks() { System.out.println("Here are the tasks in your list:"); + String output = ""; for (Task task : tasks) { System.out.println(String.format("%d. %s", task.getTaskId(), task.toString())); + output += String.format("%d. %s\n", task.getTaskId(), task.toString()); + } + try (PrintWriter printer = new PrintWriter("out.txt")) { + printer.println(output); + } catch (FileNotFoundException e) { + System.out.println(e.getMessage()); } } From 88e44fa9a4c28f020d7fadb2b5a6ebd5b44987e3 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Sun, 1 Mar 2020 13:32:04 +0800 Subject: [PATCH 22/29] Add Code Quality increment --- src/main/java/Duke.java | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5dcbe6251a..f814abe2bb 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -5,9 +5,12 @@ public class Duke { static ArrayList tasks = new ArrayList<>(); - static String options = "Here is the list of commands available\n" - + "\"bye\": to exit\n\"list\": to show the list of all your tasks\n\"todo\": add a todo\n" + - "\"deadline\": add a deadline\n\"event\": add an event\n" + + static String commands = "Here is the list of commands available\n" + + "\"bye\": to exit\n" + + "\"list\": to show the list of all your tasks\n" + + "\"todo\": add a todo\n" + + "\"deadline\": add a deadline\n" + + "\"event\": add an event\n" + "\"done\": check off a task on your list"; public static void printTasks() { @@ -19,12 +22,12 @@ public static void printTasks() { } try (PrintWriter printer = new PrintWriter("out.txt")) { printer.println(output); - } catch (FileNotFoundException e) { - System.out.println(e.getMessage()); + } catch (FileNotFoundException exception) { + System.out.println(exception.getMessage()); } } - public static void inputChecker(String userInput) throws IndexOutOfBoundsException, IllegalArgumentException { + public static void checkInput(String userInput) throws IndexOutOfBoundsException, IllegalArgumentException { if (userInput.startsWith("list")) { printTasks(); } else if (userInput.startsWith("done")) { @@ -63,7 +66,7 @@ public static void printLogo() { + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); - System.out.println(options); + System.out.println(commands); } public static void main(String[] args) { @@ -72,14 +75,14 @@ public static void main(String[] args) { String userInput = scan.nextLine(); while (!userInput.equals("bye")) { try { - inputChecker(userInput); - } catch (IndexOutOfBoundsException e) { + checkInput(userInput); + } catch (IndexOutOfBoundsException exception) { System.out.println("You have given the wrong number of arguments\n" + "Please try again or input \"bye\" to exit"); - System.out.println(e.getMessage()); - } catch (IllegalArgumentException e) { - System.out.println("Sorry I don't understand that command.\n" + options); - System.out.println(e.getMessage()); + System.out.println(exception.getMessage()); + } catch (IllegalArgumentException exception) { + System.out.println("Sorry I don't understand that command.\n" + commands); + System.out.println(exception.getMessage()); } userInput = scan.nextLine(); } From 4d4a1953f32772a629f24e3bdfec725d5631c98c Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Mon, 2 Mar 2020 03:57:03 +0800 Subject: [PATCH 23/29] Add More OOP increment --- src/main/java/Command.java | 9 ++++ src/main/java/DeadlineCommand.java | 10 ++++ src/main/java/DeleteCommand.java | 9 ++++ src/main/java/DoneCommand.java | 7 +++ src/main/java/Duke.java | 77 +++--------------------------- src/main/java/EventCommand.java | 10 ++++ src/main/java/ListCommand.java | 13 +++++ src/main/java/Messages.java | 16 +++++++ src/main/java/NoSuchCommand.java | 6 +++ src/main/java/Parser.java | 31 ++++++++++++ src/main/java/Storage.java | 22 +++++++++ src/main/java/TextUi.java | 45 +++++++++++++++++ src/main/java/TodoCommand.java | 16 +++++++ 13 files changed, 200 insertions(+), 71 deletions(-) create mode 100644 src/main/java/Command.java create mode 100644 src/main/java/DeadlineCommand.java create mode 100644 src/main/java/DeleteCommand.java create mode 100644 src/main/java/DoneCommand.java create mode 100644 src/main/java/EventCommand.java create mode 100644 src/main/java/ListCommand.java create mode 100644 src/main/java/Messages.java create mode 100644 src/main/java/NoSuchCommand.java create mode 100644 src/main/java/Parser.java create mode 100644 src/main/java/Storage.java create mode 100644 src/main/java/TextUi.java create mode 100644 src/main/java/TodoCommand.java diff --git a/src/main/java/Command.java b/src/main/java/Command.java new file mode 100644 index 0000000000..48fa5ba4bf --- /dev/null +++ b/src/main/java/Command.java @@ -0,0 +1,9 @@ +public class Command { + protected String command; + protected TextUi textUi; + + public Command(String command) { + this.command = command; + textUi = new TextUi(); + } +} diff --git a/src/main/java/DeadlineCommand.java b/src/main/java/DeadlineCommand.java new file mode 100644 index 0000000000..37eb958dc8 --- /dev/null +++ b/src/main/java/DeadlineCommand.java @@ -0,0 +1,10 @@ +public class DeadlineCommand extends Command { + private Deadline deadline; + + public DeadlineCommand(String command) throws IndexOutOfBoundsException { + super(command); + deadline = new Deadline(command.substring(9)); + textUi.printDeadlineMessage(deadline); + Duke.tasks.add(deadline); + } +} diff --git a/src/main/java/DeleteCommand.java b/src/main/java/DeleteCommand.java new file mode 100644 index 0000000000..a926ca44b0 --- /dev/null +++ b/src/main/java/DeleteCommand.java @@ -0,0 +1,9 @@ +public class DeleteCommand extends Command { + public DeleteCommand(String command) throws IndexOutOfBoundsException { + super(command); + int selectedTaskId = Integer.parseInt(command.substring(7)); + Task task = Duke.tasks.get(selectedTaskId - 1); + Duke.tasks.remove(task); + textUi.printDeleteMessage(task, Duke.tasks.size()); + } +} diff --git a/src/main/java/DoneCommand.java b/src/main/java/DoneCommand.java new file mode 100644 index 0000000000..cab21a6d2e --- /dev/null +++ b/src/main/java/DoneCommand.java @@ -0,0 +1,7 @@ +public class DoneCommand extends Command { + public DoneCommand(String command) { + super(command); + Duke.tasks.get(Integer.parseInt(Character.toString( + command.charAt(command.length() - 1))) - 1).setDone(); + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index f814abe2bb..01624be17a 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -5,87 +5,22 @@ public class Duke { static ArrayList tasks = new ArrayList<>(); - static String commands = "Here is the list of commands available\n" - + "\"bye\": to exit\n" + - "\"list\": to show the list of all your tasks\n" + - "\"todo\": add a todo\n" + - "\"deadline\": add a deadline\n" + - "\"event\": add an event\n" + - "\"done\": check off a task on your list"; - - public static void printTasks() { - System.out.println("Here are the tasks in your list:"); - String output = ""; - for (Task task : tasks) { - System.out.println(String.format("%d. %s", task.getTaskId(), task.toString())); - output += String.format("%d. %s\n", task.getTaskId(), task.toString()); - } - try (PrintWriter printer = new PrintWriter("out.txt")) { - printer.println(output); - } catch (FileNotFoundException exception) { - System.out.println(exception.getMessage()); - } - } - - public static void checkInput(String userInput) throws IndexOutOfBoundsException, IllegalArgumentException { - if (userInput.startsWith("list")) { - printTasks(); - } else if (userInput.startsWith("done")) { - tasks.get(Integer.parseInt(Character.toString( - userInput.charAt(userInput.length() - 1))) - 1).setDone(); - } else if (userInput.startsWith("todo")) { - Task task = new ToDo(userInput.substring(5)); - tasks.add(task); - System.out.println("Got it. I've added this task:\n " + task.toString() - + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); - } else if (userInput.startsWith("deadline")) { - Task task = new Deadline(userInput.substring(9)); - tasks.add(task); - System.out.println("Got it. I've added this task:\n " + task.toString() - + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); - } else if (userInput.startsWith("event")) { - Task task = new Event(userInput.substring(6)); - tasks.add(task); - System.out.println("Got it. I've added this task:\n " + task.toString() - + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); - } else if (userInput.startsWith("delete")) { // output is wrong once we have double digits. like i fI input 21, it actually works and won't give error - int taskId = Integer.parseInt(Character.toString(userInput.charAt(7))); - Task task = tasks.get(taskId - 1); - tasks.remove(task); - System.out.println("I have removed this task:\n" + task.toString() + - String.format("\nYou only have %d tasks left to do. 加油!", tasks.size())); - } else { - throw new IllegalArgumentException(); - } - } - - public static void printLogo() { - String logo = " ____ _ \n" - + "| _ \\ _ _| | __ __ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - System.out.println(commands); - } + static TextUi textUi = new TextUi(); public static void main(String[] args) { - printLogo(); + textUi.printWelcomeMessage(); Scanner scan = new Scanner(System.in); String userInput = scan.nextLine(); while (!userInput.equals("bye")) { try { - checkInput(userInput); + Parser.parseInput(userInput); } catch (IndexOutOfBoundsException exception) { - System.out.println("You have given the wrong number of arguments\n" + - "Please try again or input \"bye\" to exit"); - System.out.println(exception.getMessage()); + textUi.printIndexOutOfBoundsExceptionMessage(exception); } catch (IllegalArgumentException exception) { - System.out.println("Sorry I don't understand that command.\n" + commands); - System.out.println(exception.getMessage()); + textUi.printIllegalArgumentExceptionMessage(exception); } userInput = scan.nextLine(); } - System.out.println("Bye from Singapore!"); + textUi.printExitMessage(); } } diff --git a/src/main/java/EventCommand.java b/src/main/java/EventCommand.java new file mode 100644 index 0000000000..14e5a20420 --- /dev/null +++ b/src/main/java/EventCommand.java @@ -0,0 +1,10 @@ +public class EventCommand extends Command { + private Event event; + + public EventCommand(String command) throws IndexOutOfBoundsException { + super(command); + event = new Event(command.substring(7)); + textUi.printEventMessage(event); + Duke.tasks.add(event); + } +} diff --git a/src/main/java/ListCommand.java b/src/main/java/ListCommand.java new file mode 100644 index 0000000000..c3ca3196d4 --- /dev/null +++ b/src/main/java/ListCommand.java @@ -0,0 +1,13 @@ +public class ListCommand extends Command { + private Storage storage; + + public ListCommand(String command) { + super(command); + storage = new Storage(); + for (Task task : Duke.tasks) { + System.out.println(String.format("%d. %s", task.getTaskId(), task.toString())); + storage.addToList(String.format("%d. %s", task.getTaskId(), task.toString())); + } + storage.storeList(); + } +} diff --git a/src/main/java/Messages.java b/src/main/java/Messages.java new file mode 100644 index 0000000000..c4911c45d0 --- /dev/null +++ b/src/main/java/Messages.java @@ -0,0 +1,16 @@ +public class Messages { + public static String LIST_OF_COMMANDS = "Here is the list of commands available\n" + + "\"bye\": to exit\n" + + "\"list\": to show the list of all your tasks\n" + + "\"todo\": add a todo\n" + + "\"deadline\": add a deadline\n" + + "\"event\": add an event\n" + + "\"done\": check off a task on your list"; + public static String EXIT_MESSAGE = "Bye la you"; + public static String LOGO = " ____ _ \n" + + "| _ \\\\ _ _| | __ __ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\\\__,_|_|\\_\\\\___\n"; + public static String WELCOME_MESSAGE = "Hello there I am\n" + LOGO + LIST_OF_COMMANDS; +} diff --git a/src/main/java/NoSuchCommand.java b/src/main/java/NoSuchCommand.java new file mode 100644 index 0000000000..cfccacc2a7 --- /dev/null +++ b/src/main/java/NoSuchCommand.java @@ -0,0 +1,6 @@ +public class NoSuchCommand extends Command { + public NoSuchCommand(String command) throws IllegalArgumentException{ + super(command); + throw new IllegalArgumentException(); + } +} diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 0000000000..cea46947a1 --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,31 @@ +public class Parser { + public static Command parseInput(String userInput) throws IndexOutOfBoundsException, IllegalArgumentException { + String[] separatedUserInput = userInput.trim().split(" "); + String firstWordOfUserInput = separatedUserInput[0]; + Command command = new Command("wait ah"); + switch (firstWordOfUserInput) { + case "todo": + command = new TodoCommand(userInput); + break; + case "event": + command = new EventCommand(userInput); + break; + case "deadline": + command = new DeadlineCommand(userInput); + break; + case "done": + command = new DoneCommand(userInput); + break; + case "delete": + command = new DeleteCommand(userInput); + break; + case "list": + command = new ListCommand(userInput); + break; + default: + command = new NoSuchCommand(userInput); + break; + } + return command; + } +} diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 0000000000..a2546c2a5c --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,22 @@ +import java.io.PrintWriter; +import java.io.FileNotFoundException; + +public class Storage { + private String output; + + public Storage() { + this.output = ""; + } + + public void addToList(String newString) { + output += (newString + "\n"); + } + + public void storeList() { + try (PrintWriter printer = new PrintWriter("out.txt")) { + printer.println(output); + } catch (FileNotFoundException exception) { + System.out.println(exception.getMessage()); + } + } +} diff --git a/src/main/java/TextUi.java b/src/main/java/TextUi.java new file mode 100644 index 0000000000..9510fe5800 --- /dev/null +++ b/src/main/java/TextUi.java @@ -0,0 +1,45 @@ +public class TextUi { + private boolean isUserDone; + + public TextUi() { + this.isUserDone = false; + } + + public void printWelcomeMessage() { + System.out.println(Messages.WELCOME_MESSAGE); + } + + public void printExitMessage() { + System.out.println(Messages.EXIT_MESSAGE); + } + + public void printIndexOutOfBoundsExceptionMessage(Exception exception) { + System.out.println("You have given the wrong number of arguments or the wrong set of arguments\n" + + "Please try again or input \"bye\" to exit" + exception.getMessage()); + } + + public void printIllegalArgumentExceptionMessage(Exception exception) { + System.out.println("Sorry I don't understand that command.\n" + Messages.LIST_OF_COMMANDS + + exception.getMessage()); + } + + public void printTodoMessage(Task task) { + System.out.println("Got it. I've added this task:\n " + task.toString() + + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); + } + + public void printDeadlineMessage(Task task) { + System.out.println("Got it. I've added this task:\n " + task.toString() + + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); + } + + public void printEventMessage(Task task) { + System.out.println("Got it. I've added this task:\n " + task.toString() + + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); + } + + public void printDeleteMessage(Task task, int numOfTasksLeft) { + System.out.println("I have removed this task:\n" + task.toString() + + String.format("\nYou only have %d tasks left to do. 加油!", numOfTasksLeft)); + } +} diff --git a/src/main/java/TodoCommand.java b/src/main/java/TodoCommand.java new file mode 100644 index 0000000000..e1b2632147 --- /dev/null +++ b/src/main/java/TodoCommand.java @@ -0,0 +1,16 @@ +public class TodoCommand extends Command { + private ToDo todo; + + public TodoCommand(String command) throws IndexOutOfBoundsException { + super(command); + todo = new ToDo(command.substring(5)); + textUi.printTodoMessage(todo); + Duke.tasks.add(todo); + } +} + + +/* +Task task = new ToDo(userInput.substring(5)); + tasks.add(task); + */ From 60122daef226c1aa7db8184ab5f89bf9ffefb1f1 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Mon, 2 Mar 2020 09:52:27 +0800 Subject: [PATCH 24/29] Add Level 9 increment with a minor bug --- src/main/java/Command.java | 8 ++++++++ src/main/java/Duke.java | 13 +++++++++++++ src/main/java/EventCommand.java | 2 +- src/main/java/FindCommand.java | 22 ++++++++++++++++++++++ src/main/java/Messages.java | 2 +- src/main/java/Parser.java | 4 +++- src/main/java/TextUi.java | 9 ++++++--- src/main/java/TodoCommand.java | 6 ------ 8 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 src/main/java/FindCommand.java diff --git a/src/main/java/Command.java b/src/main/java/Command.java index 48fa5ba4bf..73920bf803 100644 --- a/src/main/java/Command.java +++ b/src/main/java/Command.java @@ -1,7 +1,15 @@ +/** + * + */ + public class Command { protected String command; protected TextUi textUi; + public Command() { + this.command = ""; + } + public Command(String command) { this.command = command; textUi = new TextUi(); diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 01624be17a..4b75a50b23 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,10 +3,23 @@ import java.util.Scanner; import java.util.ArrayList; +/** + * Duke is a project that keeps a list of the tasks that need to be completed. + */ + public class Duke { static ArrayList tasks = new ArrayList<>(); + + /** + * Stores any methods that require interaction with the user. + */ + static TextUi textUi = new TextUi(); + /** + * Contains all the objects needed to run the project. + */ + public static void main(String[] args) { textUi.printWelcomeMessage(); Scanner scan = new Scanner(System.in); diff --git a/src/main/java/EventCommand.java b/src/main/java/EventCommand.java index 14e5a20420..84f874e42c 100644 --- a/src/main/java/EventCommand.java +++ b/src/main/java/EventCommand.java @@ -3,7 +3,7 @@ public class EventCommand extends Command { public EventCommand(String command) throws IndexOutOfBoundsException { super(command); - event = new Event(command.substring(7)); + event = new Event(command.substring(6)); textUi.printEventMessage(event); Duke.tasks.add(event); } diff --git a/src/main/java/FindCommand.java b/src/main/java/FindCommand.java new file mode 100644 index 0000000000..e25aba4cb2 --- /dev/null +++ b/src/main/java/FindCommand.java @@ -0,0 +1,22 @@ +public class FindCommand extends Command { + public FindCommand(String command) { + super(command); + execute(command); + } + + public void execute(String command) { + textUi.printFindMessage(command); + String keyword = command.substring(5); + boolean isFound = false; + for (Task task : Duke.tasks) { + if (task.getTaskName().contains(keyword)) { + System.out.println(task.getTaskId() + ". " + task.toString()); + isFound = true; + } + } + if (!isFound) { + System.out.println("Sorry there are no matches"); + } + + } +} diff --git a/src/main/java/Messages.java b/src/main/java/Messages.java index c4911c45d0..94def2b599 100644 --- a/src/main/java/Messages.java +++ b/src/main/java/Messages.java @@ -5,7 +5,7 @@ public class Messages { "\"todo\": add a todo\n" + "\"deadline\": add a deadline\n" + "\"event\": add an event\n" + - "\"done\": check off a task on your list"; + "\"done\": check off a task on your list\n"; public static String EXIT_MESSAGE = "Bye la you"; public static String LOGO = " ____ _ \n" + "| _ \\\\ _ _| | __ __ \n" + diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index cea46947a1..3febcea1af 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -2,7 +2,7 @@ public class Parser { public static Command parseInput(String userInput) throws IndexOutOfBoundsException, IllegalArgumentException { String[] separatedUserInput = userInput.trim().split(" "); String firstWordOfUserInput = separatedUserInput[0]; - Command command = new Command("wait ah"); + Command command; switch (firstWordOfUserInput) { case "todo": command = new TodoCommand(userInput); @@ -22,6 +22,8 @@ public static Command parseInput(String userInput) throws IndexOutOfBoundsExcept case "list": command = new ListCommand(userInput); break; + case "find": + command = new FindCommand(userInput); default: command = new NoSuchCommand(userInput); break; diff --git a/src/main/java/TextUi.java b/src/main/java/TextUi.java index 9510fe5800..124d3ec979 100644 --- a/src/main/java/TextUi.java +++ b/src/main/java/TextUi.java @@ -15,12 +15,11 @@ public void printExitMessage() { public void printIndexOutOfBoundsExceptionMessage(Exception exception) { System.out.println("You have given the wrong number of arguments or the wrong set of arguments\n" + - "Please try again or input \"bye\" to exit" + exception.getMessage()); + "Please try again or input \"bye\" to exit"); } public void printIllegalArgumentExceptionMessage(Exception exception) { - System.out.println("Sorry I don't understand that command.\n" + Messages.LIST_OF_COMMANDS + - exception.getMessage()); + System.out.println("Sorry I don't understand that command.\n" + Messages.LIST_OF_COMMANDS); } public void printTodoMessage(Task task) { @@ -42,4 +41,8 @@ public void printDeleteMessage(Task task, int numOfTasksLeft) { System.out.println("I have removed this task:\n" + task.toString() + String.format("\nYou only have %d tasks left to do. 加油!", numOfTasksLeft)); } + + public void printFindMessage(String command) { + System.out.println("The following may be relevant to what you are looking for:"); + } } diff --git a/src/main/java/TodoCommand.java b/src/main/java/TodoCommand.java index e1b2632147..349332f1d8 100644 --- a/src/main/java/TodoCommand.java +++ b/src/main/java/TodoCommand.java @@ -8,9 +8,3 @@ public TodoCommand(String command) throws IndexOutOfBoundsException { Duke.tasks.add(todo); } } - - -/* -Task task = new ToDo(userInput.substring(5)); - tasks.add(task); - */ From bc2cba16461afeda9813ddd3a07c265f6d2062eb Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Mon, 2 Mar 2020 10:36:12 +0800 Subject: [PATCH 25/29] Add JavaDocs --- src/main/java/Command.java | 9 ++++++ src/main/java/Deadline.java | 14 ++++++++ src/main/java/DeadlineCommand.java | 14 ++++++++ src/main/java/DeleteCommand.java | 10 ++++++ src/main/java/DoneCommand.java | 9 ++++++ src/main/java/Duke.java | 9 ++++++ src/main/java/Event.java | 13 ++++++++ src/main/java/EventCommand.java | 14 ++++++++ src/main/java/ListCommand.java | 14 ++++++++ src/main/java/Messages.java | 20 ++++++++++++ src/main/java/NoSuchCommand.java | 11 +++++++ src/main/java/Parser.java | 13 ++++++++ src/main/java/Storage.java | 21 ++++++++++++ src/main/java/Task.java | 51 ++++++++++++++++++++++++++++-- src/main/java/TextUi.java | 12 +++++-- src/main/java/ToDo.java | 10 ++++++ src/main/java/TodoCommand.java | 21 ++++++++---- 17 files changed, 255 insertions(+), 10 deletions(-) diff --git a/src/main/java/Command.java b/src/main/java/Command.java index 48fa5ba4bf..7ab1da7b47 100644 --- a/src/main/java/Command.java +++ b/src/main/java/Command.java @@ -1,7 +1,16 @@ +/** + * A class that is the foundation where all the Commands extends from. + */ + public class Command { protected String command; protected TextUi textUi; + /** + * Constructor for Command object. + * @param command the command inputted by the user, with trailing and leading white spaces removed. + */ + public Command(String command) { this.command = command; textUi = new TextUi(); diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 2a26c8072e..4771c848e3 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,6 +1,20 @@ +/** + * Extends from Task. Stores the information needed for Deadline. + */ + public class Deadline extends Task { + + /** + * The latest date the task must be completed. + */ + private String latestDate; + /** + * Constructor for Deadline. + * @param userInput the command that the user typed in. + */ + public Deadline(String userInput) { super(userInput.substring(0, userInput.indexOf(" /"))); this.latestDate = userInput.substring(userInput.indexOf("/") + 4); diff --git a/src/main/java/DeadlineCommand.java b/src/main/java/DeadlineCommand.java index 37eb958dc8..863b7370ce 100644 --- a/src/main/java/DeadlineCommand.java +++ b/src/main/java/DeadlineCommand.java @@ -1,6 +1,20 @@ +/** + * Extends from Command. Gives instructions on how to proceed when a Deadline task is added. + */ + public class DeadlineCommand extends Command { + + /** + * Create a new Deadline task as requested by the user. + */ + private Deadline deadline; + /** + * Constructor for DeadlineCommand. + * @param command the command that the user typed in. + * @throws IndexOutOfBoundsException throws IndexOutOfBoundsException when there are invalid arguments. + */ public DeadlineCommand(String command) throws IndexOutOfBoundsException { super(command); deadline = new Deadline(command.substring(9)); diff --git a/src/main/java/DeleteCommand.java b/src/main/java/DeleteCommand.java index a926ca44b0..b6498e02a6 100644 --- a/src/main/java/DeleteCommand.java +++ b/src/main/java/DeleteCommand.java @@ -1,4 +1,14 @@ +/** + * Extends from Command. Gives instructions on how to proceed when a task needs to be deleted. + */ + public class DeleteCommand extends Command { + + /** + * Constructor for DeleteCommand. + * @param command the command that the user typed in. + * @throws IndexOutOfBoundsException throw IndexOutOfBoundsException when there are invalid arguments. + */ public DeleteCommand(String command) throws IndexOutOfBoundsException { super(command); int selectedTaskId = Integer.parseInt(command.substring(7)); diff --git a/src/main/java/DoneCommand.java b/src/main/java/DoneCommand.java index cab21a6d2e..ad7b8d013c 100644 --- a/src/main/java/DoneCommand.java +++ b/src/main/java/DoneCommand.java @@ -1,4 +1,13 @@ +/** + * Extends from Command. Gives instructions on how to proceed when a task is completed. + */ + public class DoneCommand extends Command { + + /** + * Constructor for DoneCommand. + * @param command the command that the user typed in. + */ public DoneCommand(String command) { super(command); Duke.tasks.get(Integer.parseInt(Character.toString( diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 01624be17a..f857cb79c1 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,10 +3,19 @@ import java.util.Scanner; import java.util.ArrayList; +/** + * Project Duke. + * Keeps a record of the tasks that the user has, which can be saved into and loaded from a hard disk. + */ + public class Duke { static ArrayList tasks = new ArrayList<>(); static TextUi textUi = new TextUi(); + /** + * Contains all the necessary objects to keep track of the tasks. + * @param args + */ public static void main(String[] args) { textUi.printWelcomeMessage(); Scanner scan = new Scanner(System.in); diff --git a/src/main/java/Event.java b/src/main/java/Event.java index a2e84d46a4..a5f8baed09 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,6 +1,19 @@ +/** + * Extends from Task. Stores the information needed for Event. + */ + public class Event extends Task { + + /** + * The details of the event as stated by the user. + */ + private String eventDetails; + /** + * Constructor for Event. + * @param userInput the command that the user typed in. + */ public Event(String userInput) { super(userInput.substring(0, userInput.indexOf(" /"))); this.eventDetails = userInput.substring(userInput.indexOf("/") + 4); diff --git a/src/main/java/EventCommand.java b/src/main/java/EventCommand.java index 14e5a20420..f4d6a0d4b4 100644 --- a/src/main/java/EventCommand.java +++ b/src/main/java/EventCommand.java @@ -1,6 +1,20 @@ +/** + * Extends from Command. Gives instructions on how to proceed when an Event task is added. + */ + public class EventCommand extends Command { + + /** + * Creates a new Event task as requested by the user. + */ private Event event; + /** + * Constructor for EventCommand. + * @param command the command that the user typed in. + * @throws IndexOutOfBoundsException throws IndexOutOfBoundsException when there are invalid arguments. + */ + public EventCommand(String command) throws IndexOutOfBoundsException { super(command); event = new Event(command.substring(7)); diff --git a/src/main/java/ListCommand.java b/src/main/java/ListCommand.java index c3ca3196d4..2cb04bfb8b 100644 --- a/src/main/java/ListCommand.java +++ b/src/main/java/ListCommand.java @@ -1,6 +1,20 @@ +/** + * Extends from Command. Gives instructions on how to proceed when a list of the tasks is requested. + */ + public class ListCommand extends Command { + + /** + * Stores the list of tasks in a text file on the hard disk. + */ + private Storage storage; + /** + * Constructor for ListCommand. + * @param command the command that the user typed in. + */ + public ListCommand(String command) { super(command); storage = new Storage(); diff --git a/src/main/java/Messages.java b/src/main/java/Messages.java index c4911c45d0..8ff9e0f8a0 100644 --- a/src/main/java/Messages.java +++ b/src/main/java/Messages.java @@ -1,4 +1,12 @@ +/** + * Contains all the frequently used messages displayed to the user. + */ + public class Messages { + + /** + * List of commands that the user can input. + */ public static String LIST_OF_COMMANDS = "Here is the list of commands available\n" + "\"bye\": to exit\n" + "\"list\": to show the list of all your tasks\n" + @@ -6,11 +14,23 @@ public class Messages { "\"deadline\": add a deadline\n" + "\"event\": add an event\n" + "\"done\": check off a task on your list"; + + /** + * Exit message. + */ public static String EXIT_MESSAGE = "Bye la you"; + + /** + * Duke logo. + */ public static String LOGO = " ____ _ \n" + "| _ \\\\ _ _| | __ __ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\\\__,_|_|\\_\\\\___\n"; + + /** + * Welcome message when the user first enters. + */ public static String WELCOME_MESSAGE = "Hello there I am\n" + LOGO + LIST_OF_COMMANDS; } diff --git a/src/main/java/NoSuchCommand.java b/src/main/java/NoSuchCommand.java index cfccacc2a7..6417982aeb 100644 --- a/src/main/java/NoSuchCommand.java +++ b/src/main/java/NoSuchCommand.java @@ -1,4 +1,15 @@ +/** + * Extends from Command. Gives instructions on how to proceed when the command is not recognised. + */ + public class NoSuchCommand extends Command { + + /** + * Constructor for NoSuchCommand. + * @param command the command that the user typed in. + * @throws IllegalArgumentException throws IllegalArgumentException within the constructor for the main method + * to catch. + */ public NoSuchCommand(String command) throws IllegalArgumentException{ super(command); throw new IllegalArgumentException(); diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index cea46947a1..be1359cfba 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,4 +1,17 @@ +/** + * Makes sense of the user's input and allocate them to the different commands. + */ + public class Parser { + + /** + * Breaks down the user's input to allocate to the different commands. + * @param userInput the command that the user typed in. + * @return command. + * @throws IndexOutOfBoundsException when one of the method throws IndexOutOfBoundsException. + * @throws IllegalArgumentException when one of the method throws IllegalArgumentException. + */ + public static Command parseInput(String userInput) throws IndexOutOfBoundsException, IllegalArgumentException { String[] separatedUserInput = userInput.trim().split(" "); String firstWordOfUserInput = separatedUserInput[0]; diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index a2546c2a5c..c57eaacc80 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -1,17 +1,38 @@ import java.io.PrintWriter; import java.io.FileNotFoundException; +/** + * Activated when the list is requested. Generates a text file from the list automatically. + */ + public class Storage { + + /** + * The output seen in the text file. + */ private String output; + /** + * Constructor for Storage. + */ + public Storage() { this.output = ""; } + /** + * Adds new text to the output. + * @param newString the string to be added on. + */ + public void addToList(String newString) { output += (newString + "\n"); } + /** + * Generates the text file of the list of tasks. + */ + public void storeList() { try (PrintWriter printer = new PrintWriter("out.txt")) { printer.println(output); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 72c585f80c..5c35e22ea6 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,32 +1,79 @@ +/** + * Contains all the information needed to construct a Task object. + */ + public class Task { + + /** + * Descrption of the task. + */ + protected String taskName; + + /** + * Status of completion of the task. + */ + protected boolean isDone; + + /** + * The task index number. + */ + protected int taskId; + + /** + * The total number of tasks that has been inputted by the user. + */ + protected static int totalNumOfTasks = 0; + /** + * Constructor for Task. + * @param taskName description of the task as stated by the user. + */ + public Task(String taskName) { this.taskName = taskName; this.isDone = false; this.taskId = ++this.totalNumOfTasks; } + /** + * To mark a task as completed. + */ + public void setDone() { this.isDone = true; System.out.println("Nice! I've marked this task as done:\n" + String.format("[✓] %s", this.taskName)); } + /** + * To get the task index number. + * @return taskId. + */ public int getTaskId() { return taskId; } + /** + * Gives the status of completion of the task. + * @return status of completino of the task. + */ + public boolean isDone() { return isDone; } - public String getTaskName() { + /*public String getTaskName() { return taskName; - } + }*/ + + /** + * Gives the total number of tasks that the user has inputted so far. + * @return total number of tasks. + */ public static int getTotalNumOfTasks() { return totalNumOfTasks; diff --git a/src/main/java/TextUi.java b/src/main/java/TextUi.java index 9510fe5800..36c96dfc23 100644 --- a/src/main/java/TextUi.java +++ b/src/main/java/TextUi.java @@ -1,8 +1,16 @@ +/** + * Stores instructions to print frequently displayed messages. + */ + public class TextUi { - private boolean isUserDone; + //private boolean isUserDone; + + /** + * Constructor for TextUi. + */ public TextUi() { - this.isUserDone = false; + //this.isUserDone = false; } public void printWelcomeMessage() { diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java index 243e1b2fa4..1a5f323902 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/ToDo.java @@ -1,4 +1,14 @@ +/** + * Extends from Task. Stores the information needed for ToDo. + */ + public class ToDo extends Task { + + /** + * Constructor for ToDo. + * @param taskName description of the toDo. + */ + public ToDo(String taskName) { super(taskName); } diff --git a/src/main/java/TodoCommand.java b/src/main/java/TodoCommand.java index e1b2632147..1e39bdaca5 100644 --- a/src/main/java/TodoCommand.java +++ b/src/main/java/TodoCommand.java @@ -1,6 +1,21 @@ +/** + * Extends from Command. Gives instructions on how to proceed when a ToDo task is added. + */ + public class TodoCommand extends Command { + + /** + * Creates a new ToDo task as requested by the user. + */ + private ToDo todo; + /** + * Constructor for TodoCommand. + * @param command the command that the user typed in. + * @throws IndexOutOfBoundsException throws IndexOutOfBoundsException when there are invalid arguments. + */ + public TodoCommand(String command) throws IndexOutOfBoundsException { super(command); todo = new ToDo(command.substring(5)); @@ -8,9 +23,3 @@ public TodoCommand(String command) throws IndexOutOfBoundsException { Duke.tasks.add(todo); } } - - -/* -Task task = new ToDo(userInput.substring(5)); - tasks.add(task); - */ From 5dcc30070da4f044b8728b61786abb23dee1b43c Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Mon, 2 Mar 2020 22:49:52 +0800 Subject: [PATCH 26/29] Fix minor bug --- src/main/java/Task.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 5c35e22ea6..1050c367ef 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -66,9 +66,9 @@ public boolean isDone() { return isDone; } - /*public String getTaskName() { + public String getTaskName() { return taskName; - }*/ + } /** * Gives the total number of tasks that the user has inputted so far. From d656f7b3b02f3e9a7316e95e3a8a5fd34a651f39 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Mon, 2 Mar 2020 23:08:48 +0800 Subject: [PATCH 27/29] Fix spelling error and created a JAR file? --- src/main/java/Task.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 1050c367ef..d43d8b66ac 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -59,7 +59,7 @@ public int getTaskId() { /** * Gives the status of completion of the task. - * @return status of completino of the task. + * @return status of completion of the task. */ public boolean isDone() { From f7fad9fe78ec19f4c1c86d6ddfaf1d0d89bbec59 Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Mon, 2 Mar 2020 23:38:21 +0800 Subject: [PATCH 28/29] Fix bugs --- src/main/java/DeadlineCommand.java | 2 +- src/main/java/DoneCommand.java | 3 +-- src/main/java/EventCommand.java | 2 +- src/main/java/TextUi.java | 6 +++--- src/main/java/TodoCommand.java | 3 ++- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/DeadlineCommand.java b/src/main/java/DeadlineCommand.java index 863b7370ce..af8a65b681 100644 --- a/src/main/java/DeadlineCommand.java +++ b/src/main/java/DeadlineCommand.java @@ -18,7 +18,7 @@ public class DeadlineCommand extends Command { public DeadlineCommand(String command) throws IndexOutOfBoundsException { super(command); deadline = new Deadline(command.substring(9)); - textUi.printDeadlineMessage(deadline); Duke.tasks.add(deadline); + textUi.printDeadlineMessage(deadline); } } diff --git a/src/main/java/DoneCommand.java b/src/main/java/DoneCommand.java index ad7b8d013c..ec166a6fe2 100644 --- a/src/main/java/DoneCommand.java +++ b/src/main/java/DoneCommand.java @@ -10,7 +10,6 @@ public class DoneCommand extends Command { */ public DoneCommand(String command) { super(command); - Duke.tasks.get(Integer.parseInt(Character.toString( - command.charAt(command.length() - 1))) - 1).setDone(); + Duke.tasks.get(Integer.parseInt(command.substring(5)) - 1).setDone(); } } diff --git a/src/main/java/EventCommand.java b/src/main/java/EventCommand.java index 1925f3b9e9..d76ba9c3a2 100644 --- a/src/main/java/EventCommand.java +++ b/src/main/java/EventCommand.java @@ -18,7 +18,7 @@ public class EventCommand extends Command { public EventCommand(String command) throws IndexOutOfBoundsException { super(command); event = new Event(command.substring(6)); - textUi.printEventMessage(event); Duke.tasks.add(event); + textUi.printEventMessage(event); } } diff --git a/src/main/java/TextUi.java b/src/main/java/TextUi.java index 3f19d6effd..bef962c02d 100644 --- a/src/main/java/TextUi.java +++ b/src/main/java/TextUi.java @@ -32,17 +32,17 @@ public void printIllegalArgumentExceptionMessage(Exception exception) { public void printTodoMessage(Task task) { System.out.println("Got it. I've added this task:\n " + task.toString() - + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); + + String.format("\nNow you have %d tasks in the list.", Duke.tasks.size())); } public void printDeadlineMessage(Task task) { System.out.println("Got it. I've added this task:\n " + task.toString() - + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); + + String.format("\nNow you have %d tasks in the list.", Duke.tasks.size())); } public void printEventMessage(Task task) { System.out.println("Got it. I've added this task:\n " + task.toString() - + String.format("\nNow you have %d tasks in the list.", Task.getTotalNumOfTasks())); + + String.format("\nNow you have %d tasks in the list.", Duke.tasks.size())); } public void printDeleteMessage(Task task, int numOfTasksLeft) { diff --git a/src/main/java/TodoCommand.java b/src/main/java/TodoCommand.java index 1e39bdaca5..18df91bb05 100644 --- a/src/main/java/TodoCommand.java +++ b/src/main/java/TodoCommand.java @@ -19,7 +19,8 @@ public class TodoCommand extends Command { public TodoCommand(String command) throws IndexOutOfBoundsException { super(command); todo = new ToDo(command.substring(5)); - textUi.printTodoMessage(todo); Duke.tasks.add(todo); + textUi.printTodoMessage(todo); + } } From 1da6df9dcdf9d3fabf8d31fe5d58b246fd18c2dc Mon Sep 17 00:00:00 2001 From: chengTzeNing <09nhnccgtzening@gmail.com> Date: Tue, 3 Mar 2020 00:12:35 +0800 Subject: [PATCH 29/29] Add README file for User Guide correctly --- docs/README.md | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/docs/README.md b/docs/README.md index fd44069597..2b441f6fe8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,19 +2,29 @@ ## Features -### Feature 1 -Description of feature. - -## Usage - -### `Keyword` - Describe action - -Describe action and its outcome. - -Example of usage: - -`keyword (optional arguments)` - -Expected outcome: - -`outcome` +### Add tasks to list +#### ToDo +* Add a ToDo to your list of tasks in the following format: "todo {task to be done}" +* Example: "todo read book" +#### Deadline +* Add a task with a deadline to your list of tasks in the following format: "deadline {task to be done} /by {date and/or time}" +* Example: "deadline write essay /by today, 2pm" +#### Event +* Add an event to your list of tasks in the following format: "event {name of event} /at {date and/or time}" +* Example: "event career fair /at 2pm, 14 Feb" + +### Mark a task as completed +* Mark a task as completed in the following format: "done {index number of task in the list}" +* Example: "done 3" + +### See your list of tasks +* See your list of tasks in the following format: "list" +* Example: "list" + +### Find a certain task using keywords +* Find a certain task using keywords in the following format: "find {keywords}" +* Example: "find book" + +### Delete a task from your list +* Delete a certain task from your list in the following format: "delete {index number of the task in the list}" +* Example: "delete 4" \ No newline at end of file