From e8e901973b751cf67fc8b96b5d201aa8b49095c0 Mon Sep 17 00:00:00 2001 From: cczhouqi <> Date: Fri, 21 Jan 2022 11:30:23 +0800 Subject: [PATCH 01/20] Implemented Level-0 --- 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 5d313334c..f5889b812 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,15 @@ public class Duke { public static void main(String[] args) { + String boundary = "____________________________________________________________\n"; String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + System.out.println(boundary+ logo); + System.out.println("Hello! I'm Duke"); + System.out.println("What can I do for you?"); + + System.out.print(boundary + "Bye. Hope to see you again soon!\n" + boundary); } } From bd9a4462a00cfc2c95dc7f14211586f814fee5f1 Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Thu, 27 Jan 2022 00:01:23 +0800 Subject: [PATCH 02/20] Week 3 tasks done (Level-1,2,3; A-CodingStandard) --- src/main/java/Duke.java | 37 ++++++++++++++++++++++++++++++++++--- src/main/java/Task.java | 25 +++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index f5889b812..fbfc89cb0 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,6 +1,8 @@ +import java.util.Scanner; + public class Duke { public static void main(String[] args) { - String boundary = "____________________________________________________________\n"; + String boundary = "____________________________________________________________" + System.lineSeparator(); String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" @@ -8,8 +10,37 @@ public static void main(String[] args) { + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println(boundary+ logo); System.out.println("Hello! I'm Duke"); - System.out.println("What can I do for you?"); + System.out.println("What can I do for you?" + System.lineSeparator() + boundary); + Scanner in = new Scanner(System.in); + String line = in.nextLine(); + Task[] taskList = new Task[100]; + int countTask = 0; - System.out.print(boundary + "Bye. Hope to see you again soon!\n" + boundary); + while (!line.equalsIgnoreCase("bye")) { + if (line.equalsIgnoreCase("list")) { + System.out.print(boundary); + for (int i = 0; i < countTask; i ++) { + System.out.println((i + 1) + ". [" + taskList[i].getStatusIcon() + "] " + taskList[i].description); + } + System.out.print(boundary); + } else if (line.toLowerCase().startsWith("mark")) { + int toMark = Integer.parseInt(line.substring(5)) - 1; + taskList[toMark].markDone(); + System.out.println(boundary + "Nice! I've marked this task as done:"); + System.out.println("[" + taskList[toMark].getStatusIcon() + "] " + taskList[toMark].description + System.lineSeparator() + boundary); + } else if (line.toLowerCase().startsWith("unmark")) { + int toMark = Integer.parseInt(line.substring(7)) - 1; + taskList[toMark].markNotDone(); + System.out.println(boundary + "OK, I've marked this task as not done yet:"); + System.out.println("[" + taskList[toMark].getStatusIcon() + "] " + taskList[toMark].description + System.lineSeparator() + boundary); + } else { + taskList[countTask] = new Task(line); + countTask ++; + System.out.println(boundary + "added: " + line + System.lineSeparator() + boundary); + } + in = new Scanner(System.in); + line = in.nextLine(); + } + System.out.print(boundary + "Bye. Hope to see you again soon!" + System.lineSeparator() + boundary); } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..c6659085a --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,25 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public void setTask(String description) { + this.description = description; + } + + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + public void markDone() { + this.isDone = true; + } + + public void markNotDone() { + this.isDone = false; + } +} From 4005ee9852ccbb4469b80b4ef6d76f0b22ef6786 Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Wed, 2 Feb 2022 22:45:40 +0800 Subject: [PATCH 03/20] Week 4 tasks done --- src/main/java/Deadline.java | 14 +++++++ src/main/java/Duke.java | 73 +++++++++++++++++++++++++++---------- src/main/java/Event.java | 14 +++++++ src/main/java/Task.java | 5 +++ src/main/java/Todo.java | 11 ++++++ 5 files changed, 97 insertions(+), 20 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/Todo.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..2de70b754 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,14 @@ +public class Deadline extends Task { + + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + @Override + public String toString() { + return "[D]" + super.toString() + " (by: " + by + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index fbfc89cb0..f980e2812 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,8 +1,54 @@ import java.util.Scanner; public class Duke { + public static String boundary = "____________________________________________________________" + System.lineSeparator(); + public static Task[] taskList = new Task[100]; + public static int countTask = 0; + + public static void printList() { + System.out.println(boundary + "Here are the tasks in your list:"); + for (int i = 0; i < countTask; i ++) { + System.out.println((i + 1) + ". " + taskList[i]); + } + System.out.print("Now you have " + countTask + " tasks in the list."+ System.lineSeparator() + boundary); + } + + public static void markTask(int toMark) { + taskList[toMark].markDone(); + System.out.println(boundary + "Nice! I've marked this task as done:" + System.lineSeparator() + taskList[toMark]); + System.out.print(boundary); + } + + public static void unmarkTask(int toUnmark) { + taskList[toUnmark].markNotDone(); + System.out.println(boundary + "OK, I've marked this task as not done yet:" + System.lineSeparator() + taskList[toUnmark]); + System.out.print(boundary); + } + + public static void addTask(String request) { + if (request.toLowerCase().startsWith("deadline")) { + int byPosition = request.indexOf("/"); + taskList[countTask] = new Deadline(request.substring(9, byPosition - 1), request.substring(byPosition + 4)); + } else if (request.toLowerCase().startsWith("event")) { + int atPosition = request.indexOf("/"); + taskList[countTask] = new Event(request.substring(6, atPosition - 1), request.substring(atPosition + 4)); + } else if (request.toLowerCase().startsWith("todo")) { + taskList[countTask] = new Todo(request.substring(5)); + } else { + taskList[countTask] = new Task(request); + } + + countTask ++; + + System.out.println(boundary + "Got it. I've added this task: " + System.lineSeparator() + taskList[countTask - 1]); + System.out.print("Now you have " + countTask + " tasks in the list."+ System.lineSeparator() + boundary); + } + + public static void sayGoodbye() { + System.out.print(boundary + "Bye. Hope to see you again soon!" + System.lineSeparator() + boundary); + } + public static void main(String[] args) { - String boundary = "____________________________________________________________" + System.lineSeparator(); String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" @@ -13,34 +59,21 @@ public static void main(String[] args) { System.out.println("What can I do for you?" + System.lineSeparator() + boundary); Scanner in = new Scanner(System.in); String line = in.nextLine(); - Task[] taskList = new Task[100]; - int countTask = 0; + while (!line.equalsIgnoreCase("bye")) { if (line.equalsIgnoreCase("list")) { - System.out.print(boundary); - for (int i = 0; i < countTask; i ++) { - System.out.println((i + 1) + ". [" + taskList[i].getStatusIcon() + "] " + taskList[i].description); - } - System.out.print(boundary); + printList(); } else if (line.toLowerCase().startsWith("mark")) { - int toMark = Integer.parseInt(line.substring(5)) - 1; - taskList[toMark].markDone(); - System.out.println(boundary + "Nice! I've marked this task as done:"); - System.out.println("[" + taskList[toMark].getStatusIcon() + "] " + taskList[toMark].description + System.lineSeparator() + boundary); + markTask(Integer.parseInt(line.substring(5)) - 1); } else if (line.toLowerCase().startsWith("unmark")) { - int toMark = Integer.parseInt(line.substring(7)) - 1; - taskList[toMark].markNotDone(); - System.out.println(boundary + "OK, I've marked this task as not done yet:"); - System.out.println("[" + taskList[toMark].getStatusIcon() + "] " + taskList[toMark].description + System.lineSeparator() + boundary); + unmarkTask(Integer.parseInt(line.substring(7)) - 1); } else { - taskList[countTask] = new Task(line); - countTask ++; - System.out.println(boundary + "added: " + line + System.lineSeparator() + boundary); + addTask(line); } in = new Scanner(System.in); line = in.nextLine(); } - System.out.print(boundary + "Bye. Hope to see you again soon!" + System.lineSeparator() + boundary); + sayGoodbye(); } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..32ecd4b67 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,14 @@ +public class Event extends Task { + + protected String at; + + public Event (String description, String at) { + super(description); + this.at = at; + } + + @Override + public String toString() { + return "[E]" + super.toString() + " (at: " + at + ")"; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index c6659085a..e8682adf3 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -22,4 +22,9 @@ public void markDone() { public void markNotDone() { this.isDone = false; } + + @Override + public String toString() { + return ("[" + getStatusIcon() + "] " + description); + } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..931cfd4f9 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,11 @@ +public class Todo extends Task { + + public Todo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} From 7bf526541a0a78dce5e0634bf0da54d2c03e8225 Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Wed, 9 Feb 2022 22:59:42 +0800 Subject: [PATCH 04/20] Level-5 implemented --- src/main/java/Deadline.java | 1 - src/main/java/DeadlineFormatException.java | 2 + src/main/java/Duke.java | 65 +++++++++++++++++----- src/main/java/Event.java | 1 - src/main/java/EventFormatException.java | 2 + src/main/java/GeneralException.java | 2 + src/main/java/TaskEmptyException.java | 2 + src/main/java/Todo.java | 1 - 8 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 src/main/java/DeadlineFormatException.java create mode 100644 src/main/java/EventFormatException.java create mode 100644 src/main/java/GeneralException.java create mode 100644 src/main/java/TaskEmptyException.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 2de70b754..95928fb5f 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,5 +1,4 @@ public class Deadline extends Task { - protected String by; public Deadline(String description, String by) { diff --git a/src/main/java/DeadlineFormatException.java b/src/main/java/DeadlineFormatException.java new file mode 100644 index 000000000..80de65e11 --- /dev/null +++ b/src/main/java/DeadlineFormatException.java @@ -0,0 +1,2 @@ +public class DeadlineFormatException extends Exception { +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index f980e2812..3778478d8 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -7,7 +7,7 @@ public class Duke { public static void printList() { System.out.println(boundary + "Here are the tasks in your list:"); - for (int i = 0; i < countTask; i ++) { + for (int i = 0; i < countTask; i++) { System.out.println((i + 1) + ". " + taskList[i]); } System.out.print("Now you have " + countTask + " tasks in the list."+ System.lineSeparator() + boundary); @@ -25,42 +25,79 @@ public static void unmarkTask(int toUnmark) { System.out.print(boundary); } - public static void addTask(String request) { + public static void checkDescription(String request) throws TaskEmptyException { + if (request.toLowerCase().endsWith("deadline") || + request.toLowerCase().endsWith("event") || + request.toLowerCase().endsWith("todo")) { + throw new TaskEmptyException(); + } + } + + public static void addTask(String request) throws GeneralException, + TaskEmptyException, DeadlineFormatException, EventFormatException { + checkDescription(request); if (request.toLowerCase().startsWith("deadline")) { + if ((!request.contains("/by"))) { + throw new DeadlineFormatException(); + } int byPosition = request.indexOf("/"); taskList[countTask] = new Deadline(request.substring(9, byPosition - 1), request.substring(byPosition + 4)); } else if (request.toLowerCase().startsWith("event")) { + if (!request.contains("/at")) { + throw new EventFormatException(); + } int atPosition = request.indexOf("/"); taskList[countTask] = new Event(request.substring(6, atPosition - 1), request.substring(atPosition + 4)); } else if (request.toLowerCase().startsWith("todo")) { taskList[countTask] = new Todo(request.substring(5)); } else { - taskList[countTask] = new Task(request); + throw new GeneralException(); } - countTask ++; + countTask++; System.out.println(boundary + "Got it. I've added this task: " + System.lineSeparator() + taskList[countTask - 1]); System.out.print("Now you have " + countTask + " tasks in the list."+ System.lineSeparator() + boundary); } - public static void sayGoodbye() { - System.out.print(boundary + "Bye. Hope to see you again soon!" + System.lineSeparator() + boundary); + public static void tryAddTask(String request) { + try { + addTask(request.trim()); + } catch (GeneralException e) { + System.out.print(boundary + "Hmm...I'm sorry but I cannot understand this..." + + System.lineSeparator() + boundary); + } catch (TaskEmptyException e) { + System.out.print(boundary + "Hmm...hi dear, remember to put in your task description~" + + System.lineSeparator() + boundary); + } catch (DeadlineFormatException e) { + System.out.print(boundary + "Hmm...hi dear, when do u want to finish this by?" + + System.lineSeparator() + boundary); + } catch (EventFormatException e) { + System.out.print(boundary + "Hmm...hi dear, when is this event happening?" + + System.lineSeparator() + boundary); + } } - public static void main(String[] args) { + public static void sayHello() { String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println(boundary+ logo); + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + System.out.println(boundary + logo); System.out.println("Hello! I'm Duke"); System.out.println("What can I do for you?" + System.lineSeparator() + boundary); + } + + public static void sayGoodbye() { + System.out.print(boundary + "Bye. Hope to see you again soon!" + System.lineSeparator() + boundary); + } + + public static void main(String[] args) { + sayHello(); Scanner in = new Scanner(System.in); String line = in.nextLine(); - while (!line.equalsIgnoreCase("bye")) { if (line.equalsIgnoreCase("list")) { printList(); @@ -69,7 +106,7 @@ public static void main(String[] args) { } else if (line.toLowerCase().startsWith("unmark")) { unmarkTask(Integer.parseInt(line.substring(7)) - 1); } else { - addTask(line); + tryAddTask(line); } in = new Scanner(System.in); line = in.nextLine(); diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 32ecd4b67..def313786 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,5 +1,4 @@ public class Event extends Task { - protected String at; public Event (String description, String at) { diff --git a/src/main/java/EventFormatException.java b/src/main/java/EventFormatException.java new file mode 100644 index 000000000..79e302788 --- /dev/null +++ b/src/main/java/EventFormatException.java @@ -0,0 +1,2 @@ +public class EventFormatException extends Exception { +} diff --git a/src/main/java/GeneralException.java b/src/main/java/GeneralException.java new file mode 100644 index 000000000..5baca365b --- /dev/null +++ b/src/main/java/GeneralException.java @@ -0,0 +1,2 @@ +public class GeneralException extends Exception { +} diff --git a/src/main/java/TaskEmptyException.java b/src/main/java/TaskEmptyException.java new file mode 100644 index 000000000..b09239ac2 --- /dev/null +++ b/src/main/java/TaskEmptyException.java @@ -0,0 +1,2 @@ +public class TaskEmptyException extends Exception { +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 931cfd4f9..eabef3ab8 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -1,5 +1,4 @@ public class Todo extends Task { - public Todo(String description) { super(description); } From 79a0e83f63026e2a6510b14eb98adeba03401a8f Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Wed, 9 Feb 2022 23:31:48 +0800 Subject: [PATCH 05/20] A-Packages implemented --- src/main/java/{ => duke}/Duke.java | 14 ++++++++++++++ .../exceptions}/DeadlineFormatException.java | 2 ++ .../exceptions}/EventFormatException.java | 2 ++ .../{ => duke/exceptions}/GeneralException.java | 2 ++ .../{ => duke/exceptions}/TaskEmptyException.java | 2 ++ src/main/java/{ => duke/task}/Deadline.java | 2 ++ src/main/java/{ => duke/task}/Event.java | 2 ++ src/main/java/{ => duke/task}/Task.java | 2 ++ src/main/java/{ => duke/task}/Todo.java | 2 ++ 9 files changed, 30 insertions(+) rename src/main/java/{ => duke}/Duke.java (90%) rename src/main/java/{ => duke/exceptions}/DeadlineFormatException.java (69%) rename src/main/java/{ => duke/exceptions}/EventFormatException.java (68%) rename src/main/java/{ => duke/exceptions}/GeneralException.java (66%) rename src/main/java/{ => duke/exceptions}/TaskEmptyException.java (67%) rename src/main/java/{ => duke/task}/Deadline.java (93%) rename src/main/java/{ => duke/task}/Event.java (93%) rename src/main/java/{ => duke/task}/Task.java (96%) rename src/main/java/{ => duke/task}/Todo.java (90%) diff --git a/src/main/java/Duke.java b/src/main/java/duke/Duke.java similarity index 90% rename from src/main/java/Duke.java rename to src/main/java/duke/Duke.java index 3778478d8..b6215474d 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,4 +1,14 @@ +package duke; + import java.util.Scanner; +import duke.task.Task; +import duke.task.Deadline; +import duke.task.Event; +import duke.task.Todo; +import duke.exceptions.GeneralException; +import duke.exceptions.TaskEmptyException; +import duke.exceptions.EventFormatException; +import duke.exceptions.DeadlineFormatException; public class Duke { public static String boundary = "____________________________________________________________" + System.lineSeparator(); @@ -39,12 +49,16 @@ public static void addTask(String request) throws GeneralException, if (request.toLowerCase().startsWith("deadline")) { if ((!request.contains("/by"))) { throw new DeadlineFormatException(); + } else if (request.substring(9, (request.indexOf("/by"))).trim().equals("")) { + throw new TaskEmptyException(); } int byPosition = request.indexOf("/"); taskList[countTask] = new Deadline(request.substring(9, byPosition - 1), request.substring(byPosition + 4)); } else if (request.toLowerCase().startsWith("event")) { if (!request.contains("/at")) { throw new EventFormatException(); + } else if (request.substring(6, (request.indexOf("/at"))).trim().equals("")) { + throw new TaskEmptyException(); } int atPosition = request.indexOf("/"); taskList[countTask] = new Event(request.substring(6, atPosition - 1), request.substring(atPosition + 4)); diff --git a/src/main/java/DeadlineFormatException.java b/src/main/java/duke/exceptions/DeadlineFormatException.java similarity index 69% rename from src/main/java/DeadlineFormatException.java rename to src/main/java/duke/exceptions/DeadlineFormatException.java index 80de65e11..a849b00bd 100644 --- a/src/main/java/DeadlineFormatException.java +++ b/src/main/java/duke/exceptions/DeadlineFormatException.java @@ -1,2 +1,4 @@ +package duke.exceptions; + public class DeadlineFormatException extends Exception { } diff --git a/src/main/java/EventFormatException.java b/src/main/java/duke/exceptions/EventFormatException.java similarity index 68% rename from src/main/java/EventFormatException.java rename to src/main/java/duke/exceptions/EventFormatException.java index 79e302788..23c287076 100644 --- a/src/main/java/EventFormatException.java +++ b/src/main/java/duke/exceptions/EventFormatException.java @@ -1,2 +1,4 @@ +package duke.exceptions; + public class EventFormatException extends Exception { } diff --git a/src/main/java/GeneralException.java b/src/main/java/duke/exceptions/GeneralException.java similarity index 66% rename from src/main/java/GeneralException.java rename to src/main/java/duke/exceptions/GeneralException.java index 5baca365b..a34a72b98 100644 --- a/src/main/java/GeneralException.java +++ b/src/main/java/duke/exceptions/GeneralException.java @@ -1,2 +1,4 @@ +package duke.exceptions; + public class GeneralException extends Exception { } diff --git a/src/main/java/TaskEmptyException.java b/src/main/java/duke/exceptions/TaskEmptyException.java similarity index 67% rename from src/main/java/TaskEmptyException.java rename to src/main/java/duke/exceptions/TaskEmptyException.java index b09239ac2..2f9aae9c2 100644 --- a/src/main/java/TaskEmptyException.java +++ b/src/main/java/duke/exceptions/TaskEmptyException.java @@ -1,2 +1,4 @@ +package duke.exceptions; + public class TaskEmptyException extends Exception { } diff --git a/src/main/java/Deadline.java b/src/main/java/duke/task/Deadline.java similarity index 93% rename from src/main/java/Deadline.java rename to src/main/java/duke/task/Deadline.java index 95928fb5f..2b0a9ca11 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,3 +1,5 @@ +package duke.task; + public class Deadline extends Task { protected String by; diff --git a/src/main/java/Event.java b/src/main/java/duke/task/Event.java similarity index 93% rename from src/main/java/Event.java rename to src/main/java/duke/task/Event.java index def313786..dee1ff84b 100644 --- a/src/main/java/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,3 +1,5 @@ +package duke.task; + public class Event extends Task { protected String at; diff --git a/src/main/java/Task.java b/src/main/java/duke/task/Task.java similarity index 96% rename from src/main/java/Task.java rename to src/main/java/duke/task/Task.java index e8682adf3..864fe6e29 100644 --- a/src/main/java/Task.java +++ b/src/main/java/duke/task/Task.java @@ -1,3 +1,5 @@ +package duke.task; + public class Task { protected String description; protected boolean isDone; diff --git a/src/main/java/Todo.java b/src/main/java/duke/task/Todo.java similarity index 90% rename from src/main/java/Todo.java rename to src/main/java/duke/task/Todo.java index eabef3ab8..1dc39b7f6 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/duke/task/Todo.java @@ -1,3 +1,5 @@ +package duke.task; + public class Todo extends Task { public Todo(String description) { super(description); From 8c52f17d477013133d298dd7ef3b9b225da99361 Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Wed, 9 Feb 2022 23:46:15 +0800 Subject: [PATCH 06/20] Duke's words edited --- src/main/java/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index b6215474d..f79cf8b7f 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -78,7 +78,7 @@ public static void tryAddTask(String request) { try { addTask(request.trim()); } catch (GeneralException e) { - System.out.print(boundary + "Hmm...I'm sorry but I cannot understand this..." + System.out.print(boundary + "Hmm...I'm sorry but I cannot understand this :(" + System.lineSeparator() + boundary); } catch (TaskEmptyException e) { System.out.print(boundary + "Hmm...hi dear, remember to put in your task description~" From b98b2986cba1ff5e90941f0aad559097b7096525 Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Wed, 16 Feb 2022 21:18:42 +0800 Subject: [PATCH 07/20] Level-6 implemented --- src/main/java/duke/Duke.java | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index f79cf8b7f..154312b37 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,6 +1,7 @@ package duke; import java.util.Scanner; +import java.util.ArrayList; import duke.task.Task; import duke.task.Deadline; import duke.task.Event; @@ -12,26 +13,26 @@ public class Duke { public static String boundary = "____________________________________________________________" + System.lineSeparator(); - public static Task[] taskList = new Task[100]; + public static ArrayList taskList = new ArrayList<>(); public static int countTask = 0; public static void printList() { System.out.println(boundary + "Here are the tasks in your list:"); for (int i = 0; i < countTask; i++) { - System.out.println((i + 1) + ". " + taskList[i]); + System.out.println((i + 1) + ". " + taskList.get(i)); } System.out.print("Now you have " + countTask + " tasks in the list."+ System.lineSeparator() + boundary); } public static void markTask(int toMark) { - taskList[toMark].markDone(); - System.out.println(boundary + "Nice! I've marked this task as done:" + System.lineSeparator() + taskList[toMark]); + taskList.get(toMark).markDone(); + System.out.println(boundary + "Nice! I've marked this task as done:" + System.lineSeparator() + taskList.get(toMark)); System.out.print(boundary); } public static void unmarkTask(int toUnmark) { - taskList[toUnmark].markNotDone(); - System.out.println(boundary + "OK, I've marked this task as not done yet:" + System.lineSeparator() + taskList[toUnmark]); + taskList.get(toUnmark).markNotDone(); + System.out.println(boundary + "OK, I've marked this task as not done yet:" + System.lineSeparator() + taskList.get(toUnmark)); System.out.print(boundary); } @@ -53,7 +54,7 @@ public static void addTask(String request) throws GeneralException, throw new TaskEmptyException(); } int byPosition = request.indexOf("/"); - taskList[countTask] = new Deadline(request.substring(9, byPosition - 1), request.substring(byPosition + 4)); + taskList.add(new Deadline(request.substring(9, byPosition - 1), request.substring(byPosition + 4))); } else if (request.toLowerCase().startsWith("event")) { if (!request.contains("/at")) { throw new EventFormatException(); @@ -61,16 +62,16 @@ public static void addTask(String request) throws GeneralException, throw new TaskEmptyException(); } int atPosition = request.indexOf("/"); - taskList[countTask] = new Event(request.substring(6, atPosition - 1), request.substring(atPosition + 4)); + taskList.add(new Event(request.substring(6, atPosition - 1), request.substring(atPosition + 4))); } else if (request.toLowerCase().startsWith("todo")) { - taskList[countTask] = new Todo(request.substring(5)); + taskList.add(new Todo(request.substring(5))); } else { throw new GeneralException(); } countTask++; - System.out.println(boundary + "Got it. I've added this task: " + System.lineSeparator() + taskList[countTask - 1]); + System.out.println(boundary + "Got it. I've added this task: " + System.lineSeparator() + taskList.get(countTask - 1)); System.out.print("Now you have " + countTask + " tasks in the list."+ System.lineSeparator() + boundary); } @@ -92,6 +93,14 @@ public static void tryAddTask(String request) { } } + public static void deleteTask(int index) { + System.out.println(boundary + "Noted. I've removed this task:"); + System.out.println(taskList.get(index)); + System.out.print("Now you have " + (countTask - 1) + " tasks in the list." + System.lineSeparator() + boundary); + taskList.remove(index); + countTask -= 1; + } + public static void sayHello() { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -119,6 +128,8 @@ public static void main(String[] args) { markTask(Integer.parseInt(line.substring(5)) - 1); } else if (line.toLowerCase().startsWith("unmark")) { unmarkTask(Integer.parseInt(line.substring(7)) - 1); + } else if (line.toLowerCase().startsWith("delete")) { + deleteTask(Integer.parseInt(line.substring(7)) - 1); } else { tryAddTask(line); } From f589ba22467f53f60359851e58773ebded2b5d56 Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Thu, 17 Feb 2022 10:39:32 +0800 Subject: [PATCH 08/20] Level-7 (to be completed) --- src/main/java/duke/Duke.java | 16 ++++++++++++++++ src/main/java/duke/data/duke.txt | 0 2 files changed, 16 insertions(+) create mode 100644 src/main/java/duke/data/duke.txt diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index f79cf8b7f..8278d5947 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,6 +1,9 @@ package duke; import java.util.Scanner; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import duke.task.Task; import duke.task.Deadline; import duke.task.Event; @@ -77,6 +80,8 @@ public static void addTask(String request) throws GeneralException, public static void tryAddTask(String request) { try { addTask(request.trim()); + System.out.println(boundary + "I'm adding the task into duke.txt..."); + appendToFile("./data/duke.txt", taskList[countTask - 1].toString()); } catch (GeneralException e) { System.out.print(boundary + "Hmm...I'm sorry but I cannot understand this :(" + System.lineSeparator() + boundary); @@ -89,6 +94,9 @@ public static void tryAddTask(String request) { } catch (EventFormatException e) { System.out.print(boundary + "Hmm...hi dear, when is this event happening?" + System.lineSeparator() + boundary); + } catch (IOException e) { + System.out.print("Hmm...I cannot write to duke.txt :(" + + System.lineSeparator() + boundary); } } @@ -107,11 +115,19 @@ public static void sayGoodbye() { System.out.print(boundary + "Bye. Hope to see you again soon!" + System.lineSeparator() + boundary); } + public static void appendToFile(String filePath, String textToAppend) throws IOException { + FileWriter fw = new FileWriter(filePath, true); // create a FileWriter in append mode + fw.write(textToAppend); + fw.close(); + } + public static void main(String[] args) { sayHello(); Scanner in = new Scanner(System.in); String line = in.nextLine(); + // File f = new File("data/fruits.txt"); + while (!line.equalsIgnoreCase("bye")) { if (line.equalsIgnoreCase("list")) { printList(); diff --git a/src/main/java/duke/data/duke.txt b/src/main/java/duke/data/duke.txt new file mode 100644 index 000000000..e69de29bb From 8704bea8a005e7d43c56dee50a8973c901550785 Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Sun, 20 Feb 2022 21:55:08 +0800 Subject: [PATCH 09/20] Level-7 implemented --- src/main/java/duke/Duke.java | 70 ++++++++++++++++++++++++------- src/main/java/duke/FileSaver.java | 37 ++++++++++++++++ src/main/java/duke/data/duke.txt | 0 3 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 src/main/java/duke/FileSaver.java delete mode 100644 src/main/java/duke/data/duke.txt diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 8278d5947..75d130953 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,9 +1,11 @@ package duke; +import java.io.FileNotFoundException; import java.util.Scanner; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import duke.FileSaver; import duke.task.Task; import duke.task.Deadline; import duke.task.Event; @@ -14,9 +16,9 @@ import duke.exceptions.DeadlineFormatException; public class Duke { - public static String boundary = "____________________________________________________________" + System.lineSeparator(); - public static Task[] taskList = new Task[100]; - public static int countTask = 0; + private static final String boundary = "____________________________________________________________" + System.lineSeparator(); + private static Task[] taskList = new Task[100]; + private static int countTask = 0; public static void printList() { System.out.println(boundary + "Here are the tasks in your list:"); @@ -80,8 +82,6 @@ public static void addTask(String request) throws GeneralException, public static void tryAddTask(String request) { try { addTask(request.trim()); - System.out.println(boundary + "I'm adding the task into duke.txt..."); - appendToFile("./data/duke.txt", taskList[countTask - 1].toString()); } catch (GeneralException e) { System.out.print(boundary + "Hmm...I'm sorry but I cannot understand this :(" + System.lineSeparator() + boundary); @@ -94,12 +94,51 @@ public static void tryAddTask(String request) { } catch (EventFormatException e) { System.out.print(boundary + "Hmm...hi dear, when is this event happening?" + System.lineSeparator() + boundary); + } + } + + public static void writeData(FileSaver dataFile) { + StringBuilder toWrite = new StringBuilder(); + for (int i = 0; i < countTask; i++) { + toWrite.append(taskList[i]).append(System.lineSeparator()); + } + + try { + dataFile.writeToFile(toWrite.toString()); } catch (IOException e) { - System.out.print("Hmm...I cannot write to duke.txt :(" + System.out.print(boundary + "Hmm...I cannot write to the data file." + System.lineSeparator() + boundary); } } + public static void readToList() throws FileNotFoundException { + File f = new File("./data/dukeData.txt"); + Scanner s = new Scanner(f); + while (s.hasNext()) { + String currentLine = s.nextLine(); + switch (currentLine.charAt(1)) { + case 'T': + taskList[countTask] = new Todo(currentLine.substring(7)); + break; + case 'D': + int byIndex = currentLine.indexOf("("); + String by = currentLine.substring(byIndex + 5, currentLine.length() - 1); + taskList[countTask] = new Deadline(currentLine.substring(7, byIndex - 1), by); + break; + case 'E': + int atIndex = currentLine.indexOf("("); + String at = currentLine.substring(atIndex + 5, currentLine.length() - 1); + taskList[countTask] = new Event(currentLine.substring(7, atIndex - 1), at); + break; + default: + } + if (currentLine.charAt(4) == 'X') { + taskList[countTask].markDone(); + } + countTask += 1; + } + } + public static void sayHello() { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -115,19 +154,21 @@ public static void sayGoodbye() { System.out.print(boundary + "Bye. Hope to see you again soon!" + System.lineSeparator() + boundary); } - public static void appendToFile(String filePath, String textToAppend) throws IOException { - FileWriter fw = new FileWriter(filePath, true); // create a FileWriter in append mode - fw.write(textToAppend); - fw.close(); - } - public static void main(String[] args) { sayHello(); + FileSaver dataFile = new FileSaver(); + + try { + System.out.println("Adding existing tasks (if any)..."); + readToList(); + System.out.print(boundary); + } catch (FileNotFoundException e) { + System.out.println("Hmm...File creation failed, I cannot write to the data file."); + } + Scanner in = new Scanner(System.in); String line = in.nextLine(); - // File f = new File("data/fruits.txt"); - while (!line.equalsIgnoreCase("bye")) { if (line.equalsIgnoreCase("list")) { printList(); @@ -141,6 +182,7 @@ public static void main(String[] args) { in = new Scanner(System.in); line = in.nextLine(); } + writeData(dataFile); sayGoodbye(); } } diff --git a/src/main/java/duke/FileSaver.java b/src/main/java/duke/FileSaver.java new file mode 100644 index 000000000..a80af0ec8 --- /dev/null +++ b/src/main/java/duke/FileSaver.java @@ -0,0 +1,37 @@ +package duke; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Scanner; + +public class FileSaver { + public FileSaver() { + File dataDirectory = new File("./data"); + if (!dataDirectory.exists()) { + try { + Files.createDirectory(Paths.get("./data")); + } catch (IOException e) { + System.out.println("Hmm...I cannot create the data directory."); + } + } + + File dukeData = new File("./data/dukeData.txt"); + try { + if (dukeData.createNewFile()) { + System.out.println("Creating a new data file..."); + } + } catch (IOException e) { + System.out.println("Hmm... I cannot create the data file."); + } + } + + public void writeToFile(String textToWrite) throws IOException { + FileWriter fw = new FileWriter("./data/dukeData.txt"); // create a FileWriter in append mode + fw.write(textToWrite); + fw.close(); + } +} diff --git a/src/main/java/duke/data/duke.txt b/src/main/java/duke/data/duke.txt deleted file mode 100644 index e69de29bb..000000000 From ea1fc60986378435d41a7b5311ee065492263a8a Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Mon, 21 Feb 2022 16:54:48 +0800 Subject: [PATCH 10/20] A-MoreOOP implemented --- src/main/java/duke/Duke.java | 195 ++---------------- src/main/java/duke/FileSaver.java | 37 ---- src/main/java/duke/Parser.java | 54 +++++ src/main/java/duke/Storage.java | 84 ++++++++ src/main/java/duke/TaskList.java | 103 +++++++++ src/main/java/duke/Ui.java | 47 +++++ .../duke/exceptions/DeleteIndexException.java | 4 + 7 files changed, 308 insertions(+), 216 deletions(-) delete mode 100644 src/main/java/duke/FileSaver.java create mode 100644 src/main/java/duke/Parser.java create mode 100644 src/main/java/duke/Storage.java create mode 100644 src/main/java/duke/TaskList.java create mode 100644 src/main/java/duke/Ui.java create mode 100644 src/main/java/duke/exceptions/DeleteIndexException.java diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 9b1939f56..a7b07862b 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,197 +1,34 @@ package duke; import java.io.FileNotFoundException; -import java.util.Scanner; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import duke.task.Task; -import duke.task.Deadline; -import duke.task.Event; -import duke.task.Todo; -import duke.exceptions.GeneralException; -import duke.exceptions.TaskEmptyException; -import duke.exceptions.EventFormatException; -import duke.exceptions.DeadlineFormatException; public class Duke { - public static String boundary = "____________________________________________________________" + System.lineSeparator(); - public static ArrayList taskList = new ArrayList<>(); - public static int countTask = 0; + private final TaskList tasks; + private final Ui ui; - public static void printList() { - System.out.println(boundary + "Here are the tasks in your list:"); - for (int i = 0; i < countTask; i++) { - System.out.println((i + 1) + ". " + taskList.get(i)); - } - System.out.print("Now you have " + countTask + " tasks in the list."+ System.lineSeparator() + boundary); - } - - public static void markTask(int toMark) { - taskList.get(toMark).markDone(); - System.out.println(boundary + "Nice! I've marked this task as done:" + System.lineSeparator() + taskList.get(toMark)); - System.out.print(boundary); - } - - public static void unmarkTask(int toUnmark) { - taskList.get(toUnmark).markNotDone(); - System.out.println(boundary + "OK, I've marked this task as not done yet:" + System.lineSeparator() + taskList.get(toUnmark)); - System.out.print(boundary); - } - - public static void checkDescription(String request) throws TaskEmptyException { - if (request.toLowerCase().endsWith("deadline") || - request.toLowerCase().endsWith("event") || - request.toLowerCase().endsWith("todo")) { - throw new TaskEmptyException(); - } - } - - public static void addTask(String request) throws GeneralException, - TaskEmptyException, DeadlineFormatException, EventFormatException { - checkDescription(request); - if (request.toLowerCase().startsWith("deadline")) { - if ((!request.contains("/by"))) { - throw new DeadlineFormatException(); - } else if (request.substring(9, (request.indexOf("/by"))).trim().equals("")) { - throw new TaskEmptyException(); - } - int byPosition = request.indexOf("/"); - taskList.add(new Deadline(request.substring(9, byPosition - 1), request.substring(byPosition + 4))); - } else if (request.toLowerCase().startsWith("event")) { - if (!request.contains("/at")) { - throw new EventFormatException(); - } else if (request.substring(6, (request.indexOf("/at"))).trim().equals("")) { - throw new TaskEmptyException(); - } - int atPosition = request.indexOf("/"); - taskList.add(new Event(request.substring(6, atPosition - 1), request.substring(atPosition + 4))); - } else if (request.toLowerCase().startsWith("todo")) { - taskList.add(new Todo(request.substring(5))); - } else { - throw new GeneralException(); - } - - countTask++; - - System.out.println(boundary + "Got it. I've added this task: " + System.lineSeparator() + taskList.get(countTask - 1)); - System.out.print("Now you have " + countTask + " tasks in the list."+ System.lineSeparator() + boundary); - } - - public static void tryAddTask(String request) { - try { - addTask(request.trim()); - } catch (GeneralException e) { - System.out.print(boundary + "Hmm...I'm sorry but I cannot understand this :(" - + System.lineSeparator() + boundary); - } catch (TaskEmptyException e) { - System.out.print(boundary + "Hmm...hi dear, remember to put in your task description~" - + System.lineSeparator() + boundary); - } catch (DeadlineFormatException e) { - System.out.print(boundary + "Hmm...hi dear, when do u want to finish this by?" - + System.lineSeparator() + boundary); - } catch (EventFormatException e) { - System.out.print(boundary + "Hmm...hi dear, when is this event happening?" - + System.lineSeparator() + boundary); - } - } - - public static void writeData(FileSaver dataFile) { - StringBuilder toWrite = new StringBuilder(); - for (int i = 0; i < countTask; i++) { - toWrite.append(taskList.get(i)).append(System.lineSeparator()); - } + public Duke() { + tasks = new TaskList(); + ui = new Ui(); try { - dataFile.writeToFile(toWrite.toString()); - } catch (IOException e) { - System.out.print(boundary + "Hmm...I cannot write to the data file." - + System.lineSeparator() + boundary); - } - } - - public static void readToList() throws FileNotFoundException { - File f = new File("./data/dukeData.txt"); - Scanner s = new Scanner(f); - while (s.hasNext()) { - String currentLine = s.nextLine(); - switch (currentLine.charAt(1)) { - case 'T': - taskList.add(new Todo(currentLine.substring(7))); - break; - case 'D': - int byIndex = currentLine.indexOf("("); - String by = currentLine.substring(byIndex + 5, currentLine.length() - 1); - taskList.add(new Deadline(currentLine.substring(7, byIndex - 1), by)); - break; - case 'E': - int atIndex = currentLine.indexOf("("); - String at = currentLine.substring(atIndex + 5, currentLine.length() - 1); - taskList.add(new Event(currentLine.substring(7, atIndex - 1), at)); - break; - default: - } - if (currentLine.charAt(4) == 'X') { - taskList.get(countTask).markDone(); - } - countTask += 1; + Storage.readToList(tasks); + } catch (FileNotFoundException e) { + System.out.println("Hmm...File creation failed, I cannot write to the data file."); } } - public static void deleteTask(int index) { - System.out.println(boundary + "Noted. I've removed this task:"); - System.out.println(taskList.get(index)); - System.out.print("Now you have " + (countTask - 1) + " tasks in the list." + System.lineSeparator() + boundary); - taskList.remove(index); - countTask -= 1; - } + public void run() { + Storage dataFile = new Storage(); + ui.sayHello(); - public static void sayHello() { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println(boundary + logo); - System.out.println("Hello! I'm Duke"); - System.out.println("What can I do for you?" + System.lineSeparator() + boundary); - } + ui.interact(tasks); - public static void sayGoodbye() { - System.out.print(boundary + "Bye. Hope to see you again soon!" + System.lineSeparator() + boundary); + Storage.writeData(dataFile, tasks); + ui.sayGoodbye(); } public static void main(String[] args) { - sayHello(); - FileSaver dataFile = new FileSaver(); - - try { - System.out.println("Adding existing tasks (if any)..."); - readToList(); - System.out.print(boundary); - } catch (FileNotFoundException e) { - System.out.println("Hmm...File creation failed, I cannot write to the data file."); - } - - Scanner in = new Scanner(System.in); - String line = in.nextLine(); - - while (!line.equalsIgnoreCase("bye")) { - if (line.equalsIgnoreCase("list")) { - printList(); - } else if (line.toLowerCase().startsWith("mark")) { - markTask(Integer.parseInt(line.substring(5)) - 1); - } else if (line.toLowerCase().startsWith("unmark")) { - unmarkTask(Integer.parseInt(line.substring(7)) - 1); - } else if (line.toLowerCase().startsWith("delete")) { - deleteTask(Integer.parseInt(line.substring(7)) - 1); - } else { - tryAddTask(line); - } - in = new Scanner(System.in); - line = in.nextLine(); - } - writeData(dataFile); - sayGoodbye(); + new Duke().run(); } + } diff --git a/src/main/java/duke/FileSaver.java b/src/main/java/duke/FileSaver.java deleted file mode 100644 index a80af0ec8..000000000 --- a/src/main/java/duke/FileSaver.java +++ /dev/null @@ -1,37 +0,0 @@ -package duke; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Scanner; - -public class FileSaver { - public FileSaver() { - File dataDirectory = new File("./data"); - if (!dataDirectory.exists()) { - try { - Files.createDirectory(Paths.get("./data")); - } catch (IOException e) { - System.out.println("Hmm...I cannot create the data directory."); - } - } - - File dukeData = new File("./data/dukeData.txt"); - try { - if (dukeData.createNewFile()) { - System.out.println("Creating a new data file..."); - } - } catch (IOException e) { - System.out.println("Hmm... I cannot create the data file."); - } - } - - public void writeToFile(String textToWrite) throws IOException { - FileWriter fw = new FileWriter("./data/dukeData.txt"); // create a FileWriter in append mode - fw.write(textToWrite); - fw.close(); - } -} diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java new file mode 100644 index 000000000..f075e41cd --- /dev/null +++ b/src/main/java/duke/Parser.java @@ -0,0 +1,54 @@ +package duke; + +import duke.exceptions.*; + +public class Parser { + public static String boundary = "____________________________________________________________" + System.lineSeparator(); + + // Report error to user if he/she did not put task description + public void checkDescription(String request) throws TaskEmptyException { + if (request.toLowerCase().endsWith("deadline") || + request.toLowerCase().endsWith("event") || + request.toLowerCase().endsWith("todo")) { + throw new TaskEmptyException(); + } + } + + // Report error if the user did not give an index of task to delete + public void checkDeleteIndex(String request) throws DeleteIndexException { + if (request.toLowerCase().endsWith("delete")) { + throw new DeleteIndexException(); + } + } + + // Report error when user input is not in correct format + public void tryAddTask(TaskList tasks, String request) { + try { + checkDescription(request); + tasks.addTask(request.trim()); + } catch (GeneralException e) { + System.out.print(boundary + "Hmm...I'm sorry but I cannot understand this :(" + + System.lineSeparator() + boundary); + } catch (TaskEmptyException e) { + System.out.print(boundary + "Hmm...hi dear, remember to put in your task description~" + + System.lineSeparator() + boundary); + } catch (DeadlineFormatException e) { + System.out.print(boundary + "Hmm...hi dear, when do u want to finish this by?" + + System.lineSeparator() + boundary); + } catch (EventFormatException e) { + System.out.print(boundary + "Hmm...hi dear, when is this event happening?" + + System.lineSeparator() + boundary); + } + } + + public void tryDeleteTask(TaskList tasks, String request) { + try { + checkDeleteIndex(request); + tasks.deleteTask(Integer.parseInt(request.substring(7)) - 1); + } catch (DeleteIndexException e) { + System.out.print(boundary + "Hmm...hi dear, which task do you want to delete?" + + System.lineSeparator() + boundary); + } + } + +} diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java new file mode 100644 index 000000000..3131ef43b --- /dev/null +++ b/src/main/java/duke/Storage.java @@ -0,0 +1,84 @@ +package duke; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Scanner; + +public class Storage { + public static String boundary = "____________________________________________________________" + System.lineSeparator(); + + // Create data directory and dukeData.txt if they don't exist + public Storage() { + File dataDirectory = new File("./data"); + if (!dataDirectory.exists()) { + try { + Files.createDirectory(Paths.get("./data")); + } catch (IOException e) { + System.out.println("Hmm...I cannot create the data directory."); + } + } + + File dukeData = new File("./data/dukeData.txt"); + try { + if (dukeData.createNewFile()) { + System.out.println("Creating a new data file..."); + } + } catch (IOException e) { + System.out.println("Hmm... I cannot create the data file."); + } + } + + public void writeToFile(String textToWrite) throws IOException { + FileWriter fw = new FileWriter("./data/dukeData.txt"); // create a FileWriter in append mode + fw.write(textToWrite); + fw.close(); + } + + // Add existing tasks from data file + public static void readToList(TaskList tasks) throws FileNotFoundException { + File f = new File("./data/dukeData.txt"); + Scanner s = new Scanner(f); + while (s.hasNext()) { + String currentLine = s.nextLine(); + switch (currentLine.charAt(1)) { + case 'T': + tasks.addTodo(currentLine.substring(7)); + break; + case 'D': + int byIndex = currentLine.indexOf("("); + String by = currentLine.substring(byIndex + 5, currentLine.length() - 1); + tasks.addDeadline(currentLine.substring(7, byIndex - 1), by); + break; + case 'E': + int atIndex = currentLine.indexOf("("); + String at = currentLine.substring(atIndex + 5, currentLine.length() - 1); + tasks.addEvent(currentLine.substring(7, atIndex - 1), at); + break; + default: + } + if (currentLine.charAt(4) == 'X') { + tasks.getTask(tasks.countTask).markDone(); + } + tasks.countTask += 1; + } + } + + // Write tasks to the given file + public static void writeData(Storage dataFile, TaskList tasks) { + StringBuilder toWrite = new StringBuilder(); + for (int i = 0; i < tasks.countTask; i++) { + toWrite.append(tasks.getTask(i)).append(System.lineSeparator()); + } + + try { + dataFile.writeToFile(toWrite.toString()); + } catch (IOException e) { + System.out.print(boundary + "Hmm...I cannot write to the data file." + + System.lineSeparator() + boundary); + } + } +} diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java new file mode 100644 index 000000000..cba35dccf --- /dev/null +++ b/src/main/java/duke/TaskList.java @@ -0,0 +1,103 @@ +package duke; + +import duke.exceptions.DeadlineFormatException; +import duke.exceptions.EventFormatException; +import duke.exceptions.GeneralException; +import duke.exceptions.TaskEmptyException; +import duke.task.Deadline; +import duke.task.Event; +import duke.task.Task; +import duke.task.Todo; + +import java.util.ArrayList; + +public class TaskList { + public static String boundary = "____________________________________________________________" + System.lineSeparator(); + protected ArrayList taskList = new ArrayList<>(); + protected int countTask; + + public TaskList() { + countTask = 0; + } + + public Task getTask(int index) { + return taskList.get(index); + } + + // Add the given task into the task list + public void addTask(String request) throws GeneralException, + TaskEmptyException, DeadlineFormatException, EventFormatException { + if (request.toLowerCase().startsWith("deadline")) { + if ((!request.contains("/by"))) { + throw new DeadlineFormatException(); + } else if (request.substring(9, (request.indexOf("/by"))).trim().equals("")) { + throw new TaskEmptyException(); + } + int byPosition = request.indexOf("/"); + taskList.add(new Deadline(request.substring(9, byPosition - 1), request.substring(byPosition + 4))); + } else if (request.toLowerCase().startsWith("event")) { + if (!request.contains("/at")) { + throw new EventFormatException(); + } else if (request.substring(6, (request.indexOf("/at"))).trim().equals("")) { + throw new TaskEmptyException(); + } + int atPosition = request.indexOf("/"); + taskList.add(new Event(request.substring(6, atPosition - 1), request.substring(atPosition + 4))); + } else if (request.toLowerCase().startsWith("todo")) { + taskList.add(new Todo(request.substring(5))); + } else { + throw new GeneralException(); + } + + countTask++; + + System.out.println(boundary + "Got it. I've added this task: " + System.lineSeparator() + taskList.get(countTask - 1)); + System.out.print("Now you have " + countTask + " tasks in the list."+ System.lineSeparator() + boundary); + } + + public void addTodo(String description) { + taskList.add(new Todo(description)); + } + + public void addDeadline(String description, String by) { + taskList.add(new Deadline(description, by)); + } + + public void addEvent(String description, String at) { + taskList.add(new Event(description, at)); + } + + // Mark the given task as done + public void markTask(int toMark) { + taskList.get(toMark).markDone(); + System.out.println(boundary + "Nice! I've marked this task as done:" + + System.lineSeparator() + taskList.get(toMark)); + System.out.print(boundary); + } + + // Mark the given task as not done yet + public void unmarkTask(int toUnmark) { + taskList.get(toUnmark).markNotDone(); + System.out.println(boundary + "OK, I've marked this task as not done yet:" + + System.lineSeparator() + taskList.get(toUnmark)); + System.out.print(boundary); + } + + // List the current tasks + public void printList() { + System.out.println(boundary + "Here are the tasks in your list:"); + for (int i = 0; i < countTask; i++) { + System.out.println((i + 1) + ". " + getTask(i)); + } + System.out.print("Now you have " + countTask + " tasks in the list."+ System.lineSeparator() + boundary); + } + + // Delete the given task from task list + public void deleteTask(int index) { + System.out.println(boundary + "Noted. I've removed this task:"); + System.out.println(taskList.get(index)); + System.out.print("Now you have " + (countTask - 1) + " tasks in the list." + System.lineSeparator() + boundary); + taskList.remove(index); + countTask -= 1; + } +} diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java new file mode 100644 index 000000000..75c9dcdd8 --- /dev/null +++ b/src/main/java/duke/Ui.java @@ -0,0 +1,47 @@ +package duke; + +import duke.exceptions.DeleteIndexException; +import duke.exceptions.TaskEmptyException; + +import java.util.Scanner; + +public class Ui { + public static String boundary = "____________________________________________________________" + System.lineSeparator(); + private static final Parser parser = new Parser(); + + public void sayHello() { + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + System.out.println(boundary + logo); + System.out.println("Hello! I'm Duke"); + System.out.println("What can I do for you?" + System.lineSeparator() + boundary); + } + + public void sayGoodbye() { + System.out.print(boundary + "Bye. Hope to see you again soon!" + System.lineSeparator() + boundary); + } + + public void interact(TaskList tasks) { + Scanner in = new Scanner(System.in); + String line = in.nextLine(); + + while (!line.equalsIgnoreCase("bye")) { + if (line.equalsIgnoreCase("list")) { + tasks.printList(); + } else if (line.toLowerCase().startsWith("mark")) { + tasks.markTask(Integer.parseInt(line.substring(5)) - 1); + } else if (line.toLowerCase().startsWith("unmark")) { + tasks.unmarkTask(Integer.parseInt(line.substring(7)) - 1); + } else if (line.toLowerCase().startsWith("delete")) { + parser.tryDeleteTask(tasks, line); + } else { + parser.tryAddTask(tasks, line); + } + in = new Scanner(System.in); + line = in.nextLine(); + } + } +} diff --git a/src/main/java/duke/exceptions/DeleteIndexException.java b/src/main/java/duke/exceptions/DeleteIndexException.java new file mode 100644 index 000000000..ad05a35f5 --- /dev/null +++ b/src/main/java/duke/exceptions/DeleteIndexException.java @@ -0,0 +1,4 @@ +package duke.exceptions; + +public class DeleteIndexException extends Exception { +} From c3fdf5e115ce8d67608fbdadd6af2705ea2bd7db Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Sat, 26 Feb 2022 16:14:14 +0800 Subject: [PATCH 11/20] Level-9 and A-JavaDoc implemented --- src/main/java/duke/Parser.java | 33 +++++++++++++++-- src/main/java/duke/Storage.java | 16 +++++++-- src/main/java/duke/TaskList.java | 35 ++++++++++++++++--- src/main/java/duke/Ui.java | 5 +++ .../duke/exceptions/FindKeywordException.java | 4 +++ src/main/java/duke/task/Task.java | 3 ++ 6 files changed, 85 insertions(+), 11 deletions(-) create mode 100644 src/main/java/duke/exceptions/FindKeywordException.java diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index f075e41cd..315754cd7 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -5,7 +5,10 @@ public class Parser { public static String boundary = "____________________________________________________________" + System.lineSeparator(); - // Report error to user if he/she did not put task description + /* Report error to user if he/she did not put task description. + * @param request The request by user. + * @throws TaskEmptyException If user request only contains task type but no task description. + */ public void checkDescription(String request) throws TaskEmptyException { if (request.toLowerCase().endsWith("deadline") || request.toLowerCase().endsWith("event") || @@ -14,14 +17,27 @@ public void checkDescription(String request) throws TaskEmptyException { } } - // Report error if the user did not give an index of task to delete + /* Report error if the user did not give an index of task to delete. + * @param request The request by user. + * @throws DeleteIndexException If user request only contains "delete" but no index. + */ public void checkDeleteIndex(String request) throws DeleteIndexException { if (request.toLowerCase().endsWith("delete")) { throw new DeleteIndexException(); } } - // Report error when user input is not in correct format + /* Report error if the user did not give a keyword to search. + * @param request The request by user. + * @throws FindKeywordException If user request only contains "find" but no keyword. + */ + public void checkFindKeyword (String request) throws FindKeywordException { + if (request.toLowerCase().endsWith("find")) { + throw new FindKeywordException(); + } + } + + // Try adding a task and print error message when user's add request is not in correct format public void tryAddTask(TaskList tasks, String request) { try { checkDescription(request); @@ -41,6 +57,7 @@ public void tryAddTask(TaskList tasks, String request) { } } + // Try deleting a task and print error message when user's delete request is not in correct format public void tryDeleteTask(TaskList tasks, String request) { try { checkDeleteIndex(request); @@ -51,4 +68,14 @@ public void tryDeleteTask(TaskList tasks, String request) { } } + // Trying finding a task and print error message when user's find request is not in correct format + public void tryFindTask(TaskList tasks, String request) { + try { + checkFindKeyword(request); + tasks.findTask(request.substring(5)); + } catch (FindKeywordException e) { + System.out.print(boundary + "Hmm...hi dear, please give me a keyword to search." + + System.lineSeparator() + boundary); + } + } } diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index 3131ef43b..33c4c3907 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -11,7 +11,7 @@ public class Storage { public static String boundary = "____________________________________________________________" + System.lineSeparator(); - // Create data directory and dukeData.txt if they don't exist + // Create data directory and dukeData.txt if they don't exist. public Storage() { File dataDirectory = new File("./data"); if (!dataDirectory.exists()) { @@ -32,13 +32,20 @@ public Storage() { } } + /* Write the given string to dukeData.txt. + * @param textToWrite The String to be written into the file. + * @throws IOException + */ public void writeToFile(String textToWrite) throws IOException { FileWriter fw = new FileWriter("./data/dukeData.txt"); // create a FileWriter in append mode fw.write(textToWrite); fw.close(); } - // Add existing tasks from data file + /* Add existing tasks from data file to the given task list. + * @param tasks The task list to be written to. + * @throws FileNotFoundException If the data file cannot be found. + */ public static void readToList(TaskList tasks) throws FileNotFoundException { File f = new File("./data/dukeData.txt"); Scanner s = new Scanner(f); @@ -67,7 +74,10 @@ public static void readToList(TaskList tasks) throws FileNotFoundException { } } - // Write tasks to the given file + /* Write tasks to the given file. + * @param dataFile The data file to be written to. + * @param tasks The task list that is read from. + */ public static void writeData(Storage dataFile, TaskList tasks) { StringBuilder toWrite = new StringBuilder(); for (int i = 0; i < tasks.countTask; i++) { diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index cba35dccf..cee8b3d94 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -20,11 +20,17 @@ public TaskList() { countTask = 0; } + /* Get the task of the given index. + * @param index The index of the task to be returned. + * @return The task of the index requested. + */ public Task getTask(int index) { return taskList.get(index); } - // Add the given task into the task list + /* Add the given task into the task list. + * @param request The input request given by user. + */ public void addTask(String request) throws GeneralException, TaskEmptyException, DeadlineFormatException, EventFormatException { if (request.toLowerCase().startsWith("deadline")) { @@ -67,7 +73,9 @@ public void addEvent(String description, String at) { taskList.add(new Event(description, at)); } - // Mark the given task as done + /* Mark the given task as done + * @param toMark The index of the task to be marked as done. + */ public void markTask(int toMark) { taskList.get(toMark).markDone(); System.out.println(boundary + "Nice! I've marked this task as done:" @@ -75,7 +83,9 @@ public void markTask(int toMark) { System.out.print(boundary); } - // Mark the given task as not done yet + /* Mark the given task as not done yet. + * @param toUnmark The index of the task to be unmarked. + */ public void unmarkTask(int toUnmark) { taskList.get(toUnmark).markNotDone(); System.out.println(boundary + "OK, I've marked this task as not done yet:" @@ -83,7 +93,7 @@ public void unmarkTask(int toUnmark) { System.out.print(boundary); } - // List the current tasks + // Print out the current tasks. public void printList() { System.out.println(boundary + "Here are the tasks in your list:"); for (int i = 0; i < countTask; i++) { @@ -92,7 +102,22 @@ public void printList() { System.out.print("Now you have " + countTask + " tasks in the list."+ System.lineSeparator() + boundary); } - // Delete the given task from task list + /* Find tasks with the given keyword and print them out. + * @param keyword The keyword to search for in existing tasks. + */ + public void findTask(String keyword) { + System.out.println(boundary + "Here are the matching tasks in your list:"); + for (int i = 0; i < countTask; i++) { + if (taskList.get(i).getDescription().contains(keyword)) { + System.out.println(taskList.get(i)); + } + } + System.out.print(boundary); + } + + /* Delete the given task from task list. + * @param index The index of the task to be deleted. + */ public void deleteTask(int index) { System.out.println(boundary + "Noted. I've removed this task:"); System.out.println(taskList.get(index)); diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 75c9dcdd8..220dbc7d9 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -9,6 +9,7 @@ public class Ui { public static String boundary = "____________________________________________________________" + System.lineSeparator(); private static final Parser parser = new Parser(); + // Print welcome message. public void sayHello() { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -20,10 +21,12 @@ public void sayHello() { System.out.println("What can I do for you?" + System.lineSeparator() + boundary); } + // Print goodbye message. public void sayGoodbye() { System.out.print(boundary + "Bye. Hope to see you again soon!" + System.lineSeparator() + boundary); } + // Interact with user and edit the given task list accordingly. public void interact(TaskList tasks) { Scanner in = new Scanner(System.in); String line = in.nextLine(); @@ -37,6 +40,8 @@ public void interact(TaskList tasks) { tasks.unmarkTask(Integer.parseInt(line.substring(7)) - 1); } else if (line.toLowerCase().startsWith("delete")) { parser.tryDeleteTask(tasks, line); + } else if (line.toLowerCase().startsWith("find")) { + parser.tryFindTask(tasks, line); } else { parser.tryAddTask(tasks, line); } diff --git a/src/main/java/duke/exceptions/FindKeywordException.java b/src/main/java/duke/exceptions/FindKeywordException.java new file mode 100644 index 000000000..88a12899b --- /dev/null +++ b/src/main/java/duke/exceptions/FindKeywordException.java @@ -0,0 +1,4 @@ +package duke.exceptions; + +public class FindKeywordException extends Exception { +} diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index 864fe6e29..010efdb43 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -13,6 +13,9 @@ public void setTask(String description) { this.description = description; } + public String getDescription() { + return description; + } public String getStatusIcon() { return (isDone ? "X" : " "); // mark done task with X } From c0904098aee16fc5103f74548a9aa82f21d08bc6 Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Sat, 26 Feb 2022 22:14:34 +0800 Subject: [PATCH 12/20] Level-8 implemented --- src/main/java/duke/Duke.java | 3 +++ src/main/java/duke/Parser.java | 5 +++++ src/main/java/duke/Storage.java | 8 ++++++-- src/main/java/duke/TaskList.java | 1 + src/main/java/duke/task/Deadline.java | 7 ++++++- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index a7b07862b..c27bdf6e0 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,6 +1,7 @@ package duke; import java.io.FileNotFoundException; +import java.text.ParseException; public class Duke { private final TaskList tasks; @@ -14,6 +15,8 @@ public Duke() { Storage.readToList(tasks); } catch (FileNotFoundException e) { System.out.println("Hmm...File creation failed, I cannot write to the data file."); + } catch (ParseException e) { + System.out.println("Hmm...There's something wrong with Deadlines in your data file."); } } diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index f075e41cd..baca5b186 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -2,6 +2,8 @@ import duke.exceptions.*; +import java.time.format.DateTimeParseException; + public class Parser { public static String boundary = "____________________________________________________________" + System.lineSeparator(); @@ -35,6 +37,9 @@ public void tryAddTask(TaskList tasks, String request) { } catch (DeadlineFormatException e) { System.out.print(boundary + "Hmm...hi dear, when do u want to finish this by?" + System.lineSeparator() + boundary); + } catch (DateTimeParseException e) { + System.out.print(boundary + "Hmm...hi dear, please input your Deadline in \"description /by yyyy-mm-dd\" format" + + System.lineSeparator() + boundary); } catch (EventFormatException e) { System.out.print(boundary + "Hmm...hi dear, when is this event happening?" + System.lineSeparator() + boundary); diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index 3131ef43b..cc0e0c17e 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -6,6 +6,9 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.text.ParseException; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.Scanner; public class Storage { @@ -39,7 +42,7 @@ public void writeToFile(String textToWrite) throws IOException { } // Add existing tasks from data file - public static void readToList(TaskList tasks) throws FileNotFoundException { + public static void readToList(TaskList tasks) throws FileNotFoundException, ParseException { File f = new File("./data/dukeData.txt"); Scanner s = new Scanner(f); while (s.hasNext()) { @@ -51,7 +54,8 @@ public static void readToList(TaskList tasks) throws FileNotFoundException { case 'D': int byIndex = currentLine.indexOf("("); String by = currentLine.substring(byIndex + 5, currentLine.length() - 1); - tasks.addDeadline(currentLine.substring(7, byIndex - 1), by); + final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy"); + tasks.addDeadline(currentLine.substring(7, byIndex - 1), String.valueOf(LocalDate.parse(by, formatter))); break; case 'E': int atIndex = currentLine.indexOf("("); diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index cba35dccf..5e0df89db 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -9,6 +9,7 @@ import duke.task.Task; import duke.task.Todo; +import java.time.LocalDate; import java.util.ArrayList; public class TaskList { diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index 2b0a9ca11..47cb836c6 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,15 +1,20 @@ package duke.task; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + public class Deadline extends Task { protected String by; + protected LocalDate date; public Deadline(String description, String by) { super(description); this.by = by; + this.date = LocalDate.parse(by); } @Override public String toString() { - return "[D]" + super.toString() + " (by: " + by + ")"; + return "[D]" + super.toString() + " (by: " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + ")"; } } \ No newline at end of file From 057cc7e779385155ef262e8da74d3ea2b7c096f3 Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Tue, 1 Mar 2022 14:18:46 +0800 Subject: [PATCH 13/20] Some minor changes --- src/main/java/duke/TaskList.java | 1 - src/main/java/duke/Ui.java | 3 --- 2 files changed, 4 deletions(-) diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index 7bf0aa0e8..cee8b3d94 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -9,7 +9,6 @@ import duke.task.Task; import duke.task.Todo; -import java.time.LocalDate; import java.util.ArrayList; public class TaskList { diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 220dbc7d9..42a466c26 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -1,8 +1,5 @@ package duke; -import duke.exceptions.DeleteIndexException; -import duke.exceptions.TaskEmptyException; - import java.util.Scanner; public class Ui { From 6880a0a76fe1ca9d2d1d90fdf9ea5875861bf796 Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Wed, 2 Mar 2022 10:11:21 +0800 Subject: [PATCH 14/20] README updated --- docs/README.md | 175 +++++++++++++++++++++++++++++++-- src/main/java/duke/Parser.java | 2 +- 2 files changed, 166 insertions(+), 11 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..ed72121fa 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,28 +2,183 @@ ## Features -### Feature-ABC +### Add task -Description of the feature. +Add different type of tasks by using `todo`, `deadline`, and `event`. -### Feature-XYZ +### Delete task -Description of the feature. +Delete existing task by using `delete` + +### View task + +View existing tasks by using `list` + +### Find task + +Search for tasks with a keyword by using `find` ## Usage -### `Keyword` - Describe action +### `list` - View current task list + +Example of usage: + +`list` + +Expected outcome: +The tasks you have in your current task list. +``` +____________________________________________________________ +Here are the tasks in your list: +1. [E][X] that event (at: this time) +2. [T][ ] something +3. [D][ ] java practice (by: Sep 1 2023) +Now you have 3 tasks in the list. +____________________________________________________________ +``` + +### `todo` - Add a Todo task + +Add a Todo task with description to the task list. + +Format: `todo DESCRIPTION` + +Example of usage: + +`todo CS2113 assignment` + +Expected outcome: +Message showing the task is added successfully. +``` +____________________________________________________________ +Got it. I've added this task: +[T][ ] CS2113 assignment +Now you have 4 tasks in the list. +____________________________________________________________ +``` + +### `event` - Add an Event -Describe the action and its outcome. +Add an Event task with description and event time. -Example of usage: +Format: `event EVENTDESCRIPTION /at TIMEDESCRIPTION` -`keyword (optional arguments)` +Example of usage: + +`event CS2113 lecture /at this afternoon` Expected outcome: +Message showing the task is added successfully. +``` +____________________________________________________________ +Got it. I've added this task: +[E][ ] CS2113 lecture (at: this afternoon) +Now you have 5 tasks in the list. +____________________________________________________________ +``` + +### `deadline` - Add a deadline + +Add a deadline task with description and due date. + +Format: `deadline DESCRIPTION /by YYYY-MM-DD` -Description of the outcome. +Example of usage: +`deadline CS2113 quiz /by 2022-3-5` + +Expected outcome: +Message showing the task is added successfully. ``` -expected output +____________________________________________________________ +Got it. I've added this task: +[D][ ] CS2113 quiz (by: Mar 5 2022) +Now you have 6 tasks in the list. +____________________________________________________________ ``` + +### `mark` - Mark a task as done + +Mark the task with the given index as finished. + +Format: `mark INDEX` + +Example of usage: + +`mark 6` + +Expected outcome: +Message showing the task is marked as done. +``` +____________________________________________________________ +Nice! I've marked this task as done: +[D][X] CS2113 quiz (by: Mar 5 2022) +____________________________________________________________ +``` + +### `unmark` - Mark a task as not done yet + +Mark the task with the given index as not finished. + +Format: `unmark INDEX` + +Example of usage: + +`unmark 6` + +Expected outcome: +Message showing the task is marked as not done yet. +``` +____________________________________________________________ +OK, I've marked this task as not done yet: +[D][ ] CS2113 quiz (by: Mar 5 2022) +____________________________________________________________ +``` + +### `find` - Find tasks with keyword + +Find tasks by searching for a keyword. + +Format: `find KEYWORD` + +Example of usage: + +`find 2113` + +Expected outcome: +The list of matching tasks in current task list. +``` +____________________________________________________________ +Here are the matching tasks in your list: +[T][ ] CS2113 assignment +[E][ ] CS2113 lecture (at: this afternoon) +[D][ ] CS2113 quiz (by: Mar 5 2022) +____________________________________________________________ +``` + +### `delete` - Delete a task + +Delete the task with the given index. + +Format: `delete INDEX` + +Example of usage: + +`delete 3` + +Expected outcome: +Message showing the task is deleted successfully. +``` +____________________________________________________________ +Noted. I've removed this task: +[T][ ] something +Now you have 5 tasks in the list. +____________________________________________________________ +``` + +### `bye` - Exit + +Exit the program. + +Format: `bye` diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index c6fca9b29..5716a73f9 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -54,7 +54,7 @@ public void tryAddTask(TaskList tasks, String request) { System.out.print(boundary + "Hmm...hi dear, when do u want to finish this by?" + System.lineSeparator() + boundary); } catch (DateTimeParseException e) { - System.out.print(boundary + "Hmm...hi dear, please input your Deadline in \"description /by yyyy-mm-dd\" format" + System.out.print(boundary + "Hmm...hi dear, please input your Deadline in \"deadline DESCRIPTION /by yyyy-mm-dd\" format" + System.lineSeparator() + boundary); } catch (EventFormatException e) { System.out.print(boundary + "Hmm...hi dear, when is this event happening?" From 59aebe28307ef01a6f350997075e5187036a3c56 Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Wed, 2 Mar 2022 10:28:59 +0800 Subject: [PATCH 15/20] A-JavaDoc improved --- src/main/java/duke/Duke.java | 1 + src/main/java/duke/task/Deadline.java | 1 + src/main/java/duke/task/Event.java | 1 + src/main/java/duke/task/Todo.java | 1 + 4 files changed, 4 insertions(+) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index c27bdf6e0..695b6cce2 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -20,6 +20,7 @@ public Duke() { } } + // Run the Duke program from start public void run() { Storage dataFile = new Storage(); ui.sayHello(); diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index 47cb836c6..eaafd5cc0 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -13,6 +13,7 @@ public Deadline(String description, String by) { this.date = LocalDate.parse(by); } + // Print Deadline in a fixed format @Override public String toString() { return "[D]" + super.toString() + " (by: " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + ")"; diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index dee1ff84b..62609eea6 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -8,6 +8,7 @@ public Event (String description, String at) { this.at = at; } + // Print event in a fixed format @Override public String toString() { return "[E]" + super.toString() + " (at: " + at + ")"; diff --git a/src/main/java/duke/task/Todo.java b/src/main/java/duke/task/Todo.java index 1dc39b7f6..5f83030ec 100644 --- a/src/main/java/duke/task/Todo.java +++ b/src/main/java/duke/task/Todo.java @@ -5,6 +5,7 @@ public Todo(String description) { super(description); } + // Print the todo task in a fixed format @Override public String toString() { return "[T]" + super.toString(); From 1784b96ac2582b4edb3e196c3f9f5bd74238cc2c Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Wed, 2 Mar 2022 12:00:32 +0800 Subject: [PATCH 16/20] Smoke test debug --- docs/README.md | 13 +++++++++++++ src/main/java/duke/Duke.java | 2 +- src/main/java/duke/Storage.java | 3 ++- src/main/java/duke/task/Deadline.java | 4 +++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index ed72121fa..c9543d6a6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,5 +1,14 @@ # User Guide +Duke is a desktop app for managing tasks, optimized for use via a Command Line Interface (CLI). + +## Quick Start + +1. Ensure you have Java `11` or above installed in your Computer. +2. Download the latest duke.jar from [here](https://github.com/cczhouqi/ip/releases). +3. Copy the file to the folder you want to use as the home folder for your Duke. +4. Run the command `java -jar ip.jar` in the same folder as the jar file. + ## Features ### Add task @@ -18,6 +27,10 @@ View existing tasks by using `list` Search for tasks with a keyword by using `find` +### Mark task + +Mark a task as finished/unfinished by using `mark` and `unmark` + ## Usage ### `list` - View current task list diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 695b6cce2..f562d740c 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -14,7 +14,7 @@ public Duke() { try { Storage.readToList(tasks); } catch (FileNotFoundException e) { - System.out.println("Hmm...File creation failed, I cannot write to the data file."); + System.out.println("Hmm...I think I need to create a new data file."); } catch (ParseException e) { System.out.println("Hmm...There's something wrong with Deadlines in your data file."); } diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index c4c64b544..5779e647f 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -9,6 +9,7 @@ import java.text.ParseException; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.util.Locale; import java.util.Scanner; public class Storage { @@ -61,7 +62,7 @@ public static void readToList(TaskList tasks) throws FileNotFoundException, Pars case 'D': int byIndex = currentLine.indexOf("("); String by = currentLine.substring(byIndex + 5, currentLine.length() - 1); - final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy"); + final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd yyyy", Locale.ENGLISH); tasks.addDeadline(currentLine.substring(7, byIndex - 1), String.valueOf(LocalDate.parse(by, formatter))); break; case 'E': diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index eaafd5cc0..aae633c16 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -2,6 +2,7 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.util.Locale; public class Deadline extends Task { protected String by; @@ -16,6 +17,7 @@ public Deadline(String description, String by) { // Print Deadline in a fixed format @Override public String toString() { - return "[D]" + super.toString() + " (by: " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + ")"; + return "[D]" + super.toString() + " (by: " + + date.format(DateTimeFormatter.ofPattern("MMM dd yyyy", Locale.ENGLISH)) + ")"; } } \ No newline at end of file From 8ae885d7843c53e01b4314b58d7f9b4afb07085f Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Thu, 3 Mar 2022 20:19:17 +0800 Subject: [PATCH 17/20] Edit JavaDoc --- src/main/java/duke/Duke.java | 2 +- src/main/java/duke/Parser.java | 15 +++++++++------ src/main/java/duke/Storage.java | 11 +++++++---- src/main/java/duke/TaskList.java | 18 ++++++++++++------ src/main/java/duke/Ui.java | 6 +++--- src/main/java/duke/task/Deadline.java | 2 +- src/main/java/duke/task/Event.java | 2 +- src/main/java/duke/task/Todo.java | 2 +- 8 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index f562d740c..135b1668b 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -20,7 +20,7 @@ public Duke() { } } - // Run the Duke program from start + // Runs the Duke program from start public void run() { Storage dataFile = new Storage(); ui.sayHello(); diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 5716a73f9..a9ec17357 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -7,7 +7,8 @@ public class Parser { public static String boundary = "____________________________________________________________" + System.lineSeparator(); - /* Report error to user if he/she did not put task description. + /* Reports error to user if he/she did not put task description. + * * @param request The request by user. * @throws TaskEmptyException If user request only contains task type but no task description. */ @@ -19,7 +20,8 @@ public void checkDescription(String request) throws TaskEmptyException { } } - /* Report error if the user did not give an index of task to delete. + /* Reports error if the user did not give an index of task to delete. + * * @param request The request by user. * @throws DeleteIndexException If user request only contains "delete" but no index. */ @@ -29,7 +31,8 @@ public void checkDeleteIndex(String request) throws DeleteIndexException { } } - /* Report error if the user did not give a keyword to search. + /* Reports error if the user did not give a keyword to search. + * * @param request The request by user. * @throws FindKeywordException If user request only contains "find" but no keyword. */ @@ -39,7 +42,7 @@ public void checkFindKeyword (String request) throws FindKeywordException { } } - // Try adding a task and print error message when user's add request is not in correct format + // Tries adding a task and print error message when user's add request is not in correct format public void tryAddTask(TaskList tasks, String request) { try { checkDescription(request); @@ -62,7 +65,7 @@ public void tryAddTask(TaskList tasks, String request) { } } - // Try deleting a task and print error message when user's delete request is not in correct format + // Tries deleting a task and print error message when user's delete request is not in correct format public void tryDeleteTask(TaskList tasks, String request) { try { checkDeleteIndex(request); @@ -73,7 +76,7 @@ public void tryDeleteTask(TaskList tasks, String request) { } } - // Trying finding a task and print error message when user's find request is not in correct format + // Tries finding a task and print error message when user's find request is not in correct format public void tryFindTask(TaskList tasks, String request) { try { checkFindKeyword(request); diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index 5779e647f..27b27e54b 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -15,7 +15,7 @@ public class Storage { public static String boundary = "____________________________________________________________" + System.lineSeparator(); - // Create data directory and dukeData.txt if they don't exist. + // Creates data directory and dukeData.txt if they don't exist. public Storage() { File dataDirectory = new File("./data"); if (!dataDirectory.exists()) { @@ -36,7 +36,8 @@ public Storage() { } } - /* Write the given string to dukeData.txt. + /* Writes the given string to dukeData.txt. + * * @param textToWrite The String to be written into the file. * @throws IOException */ @@ -46,7 +47,8 @@ public void writeToFile(String textToWrite) throws IOException { fw.close(); } - /* Add existing tasks from data file to the given task list. + /* Adds existing tasks from data file to the given task list. + * * @param tasks The task list to be written to. * @throws FileNotFoundException If the data file cannot be found. */ @@ -79,7 +81,8 @@ public static void readToList(TaskList tasks) throws FileNotFoundException, Pars } } - /* Write tasks to the given file. + /* Writes the tasks to the given file. + * * @param dataFile The data file to be written to. * @param tasks The task list that is read from. */ diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index cee8b3d94..99aef026f 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -20,7 +20,8 @@ public TaskList() { countTask = 0; } - /* Get the task of the given index. + /* Gets the task of the given index. + * * @param index The index of the task to be returned. * @return The task of the index requested. */ @@ -28,7 +29,8 @@ public Task getTask(int index) { return taskList.get(index); } - /* Add the given task into the task list. + /* Adds the given task into the task list. + * * @param request The input request given by user. */ public void addTask(String request) throws GeneralException, @@ -73,7 +75,8 @@ public void addEvent(String description, String at) { taskList.add(new Event(description, at)); } - /* Mark the given task as done + /* Marks the given task as done + * * @param toMark The index of the task to be marked as done. */ public void markTask(int toMark) { @@ -83,7 +86,8 @@ public void markTask(int toMark) { System.out.print(boundary); } - /* Mark the given task as not done yet. + /* Marks the given task as not done yet. + * * @param toUnmark The index of the task to be unmarked. */ public void unmarkTask(int toUnmark) { @@ -102,7 +106,8 @@ public void printList() { System.out.print("Now you have " + countTask + " tasks in the list."+ System.lineSeparator() + boundary); } - /* Find tasks with the given keyword and print them out. + /* Finds the tasks with the given keyword and print them out. + * * @param keyword The keyword to search for in existing tasks. */ public void findTask(String keyword) { @@ -115,7 +120,8 @@ public void findTask(String keyword) { System.out.print(boundary); } - /* Delete the given task from task list. + /* Deletes the given task from task list. + * * @param index The index of the task to be deleted. */ public void deleteTask(int index) { diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 42a466c26..da1a729bb 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -6,7 +6,7 @@ public class Ui { public static String boundary = "____________________________________________________________" + System.lineSeparator(); private static final Parser parser = new Parser(); - // Print welcome message. + // Prints welcome message. public void sayHello() { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -18,12 +18,12 @@ public void sayHello() { System.out.println("What can I do for you?" + System.lineSeparator() + boundary); } - // Print goodbye message. + // Prints goodbye message. public void sayGoodbye() { System.out.print(boundary + "Bye. Hope to see you again soon!" + System.lineSeparator() + boundary); } - // Interact with user and edit the given task list accordingly. + // Interacts with user and edit the given task list accordingly. public void interact(TaskList tasks) { Scanner in = new Scanner(System.in); String line = in.nextLine(); diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index aae633c16..faff41c92 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -14,7 +14,7 @@ public Deadline(String description, String by) { this.date = LocalDate.parse(by); } - // Print Deadline in a fixed format + // Prints Deadline in a fixed format @Override public String toString() { return "[D]" + super.toString() + " (by: " diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index 62609eea6..dc28ca224 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -8,7 +8,7 @@ public Event (String description, String at) { this.at = at; } - // Print event in a fixed format + // Prints event in a fixed format @Override public String toString() { return "[E]" + super.toString() + " (at: " + at + ")"; diff --git a/src/main/java/duke/task/Todo.java b/src/main/java/duke/task/Todo.java index 5f83030ec..75fb0b7f0 100644 --- a/src/main/java/duke/task/Todo.java +++ b/src/main/java/duke/task/Todo.java @@ -5,7 +5,7 @@ public Todo(String description) { super(description); } - // Print the todo task in a fixed format + // Prints the todo task in a fixed format @Override public String toString() { return "[T]" + super.toString(); From bc99b0fdd13b890b404644d5ae156b61918f2f36 Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Wed, 16 Mar 2022 21:15:17 +0800 Subject: [PATCH 18/20] Update all --- src/main/java/duke/Duke.java | 38 ----- src/main/java/duke/Parser.java | 89 ------------ src/main/java/duke/Storage.java | 102 ------------- src/main/java/duke/TaskList.java | 134 ------------------ src/main/java/duke/Ui.java | 49 ------- .../exceptions/DeadlineFormatException.java | 4 - .../duke/exceptions/DeleteIndexException.java | 4 - .../duke/exceptions/EventFormatException.java | 4 - .../duke/exceptions/FindKeywordException.java | 4 - .../duke/exceptions/GeneralException.java | 4 - .../duke/exceptions/TaskEmptyException.java | 4 - src/main/java/duke/task/Deadline.java | 23 --- src/main/java/duke/task/Event.java | 16 --- src/main/java/duke/task/Task.java | 35 ----- src/main/java/duke/task/Todo.java | 13 -- src/main/java/tp/AddAppointmentCommand.java | 31 ++++ src/main/java/tp/AddDoctorCommand.java | 29 ++++ src/main/java/tp/AddPatientCommand.java | 28 ++++ src/main/java/tp/Appointment.java | 24 ++++ src/main/java/tp/AppointmentList.java | 64 +++++++++ src/main/java/tp/Command.java | 11 ++ .../java/tp/DeleteAppointmentCommand.java | 19 +++ src/main/java/tp/DeleteDoctorCommand.java | 15 ++ src/main/java/tp/DeletePatientCommand.java | 15 ++ src/main/java/tp/DoctorList.java | 51 +++++++ src/main/java/tp/IHospital.java | 36 +++++ src/main/java/tp/IHospitalException.java | 13 ++ .../java/tp/ListAppointmentListCommand.java | 10 ++ src/main/java/tp/ListDoctorListCommand.java | 10 ++ src/main/java/tp/ListPatientListCommand.java | 10 ++ src/main/java/tp/Parser.java | 96 +++++++++++++ src/main/java/tp/PatientList.java | 57 ++++++++ src/main/java/tp/Storage.java | 5 + src/main/java/tp/Ui.java | 32 +++++ src/main/java/tp/person/Doctor.java | 24 ++++ src/main/java/tp/person/Patient.java | 12 ++ src/main/java/tp/person/Person.java | 55 +++++++ src/test/tp/AddPatientCommandTest.java | 4 + 38 files changed, 651 insertions(+), 523 deletions(-) delete mode 100644 src/main/java/duke/Duke.java delete mode 100644 src/main/java/duke/Parser.java delete mode 100644 src/main/java/duke/Storage.java delete mode 100644 src/main/java/duke/TaskList.java delete mode 100644 src/main/java/duke/Ui.java delete mode 100644 src/main/java/duke/exceptions/DeadlineFormatException.java delete mode 100644 src/main/java/duke/exceptions/DeleteIndexException.java delete mode 100644 src/main/java/duke/exceptions/EventFormatException.java delete mode 100644 src/main/java/duke/exceptions/FindKeywordException.java delete mode 100644 src/main/java/duke/exceptions/GeneralException.java delete mode 100644 src/main/java/duke/exceptions/TaskEmptyException.java delete mode 100644 src/main/java/duke/task/Deadline.java delete mode 100644 src/main/java/duke/task/Event.java delete mode 100644 src/main/java/duke/task/Task.java delete mode 100644 src/main/java/duke/task/Todo.java create mode 100644 src/main/java/tp/AddAppointmentCommand.java create mode 100644 src/main/java/tp/AddDoctorCommand.java create mode 100644 src/main/java/tp/AddPatientCommand.java create mode 100644 src/main/java/tp/Appointment.java create mode 100644 src/main/java/tp/AppointmentList.java create mode 100644 src/main/java/tp/Command.java create mode 100644 src/main/java/tp/DeleteAppointmentCommand.java create mode 100644 src/main/java/tp/DeleteDoctorCommand.java create mode 100644 src/main/java/tp/DeletePatientCommand.java create mode 100644 src/main/java/tp/DoctorList.java create mode 100644 src/main/java/tp/IHospital.java create mode 100644 src/main/java/tp/IHospitalException.java create mode 100644 src/main/java/tp/ListAppointmentListCommand.java create mode 100644 src/main/java/tp/ListDoctorListCommand.java create mode 100644 src/main/java/tp/ListPatientListCommand.java create mode 100644 src/main/java/tp/Parser.java create mode 100644 src/main/java/tp/PatientList.java create mode 100644 src/main/java/tp/Storage.java create mode 100644 src/main/java/tp/Ui.java create mode 100644 src/main/java/tp/person/Doctor.java create mode 100644 src/main/java/tp/person/Patient.java create mode 100644 src/main/java/tp/person/Person.java create mode 100644 src/test/tp/AddPatientCommandTest.java diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java deleted file mode 100644 index 135b1668b..000000000 --- a/src/main/java/duke/Duke.java +++ /dev/null @@ -1,38 +0,0 @@ -package duke; - -import java.io.FileNotFoundException; -import java.text.ParseException; - -public class Duke { - private final TaskList tasks; - private final Ui ui; - - public Duke() { - tasks = new TaskList(); - ui = new Ui(); - - try { - Storage.readToList(tasks); - } catch (FileNotFoundException e) { - System.out.println("Hmm...I think I need to create a new data file."); - } catch (ParseException e) { - System.out.println("Hmm...There's something wrong with Deadlines in your data file."); - } - } - - // Runs the Duke program from start - public void run() { - Storage dataFile = new Storage(); - ui.sayHello(); - - ui.interact(tasks); - - Storage.writeData(dataFile, tasks); - ui.sayGoodbye(); - } - - public static void main(String[] args) { - new Duke().run(); - } - -} diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java deleted file mode 100644 index a9ec17357..000000000 --- a/src/main/java/duke/Parser.java +++ /dev/null @@ -1,89 +0,0 @@ -package duke; - -import duke.exceptions.*; - -import java.time.format.DateTimeParseException; - -public class Parser { - public static String boundary = "____________________________________________________________" + System.lineSeparator(); - - /* Reports error to user if he/she did not put task description. - * - * @param request The request by user. - * @throws TaskEmptyException If user request only contains task type but no task description. - */ - public void checkDescription(String request) throws TaskEmptyException { - if (request.toLowerCase().endsWith("deadline") || - request.toLowerCase().endsWith("event") || - request.toLowerCase().endsWith("todo")) { - throw new TaskEmptyException(); - } - } - - /* Reports error if the user did not give an index of task to delete. - * - * @param request The request by user. - * @throws DeleteIndexException If user request only contains "delete" but no index. - */ - public void checkDeleteIndex(String request) throws DeleteIndexException { - if (request.toLowerCase().endsWith("delete")) { - throw new DeleteIndexException(); - } - } - - /* Reports error if the user did not give a keyword to search. - * - * @param request The request by user. - * @throws FindKeywordException If user request only contains "find" but no keyword. - */ - public void checkFindKeyword (String request) throws FindKeywordException { - if (request.toLowerCase().endsWith("find")) { - throw new FindKeywordException(); - } - } - - // Tries adding a task and print error message when user's add request is not in correct format - public void tryAddTask(TaskList tasks, String request) { - try { - checkDescription(request); - tasks.addTask(request.trim()); - } catch (GeneralException e) { - System.out.print(boundary + "Hmm...I'm sorry but I cannot understand this :(" - + System.lineSeparator() + boundary); - } catch (TaskEmptyException e) { - System.out.print(boundary + "Hmm...hi dear, remember to put in your task description~" - + System.lineSeparator() + boundary); - } catch (DeadlineFormatException e) { - System.out.print(boundary + "Hmm...hi dear, when do u want to finish this by?" - + System.lineSeparator() + boundary); - } catch (DateTimeParseException e) { - System.out.print(boundary + "Hmm...hi dear, please input your Deadline in \"deadline DESCRIPTION /by yyyy-mm-dd\" format" - + System.lineSeparator() + boundary); - } catch (EventFormatException e) { - System.out.print(boundary + "Hmm...hi dear, when is this event happening?" - + System.lineSeparator() + boundary); - } - } - - // Tries deleting a task and print error message when user's delete request is not in correct format - public void tryDeleteTask(TaskList tasks, String request) { - try { - checkDeleteIndex(request); - tasks.deleteTask(Integer.parseInt(request.substring(7)) - 1); - } catch (DeleteIndexException e) { - System.out.print(boundary + "Hmm...hi dear, which task do you want to delete?" - + System.lineSeparator() + boundary); - } - } - - // Tries finding a task and print error message when user's find request is not in correct format - public void tryFindTask(TaskList tasks, String request) { - try { - checkFindKeyword(request); - tasks.findTask(request.substring(5)); - } catch (FindKeywordException e) { - System.out.print(boundary + "Hmm...hi dear, please give me a keyword to search." - + System.lineSeparator() + boundary); - } - } -} diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java deleted file mode 100644 index 27b27e54b..000000000 --- a/src/main/java/duke/Storage.java +++ /dev/null @@ -1,102 +0,0 @@ -package duke; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.text.ParseException; -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.util.Locale; -import java.util.Scanner; - -public class Storage { - public static String boundary = "____________________________________________________________" + System.lineSeparator(); - - // Creates data directory and dukeData.txt if they don't exist. - public Storage() { - File dataDirectory = new File("./data"); - if (!dataDirectory.exists()) { - try { - Files.createDirectory(Paths.get("./data")); - } catch (IOException e) { - System.out.println("Hmm...I cannot create the data directory."); - } - } - - File dukeData = new File("./data/dukeData.txt"); - try { - if (dukeData.createNewFile()) { - System.out.println("Creating a new data file..."); - } - } catch (IOException e) { - System.out.println("Hmm... I cannot create the data file."); - } - } - - /* Writes the given string to dukeData.txt. - * - * @param textToWrite The String to be written into the file. - * @throws IOException - */ - public void writeToFile(String textToWrite) throws IOException { - FileWriter fw = new FileWriter("./data/dukeData.txt"); // create a FileWriter in append mode - fw.write(textToWrite); - fw.close(); - } - - /* Adds existing tasks from data file to the given task list. - * - * @param tasks The task list to be written to. - * @throws FileNotFoundException If the data file cannot be found. - */ - public static void readToList(TaskList tasks) throws FileNotFoundException, ParseException { - File f = new File("./data/dukeData.txt"); - Scanner s = new Scanner(f); - while (s.hasNext()) { - String currentLine = s.nextLine(); - switch (currentLine.charAt(1)) { - case 'T': - tasks.addTodo(currentLine.substring(7)); - break; - case 'D': - int byIndex = currentLine.indexOf("("); - String by = currentLine.substring(byIndex + 5, currentLine.length() - 1); - final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd yyyy", Locale.ENGLISH); - tasks.addDeadline(currentLine.substring(7, byIndex - 1), String.valueOf(LocalDate.parse(by, formatter))); - break; - case 'E': - int atIndex = currentLine.indexOf("("); - String at = currentLine.substring(atIndex + 5, currentLine.length() - 1); - tasks.addEvent(currentLine.substring(7, atIndex - 1), at); - break; - default: - } - if (currentLine.charAt(4) == 'X') { - tasks.getTask(tasks.countTask).markDone(); - } - tasks.countTask += 1; - } - } - - /* Writes the tasks to the given file. - * - * @param dataFile The data file to be written to. - * @param tasks The task list that is read from. - */ - public static void writeData(Storage dataFile, TaskList tasks) { - StringBuilder toWrite = new StringBuilder(); - for (int i = 0; i < tasks.countTask; i++) { - toWrite.append(tasks.getTask(i)).append(System.lineSeparator()); - } - - try { - dataFile.writeToFile(toWrite.toString()); - } catch (IOException e) { - System.out.print(boundary + "Hmm...I cannot write to the data file." - + System.lineSeparator() + boundary); - } - } -} diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java deleted file mode 100644 index 99aef026f..000000000 --- a/src/main/java/duke/TaskList.java +++ /dev/null @@ -1,134 +0,0 @@ -package duke; - -import duke.exceptions.DeadlineFormatException; -import duke.exceptions.EventFormatException; -import duke.exceptions.GeneralException; -import duke.exceptions.TaskEmptyException; -import duke.task.Deadline; -import duke.task.Event; -import duke.task.Task; -import duke.task.Todo; - -import java.util.ArrayList; - -public class TaskList { - public static String boundary = "____________________________________________________________" + System.lineSeparator(); - protected ArrayList taskList = new ArrayList<>(); - protected int countTask; - - public TaskList() { - countTask = 0; - } - - /* Gets the task of the given index. - * - * @param index The index of the task to be returned. - * @return The task of the index requested. - */ - public Task getTask(int index) { - return taskList.get(index); - } - - /* Adds the given task into the task list. - * - * @param request The input request given by user. - */ - public void addTask(String request) throws GeneralException, - TaskEmptyException, DeadlineFormatException, EventFormatException { - if (request.toLowerCase().startsWith("deadline")) { - if ((!request.contains("/by"))) { - throw new DeadlineFormatException(); - } else if (request.substring(9, (request.indexOf("/by"))).trim().equals("")) { - throw new TaskEmptyException(); - } - int byPosition = request.indexOf("/"); - taskList.add(new Deadline(request.substring(9, byPosition - 1), request.substring(byPosition + 4))); - } else if (request.toLowerCase().startsWith("event")) { - if (!request.contains("/at")) { - throw new EventFormatException(); - } else if (request.substring(6, (request.indexOf("/at"))).trim().equals("")) { - throw new TaskEmptyException(); - } - int atPosition = request.indexOf("/"); - taskList.add(new Event(request.substring(6, atPosition - 1), request.substring(atPosition + 4))); - } else if (request.toLowerCase().startsWith("todo")) { - taskList.add(new Todo(request.substring(5))); - } else { - throw new GeneralException(); - } - - countTask++; - - System.out.println(boundary + "Got it. I've added this task: " + System.lineSeparator() + taskList.get(countTask - 1)); - System.out.print("Now you have " + countTask + " tasks in the list."+ System.lineSeparator() + boundary); - } - - public void addTodo(String description) { - taskList.add(new Todo(description)); - } - - public void addDeadline(String description, String by) { - taskList.add(new Deadline(description, by)); - } - - public void addEvent(String description, String at) { - taskList.add(new Event(description, at)); - } - - /* Marks the given task as done - * - * @param toMark The index of the task to be marked as done. - */ - public void markTask(int toMark) { - taskList.get(toMark).markDone(); - System.out.println(boundary + "Nice! I've marked this task as done:" - + System.lineSeparator() + taskList.get(toMark)); - System.out.print(boundary); - } - - /* Marks the given task as not done yet. - * - * @param toUnmark The index of the task to be unmarked. - */ - public void unmarkTask(int toUnmark) { - taskList.get(toUnmark).markNotDone(); - System.out.println(boundary + "OK, I've marked this task as not done yet:" - + System.lineSeparator() + taskList.get(toUnmark)); - System.out.print(boundary); - } - - // Print out the current tasks. - public void printList() { - System.out.println(boundary + "Here are the tasks in your list:"); - for (int i = 0; i < countTask; i++) { - System.out.println((i + 1) + ". " + getTask(i)); - } - System.out.print("Now you have " + countTask + " tasks in the list."+ System.lineSeparator() + boundary); - } - - /* Finds the tasks with the given keyword and print them out. - * - * @param keyword The keyword to search for in existing tasks. - */ - public void findTask(String keyword) { - System.out.println(boundary + "Here are the matching tasks in your list:"); - for (int i = 0; i < countTask; i++) { - if (taskList.get(i).getDescription().contains(keyword)) { - System.out.println(taskList.get(i)); - } - } - System.out.print(boundary); - } - - /* Deletes the given task from task list. - * - * @param index The index of the task to be deleted. - */ - public void deleteTask(int index) { - System.out.println(boundary + "Noted. I've removed this task:"); - System.out.println(taskList.get(index)); - System.out.print("Now you have " + (countTask - 1) + " tasks in the list." + System.lineSeparator() + boundary); - taskList.remove(index); - countTask -= 1; - } -} diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java deleted file mode 100644 index da1a729bb..000000000 --- a/src/main/java/duke/Ui.java +++ /dev/null @@ -1,49 +0,0 @@ -package duke; - -import java.util.Scanner; - -public class Ui { - public static String boundary = "____________________________________________________________" + System.lineSeparator(); - private static final Parser parser = new Parser(); - - // Prints welcome message. - public void sayHello() { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println(boundary + logo); - System.out.println("Hello! I'm Duke"); - System.out.println("What can I do for you?" + System.lineSeparator() + boundary); - } - - // Prints goodbye message. - public void sayGoodbye() { - System.out.print(boundary + "Bye. Hope to see you again soon!" + System.lineSeparator() + boundary); - } - - // Interacts with user and edit the given task list accordingly. - public void interact(TaskList tasks) { - Scanner in = new Scanner(System.in); - String line = in.nextLine(); - - while (!line.equalsIgnoreCase("bye")) { - if (line.equalsIgnoreCase("list")) { - tasks.printList(); - } else if (line.toLowerCase().startsWith("mark")) { - tasks.markTask(Integer.parseInt(line.substring(5)) - 1); - } else if (line.toLowerCase().startsWith("unmark")) { - tasks.unmarkTask(Integer.parseInt(line.substring(7)) - 1); - } else if (line.toLowerCase().startsWith("delete")) { - parser.tryDeleteTask(tasks, line); - } else if (line.toLowerCase().startsWith("find")) { - parser.tryFindTask(tasks, line); - } else { - parser.tryAddTask(tasks, line); - } - in = new Scanner(System.in); - line = in.nextLine(); - } - } -} diff --git a/src/main/java/duke/exceptions/DeadlineFormatException.java b/src/main/java/duke/exceptions/DeadlineFormatException.java deleted file mode 100644 index a849b00bd..000000000 --- a/src/main/java/duke/exceptions/DeadlineFormatException.java +++ /dev/null @@ -1,4 +0,0 @@ -package duke.exceptions; - -public class DeadlineFormatException extends Exception { -} diff --git a/src/main/java/duke/exceptions/DeleteIndexException.java b/src/main/java/duke/exceptions/DeleteIndexException.java deleted file mode 100644 index ad05a35f5..000000000 --- a/src/main/java/duke/exceptions/DeleteIndexException.java +++ /dev/null @@ -1,4 +0,0 @@ -package duke.exceptions; - -public class DeleteIndexException extends Exception { -} diff --git a/src/main/java/duke/exceptions/EventFormatException.java b/src/main/java/duke/exceptions/EventFormatException.java deleted file mode 100644 index 23c287076..000000000 --- a/src/main/java/duke/exceptions/EventFormatException.java +++ /dev/null @@ -1,4 +0,0 @@ -package duke.exceptions; - -public class EventFormatException extends Exception { -} diff --git a/src/main/java/duke/exceptions/FindKeywordException.java b/src/main/java/duke/exceptions/FindKeywordException.java deleted file mode 100644 index 88a12899b..000000000 --- a/src/main/java/duke/exceptions/FindKeywordException.java +++ /dev/null @@ -1,4 +0,0 @@ -package duke.exceptions; - -public class FindKeywordException extends Exception { -} diff --git a/src/main/java/duke/exceptions/GeneralException.java b/src/main/java/duke/exceptions/GeneralException.java deleted file mode 100644 index a34a72b98..000000000 --- a/src/main/java/duke/exceptions/GeneralException.java +++ /dev/null @@ -1,4 +0,0 @@ -package duke.exceptions; - -public class GeneralException extends Exception { -} diff --git a/src/main/java/duke/exceptions/TaskEmptyException.java b/src/main/java/duke/exceptions/TaskEmptyException.java deleted file mode 100644 index 2f9aae9c2..000000000 --- a/src/main/java/duke/exceptions/TaskEmptyException.java +++ /dev/null @@ -1,4 +0,0 @@ -package duke.exceptions; - -public class TaskEmptyException extends Exception { -} diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java deleted file mode 100644 index faff41c92..000000000 --- a/src/main/java/duke/task/Deadline.java +++ /dev/null @@ -1,23 +0,0 @@ -package duke.task; - -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.util.Locale; - -public class Deadline extends Task { - protected String by; - protected LocalDate date; - - public Deadline(String description, String by) { - super(description); - this.by = by; - this.date = LocalDate.parse(by); - } - - // Prints Deadline in a fixed format - @Override - public String toString() { - return "[D]" + super.toString() + " (by: " - + date.format(DateTimeFormatter.ofPattern("MMM dd yyyy", Locale.ENGLISH)) + ")"; - } -} \ No newline at end of file diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java deleted file mode 100644 index dc28ca224..000000000 --- a/src/main/java/duke/task/Event.java +++ /dev/null @@ -1,16 +0,0 @@ -package duke.task; - -public class Event extends Task { - protected String at; - - public Event (String description, String at) { - super(description); - this.at = at; - } - - // Prints event in a fixed format - @Override - public String toString() { - return "[E]" + super.toString() + " (at: " + at + ")"; - } -} diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java deleted file mode 100644 index 010efdb43..000000000 --- a/src/main/java/duke/task/Task.java +++ /dev/null @@ -1,35 +0,0 @@ -package duke.task; - -public class Task { - protected String description; - protected boolean isDone; - - public Task(String description) { - this.description = description; - this.isDone = false; - } - - public void setTask(String description) { - this.description = description; - } - - public String getDescription() { - return description; - } - public String getStatusIcon() { - return (isDone ? "X" : " "); // mark done task with X - } - - public void markDone() { - this.isDone = true; - } - - public void markNotDone() { - this.isDone = false; - } - - @Override - public String toString() { - return ("[" + getStatusIcon() + "] " + description); - } -} diff --git a/src/main/java/duke/task/Todo.java b/src/main/java/duke/task/Todo.java deleted file mode 100644 index 75fb0b7f0..000000000 --- a/src/main/java/duke/task/Todo.java +++ /dev/null @@ -1,13 +0,0 @@ -package duke.task; - -public class Todo extends Task { - public Todo(String description) { - super(description); - } - - // Prints the todo task in a fixed format - @Override - public String toString() { - return "[T]" + super.toString(); - } -} diff --git a/src/main/java/tp/AddAppointmentCommand.java b/src/main/java/tp/AddAppointmentCommand.java new file mode 100644 index 000000000..a99d6759e --- /dev/null +++ b/src/main/java/tp/AddAppointmentCommand.java @@ -0,0 +1,31 @@ +package tp; + +import tp.person.Doctor; +import tp.person.Patient; + +import java.time.LocalDateTime; + +public class AddAppointmentCommand extends Command { + protected int doctorIndex; + protected int patientIndex; + protected LocalDateTime time; + + public AddAppointmentCommand() { + + } + + public AddAppointmentCommand(int doctorIndex, int patientIndex, String time) { + this.doctorIndex = doctorIndex; + this.patientIndex = patientIndex; + this.time = LocalDateTime.parse(time); + } + + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + Doctor doctor = (Doctor) doctorList.getDoctor(doctorIndex); + Patient patient = (Patient) patientList.getPatient(patientIndex); + appointmentList.addAppointment(doctor, patient, time); + } +} diff --git a/src/main/java/tp/AddDoctorCommand.java b/src/main/java/tp/AddDoctorCommand.java new file mode 100644 index 000000000..bdabf877d --- /dev/null +++ b/src/main/java/tp/AddDoctorCommand.java @@ -0,0 +1,29 @@ +package tp; + +import tp.person.Doctor; + +public class AddDoctorCommand extends Command { + protected String id; + protected String name; + protected String phoneNumber; + protected String email; + protected boolean isOnDuty; + + public AddDoctorCommand() { + } + + public AddDoctorCommand(String id, String name, String phoneNumber, String email, boolean isOnDuty) { + this.id = id; + this.name = name; + this.phoneNumber = phoneNumber; + this.email = email; + this.isOnDuty = isOnDuty; + } + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + Doctor doctor = new Doctor(id, name, phoneNumber, email); + doctorList.addDoctor(doctor); + } +} diff --git a/src/main/java/tp/AddPatientCommand.java b/src/main/java/tp/AddPatientCommand.java new file mode 100644 index 000000000..fa3f20d62 --- /dev/null +++ b/src/main/java/tp/AddPatientCommand.java @@ -0,0 +1,28 @@ +package tp; + +import tp.person.Doctor; +import tp.person.Patient; + +public class AddPatientCommand extends Command { + protected String id; + protected String name; + protected String phoneNumber; + protected String email; + + public AddPatientCommand() { + } + + public AddPatientCommand(String id, String name, String phoneNumber, String email) { + this.id = id; + this.name = name; + this.phoneNumber = phoneNumber; + this.email = email; + } + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + Patient patient = new Patient(id, name, phoneNumber, email); + patientList.addPatient(patient); + } +} diff --git a/src/main/java/tp/Appointment.java b/src/main/java/tp/Appointment.java new file mode 100644 index 000000000..05f72429b --- /dev/null +++ b/src/main/java/tp/Appointment.java @@ -0,0 +1,24 @@ +package tp; + +import tp.person.Doctor; +import tp.person.Patient; + +import java.time.LocalDateTime; + +public class Appointment { + protected Doctor doctor; + protected Patient patient; + protected LocalDateTime time; + + public Appointment(Doctor doctor, Patient patient, LocalDateTime time) { + this.doctor = doctor; + this.patient = patient; + this.time = time; + } + + @Override + public String toString() { + return "Doctor: " + doctor.getName() + " || Patient: " + + patient.getName() + " || Appointment time: " + time; + } +} diff --git a/src/main/java/tp/AppointmentList.java b/src/main/java/tp/AppointmentList.java new file mode 100644 index 000000000..3996c8578 --- /dev/null +++ b/src/main/java/tp/AppointmentList.java @@ -0,0 +1,64 @@ +package tp; + +import tp.person.Doctor; +import tp.person.Patient; + +import java.time.LocalDateTime; +import java.util.ArrayList; + +public class AppointmentList { + public static String boundary = "____________________________________________________________" + + System.lineSeparator(); + protected ArrayList appointments = new ArrayList<>(); + protected int countAppointment; + + public AppointmentList() { + countAppointment = 0; + } + + public Appointment getAppointment(int index) { + return appointments.get(index); + } + + /** + * Adds an appointment to appointment list. + * + * @param doctor Doctor assigned for this appointment. + * @param patient Patient coming for this appointment. + * @param time The time reserved. + */ + public void addAppointment(Doctor doctor, Patient patient, LocalDateTime time) { + appointments.add(new Appointment(doctor, patient, time)); + countAppointment++; + System.out.println(boundary + "Noted. I've added this appointment:"); + System.out.println(appointments.get(countAppointment - 1)); + System.out.print("Now you have " + countAppointment + + " appointments recorded in the system." + System.lineSeparator() + boundary); + } + + /** + * Deletes an appointment from the list. + * + * @param index Index of the appointment to be deleted. + */ + public void deleteAppointment(int index) { + System.out.println(boundary + "Noted. I've removed this appointment:"); + System.out.println(appointments.get(index)); + System.out.print("Now you have " + (countAppointment - 1) + + " appointments recorded in the system." + System.lineSeparator() + boundary); + appointments.remove(index - 1); + countAppointment -= 1; + } + + @Override + public String toString() { + String toPrint = boundary + "Here are the existing appointments:" + System.lineSeparator(); + for (int i = 0; i < countAppointment; i++) { + toPrint += ((i + 1) + ". " + getAppointment(i)); + } + toPrint += ("Now you have " + countAppointment + + " appointments recorded in the system." + System.lineSeparator() + + boundary + System.lineSeparator()); + return toPrint; + } +} diff --git a/src/main/java/tp/Command.java b/src/main/java/tp/Command.java new file mode 100644 index 000000000..a57a18b08 --- /dev/null +++ b/src/main/java/tp/Command.java @@ -0,0 +1,11 @@ +package tp; + +public abstract class Command { + + public boolean isExit() { + return false; + } + + public abstract void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException; +} diff --git a/src/main/java/tp/DeleteAppointmentCommand.java b/src/main/java/tp/DeleteAppointmentCommand.java new file mode 100644 index 000000000..e7f600a26 --- /dev/null +++ b/src/main/java/tp/DeleteAppointmentCommand.java @@ -0,0 +1,19 @@ +package tp; + +public class DeleteAppointmentCommand extends Command { + int index; + + public DeleteAppointmentCommand(){ + + } + + public DeleteAppointmentCommand(int index) { + this.index = index; + } + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + appointmentList.deleteAppointment(index); + } +} diff --git a/src/main/java/tp/DeleteDoctorCommand.java b/src/main/java/tp/DeleteDoctorCommand.java new file mode 100644 index 000000000..053de908e --- /dev/null +++ b/src/main/java/tp/DeleteDoctorCommand.java @@ -0,0 +1,15 @@ +package tp; + +public class DeleteDoctorCommand extends Command { + private final int index; + + public DeleteDoctorCommand(int index) { + this.index = index; + } + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + doctorList.deleteDoctor(index); + } +} diff --git a/src/main/java/tp/DeletePatientCommand.java b/src/main/java/tp/DeletePatientCommand.java new file mode 100644 index 000000000..9d6131922 --- /dev/null +++ b/src/main/java/tp/DeletePatientCommand.java @@ -0,0 +1,15 @@ +package tp; + +public class DeletePatientCommand extends Command { + private final int index; + + public DeletePatientCommand(int index) { + this.index = index; + } + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + patientList.deletePatient(index); + } +} diff --git a/src/main/java/tp/DoctorList.java b/src/main/java/tp/DoctorList.java new file mode 100644 index 000000000..10d31fa57 --- /dev/null +++ b/src/main/java/tp/DoctorList.java @@ -0,0 +1,51 @@ +package tp; + +import tp.person.Doctor; +import tp.person.Person; + +import javax.print.Doc; +import java.util.ArrayList; + +public class DoctorList { + public static String boundary = "____________________________________________________________" + + System.lineSeparator(); + protected ArrayList doctors = new ArrayList<>(); + protected int size; + + public DoctorList() { + size = 0; + } + + public Person getDoctor(int index) { + return doctors.get(index - 1); + } + + public void addDoctor(Doctor doctor) { + doctors.add(doctor); + size++; + System.out.println(boundary + "Noted. I've added this doctor:"); + System.out.println(doctors.get(size - 1)); + System.out.print("Now you have " + size + + " doctors recorded in the system." + System.lineSeparator() + boundary); + } + + public void deleteDoctor(int index) { + System.out.println(boundary + "Noted. I've removed this doctor:"); + System.out.println(doctors.get(index)); + System.out.print("Now you have " + (size - 1) + + " doctors in the system." + System.lineSeparator() + boundary); + doctors.remove(index - 1); + size -= 1; + } + + @Override + public String toString() { + String toPrint = boundary + "Here are the doctors in this hospital:" + System.lineSeparator(); + for (int i = 0; i < size; i++) { + toPrint += ((i + 1) + ". " + getDoctor(i)); + } + toPrint += ("You have " + size + " doctors recorded in the system." + + System.lineSeparator() + boundary + System.lineSeparator()); + return toPrint; + } +} diff --git a/src/main/java/tp/IHospital.java b/src/main/java/tp/IHospital.java new file mode 100644 index 000000000..4a8c9720d --- /dev/null +++ b/src/main/java/tp/IHospital.java @@ -0,0 +1,36 @@ +package tp; + +public class IHospital { + private static final Ui ui = new Ui(); + private static final Parser parser = new Parser(); + + private static DoctorList doctors = new DoctorList(); + private static PatientList patients = new PatientList(); + private static AppointmentList appointments = new AppointmentList(); + + public IHospital() { + } + + public void run() { + ui.sayHello(); + String fullCommand = Parser.getCommand(); + Storage storage; + + while (!fullCommand.equals("bye")) { + try { + Command c = parser.parse(fullCommand); + // System.out.println(c.execute(doctors, patients, appointments, ui, storage)); + fullCommand = Parser.getCommand(); + } catch (IHospitalException e) { + System.out.println(e.getMessage()); + fullCommand = Parser.getCommand(); + } + } + ui.sayGoodbye(); + } + + public static void main(String[] args) { + new IHospital().run(); + } + +} diff --git a/src/main/java/tp/IHospitalException.java b/src/main/java/tp/IHospitalException.java new file mode 100644 index 000000000..5aa0e8b08 --- /dev/null +++ b/src/main/java/tp/IHospitalException.java @@ -0,0 +1,13 @@ +package tp; + +public class IHospitalException extends Throwable { + public IHospitalException(String s) { + super(s); + } + + @Override + public String toString() { + return super.getMessage(); + } + +} diff --git a/src/main/java/tp/ListAppointmentListCommand.java b/src/main/java/tp/ListAppointmentListCommand.java new file mode 100644 index 000000000..4961b79dd --- /dev/null +++ b/src/main/java/tp/ListAppointmentListCommand.java @@ -0,0 +1,10 @@ +package tp; + +public class ListAppointmentListCommand extends Command { + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + System.out.print(appointmentList); + } +} diff --git a/src/main/java/tp/ListDoctorListCommand.java b/src/main/java/tp/ListDoctorListCommand.java new file mode 100644 index 000000000..13d8eb0a1 --- /dev/null +++ b/src/main/java/tp/ListDoctorListCommand.java @@ -0,0 +1,10 @@ +package tp; + +public class ListDoctorListCommand extends Command { + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + System.out.print(doctorList); + } +} diff --git a/src/main/java/tp/ListPatientListCommand.java b/src/main/java/tp/ListPatientListCommand.java new file mode 100644 index 000000000..4f221d24b --- /dev/null +++ b/src/main/java/tp/ListPatientListCommand.java @@ -0,0 +1,10 @@ +package tp; + +public class ListPatientListCommand extends Command { + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + System.out.print(patientList); + } +} diff --git a/src/main/java/tp/Parser.java b/src/main/java/tp/Parser.java new file mode 100644 index 000000000..d9b0bb84e --- /dev/null +++ b/src/main/java/tp/Parser.java @@ -0,0 +1,96 @@ +package tp; + +import java.util.Scanner; + +public class Parser { + + public Parser() { + + } + + public static String getCommand() { + String command; + Scanner in = new Scanner(System.in); + command = in.nextLine(); + return command; + } + + public Command parse(String fullCommand) throws IHospitalException { + if (fullCommand.contains("add doctor")) { + String id; + String dummy = fullCommand.trim(); + int idIndex = dummy.indexOf("/id") + 4; + int nameIndex = dummy.indexOf("/n"); + id = dummy.substring(idIndex, nameIndex); + nameIndex += 3; + int phoneNumberIndex = dummy.indexOf("/ph"); + String name = dummy.substring(nameIndex, phoneNumberIndex); + phoneNumberIndex += 4; + int emailIndex = dummy.indexOf("/e"); + String phoneNumber = dummy.substring(phoneNumberIndex, emailIndex); + emailIndex += 3; + + String email = dummy.substring(emailIndex); + + return new AddDoctorCommand(id, name, phoneNumber, email, false); + } else if (fullCommand.contains("add patient")) { + String id; + String dummy = fullCommand.trim(); + int idIndex = dummy.indexOf("/id") + 4; + int nameIndex = dummy.indexOf("/n"); + id = dummy.substring(idIndex, nameIndex); + + nameIndex += 3; + + int phoneNumberIndex = dummy.indexOf("/ph"); + + String name = dummy.substring(nameIndex, phoneNumberIndex); + + phoneNumberIndex += 4; + + int emailIndex = dummy.indexOf("/e"); + String phoneNumber = dummy.substring(phoneNumberIndex, emailIndex); + + emailIndex += 3; + + String email = dummy.substring(emailIndex); + + return new AddPatientCommand(id, name, phoneNumber, email); + } else if (fullCommand.contains("add appointment")) { + String time; + String dummy = fullCommand.trim(); + int timeIndex = dummy.indexOf("/t"); + int doctorIndex = dummy.indexOf("/d"); + time = dummy.substring(timeIndex, doctorIndex); + int patientIndex = dummy.indexOf("/p"); + String s = dummy.substring(doctorIndex, patientIndex); + + doctorIndex = Integer.parseInt(s); + patientIndex += 3; + s = dummy.substring(patientIndex); + patientIndex = Integer.parseInt(s); + return new AddAppointmentCommand(doctorIndex, patientIndex, time); + } else if (fullCommand.contains("delete doctor")) { + String dummy = fullCommand.trim(); + int index = Integer.parseInt(dummy.substring(dummy.length() - 1)); + return new DeleteDoctorCommand(index); + } else if (fullCommand.contains("delete patient")) { + String dummy = fullCommand.trim(); + int index = Integer.parseInt(dummy.substring(dummy.length() - 1)); + return new DeletePatientCommand(index); + } else if (fullCommand.contains("delete appointment")) { + String dummy = fullCommand.trim(); + int index = Integer.parseInt(dummy.substring(dummy.length() - 1)); + return new DeleteAppointmentCommand(index); + } else if (fullCommand.contains("list doctor")) { + return new ListDoctorListCommand(); + } else if (fullCommand.contains("list appointment")) { + return new ListAppointmentListCommand(); + } else if (fullCommand.contains("list patient")) { + return new ListPatientListCommand(); + } + return null; + } + + +} diff --git a/src/main/java/tp/PatientList.java b/src/main/java/tp/PatientList.java new file mode 100644 index 000000000..6fbc52516 --- /dev/null +++ b/src/main/java/tp/PatientList.java @@ -0,0 +1,57 @@ +package tp; + +import tp.person.Patient; +import tp.person.Person; + +import java.util.ArrayList; + +public class PatientList { + public static String boundary = "____________________________________________________________" + + System.lineSeparator(); + protected ArrayList patients = new ArrayList<>(); + protected int countPatient; + + public PatientList() { + countPatient = 0; + } + + public Person getPatient(int index) { + return patients.get(index - 1); + } + + public void addPatient(Patient patient) { + patients.add(patient); + countPatient++; + + System.out.println(boundary + "Noted. I've added this patient:"); + System.out.println(patients.get(countPatient - 1)); + System.out.print("Now you have " + countPatient + + " patients recorded in the system." + System.lineSeparator() + boundary); + } + + /** + * Deletes a patient from the list. + * + * @param index Index of the patient to be deleted. + */ + public void deletePatient(int index) { + System.out.println(boundary + "Noted. I've removed this patient:"); + System.out.println(patients.get(index)); + System.out.print("Now you have " + (countPatient - 1) + + " patients recorded in the system." + System.lineSeparator() + boundary); + patients.remove(index - 1); + countPatient -= 1; + } + + @Override + public String toString() { + String toPrint = boundary + "Here are the patients recorded:" + System.lineSeparator(); + for (int i = 0; i < countPatient; i++) { + toPrint += ((i + 1) + ". " + getPatient(i) + System.lineSeparator()); + } + toPrint += ("You have " + countPatient + " patients recorded in the system." + + System.lineSeparator() + boundary + System.lineSeparator()); + return toPrint; + } +} + diff --git a/src/main/java/tp/Storage.java b/src/main/java/tp/Storage.java new file mode 100644 index 000000000..ff554ad47 --- /dev/null +++ b/src/main/java/tp/Storage.java @@ -0,0 +1,5 @@ +package tp; + +public class Storage { + +} diff --git a/src/main/java/tp/Ui.java b/src/main/java/tp/Ui.java new file mode 100644 index 000000000..6a5cd67aa --- /dev/null +++ b/src/main/java/tp/Ui.java @@ -0,0 +1,32 @@ +package tp; + +import java.util.Scanner; + +public class Ui { + public static String boundary = "____________________________________________________________" + + System.lineSeparator(); + + // Prints welcome message. + public void sayHello() { + System.out.print(boundary); + System.out.println("Hello! This is IHospital."); + System.out.print("What can I do for you?" + System.lineSeparator() + boundary); + } + + // Prints goodbye message. + public void sayGoodbye() { + System.out.print(boundary + "Bye. Hope to see you again soon!" + System.lineSeparator() + boundary); + } + + public void printDoctorPage(DoctorList doctors) { + System.out.print(boundary); + System.out.println("Welcome to Doctor Page."); + System.out.print(doctors); + } + + public void printPatientPage(PatientList patients) { + System.out.print(boundary); + System.out.println("Welcome to Patient Page."); + System.out.print(patients); + } +} diff --git a/src/main/java/tp/person/Doctor.java b/src/main/java/tp/person/Doctor.java new file mode 100644 index 000000000..152b8c954 --- /dev/null +++ b/src/main/java/tp/person/Doctor.java @@ -0,0 +1,24 @@ +package tp.person; + +public class Doctor extends Person { + protected boolean isOnDuty; + + public Doctor(String id, String name, String phoneNumber, String email) { + super(id, name, phoneNumber, email); + isOnDuty = false; + } + + public void markOnDuty() { + isOnDuty = true; + } + + public void markOnLeave() { + isOnDuty = false; + } + + @Override + public String toString() { + return "* DOCTOR " + super.toString(); + } + +} diff --git a/src/main/java/tp/person/Patient.java b/src/main/java/tp/person/Patient.java new file mode 100644 index 000000000..e0975185f --- /dev/null +++ b/src/main/java/tp/person/Patient.java @@ -0,0 +1,12 @@ +package tp.person; + +public class Patient extends Person { + public Patient(String id, String name, String phoneNumber, String email) { + super(id, name, phoneNumber, email); + } + + @Override + public String toString() { + return "* PATIENT " + super.toString(); + } +} diff --git a/src/main/java/tp/person/Person.java b/src/main/java/tp/person/Person.java new file mode 100644 index 000000000..2099ae12c --- /dev/null +++ b/src/main/java/tp/person/Person.java @@ -0,0 +1,55 @@ +package tp.person; + +public class Person { + protected String id; + protected String name; + protected String phoneNumber; + protected String email; + + public Person(String id, String name, String phoneNumber, String email) { + this.id = id; + this.name = name; + this.phoneNumber = phoneNumber; + this.email = email; + } + + public void setPerson(String name, String phoneNumber, String email) { + this.name = name; + this.phoneNumber = phoneNumber; + this.email = email; + } + + public void editName(String name) { + this.name = name; + } + + public void editPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public void editEmail(String email) { + this.email = email; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public String getEmail() { + return email; + } + + @Override + public String toString() { + return "[" + id + "] || Name: " + name + + " || Contact No.: " + phoneNumber + " || Email: " + email; + } +} diff --git a/src/test/tp/AddPatientCommandTest.java b/src/test/tp/AddPatientCommandTest.java new file mode 100644 index 000000000..77b283894 --- /dev/null +++ b/src/test/tp/AddPatientCommandTest.java @@ -0,0 +1,4 @@ +import static org.junit.jupiter.api.Assertions.*; +class AddPatientCommandTest { + +} \ No newline at end of file From 6bcb5f3552b54b4fad6211a8d0c4bfe3eddc9e59 Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Wed, 16 Mar 2022 21:21:24 +0800 Subject: [PATCH 19/20] Copy updates --- src/main/java/seedu/duke/Duke.java | 36 +++++++++++++++++++++++++++ src/main/java/tp/AppointmentList.java | 10 ++++---- src/main/java/tp/DoctorList.java | 10 ++++---- src/main/java/tp/ExitCommand.java | 14 +++++++++++ src/main/java/tp/Parser.java | 14 ++++++----- src/main/java/tp/PatientList.java | 9 +++---- 6 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 src/main/java/seedu/duke/Duke.java create mode 100644 src/main/java/tp/ExitCommand.java diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java new file mode 100644 index 000000000..5616b78ff --- /dev/null +++ b/src/main/java/seedu/duke/Duke.java @@ -0,0 +1,36 @@ +package seedu.duke; + +import tp.DoctorList; +import tp.Parser; +import tp.PatientList; +import tp.Ui; +import tp.AppointmentList; +import tp.Storage; +import tp.IHospitalException; +import tp.Command; +import tp.person.Patient; + +import java.util.Scanner; + +public class Duke { + /** + * Main entry-point for the java.duke.Duke application. + */ + private static final Ui ui = new Ui(); + private static final Parser parser = new Parser(); + private static PatientList patientList = new PatientList(); + private static DoctorList doctorList = new DoctorList(); + private static AppointmentList appointmentList = new AppointmentList(); + private static Storage storage = new Storage(); + + public static void main(String[] args) throws IHospitalException { + ui.sayHello(); + String fullCommand = parser.getCommand(); + while (!fullCommand.equals("bye")) { + Command command = parser.parse(fullCommand); + command.execute(doctorList, patientList, appointmentList, ui, storage); + fullCommand = parser.getCommand(); + } + ui.sayGoodbye(); + } +} diff --git a/src/main/java/tp/AppointmentList.java b/src/main/java/tp/AppointmentList.java index 3996c8578..6d82ff937 100644 --- a/src/main/java/tp/AppointmentList.java +++ b/src/main/java/tp/AppointmentList.java @@ -17,7 +17,7 @@ public AppointmentList() { } public Appointment getAppointment(int index) { - return appointments.get(index); + return appointments.get(index - 1); } /** @@ -43,7 +43,7 @@ public void addAppointment(Doctor doctor, Patient patient, LocalDateTime time) { */ public void deleteAppointment(int index) { System.out.println(boundary + "Noted. I've removed this appointment:"); - System.out.println(appointments.get(index)); + System.out.println(appointments.get(index - 1)); System.out.print("Now you have " + (countAppointment - 1) + " appointments recorded in the system." + System.lineSeparator() + boundary); appointments.remove(index - 1); @@ -53,12 +53,12 @@ public void deleteAppointment(int index) { @Override public String toString() { String toPrint = boundary + "Here are the existing appointments:" + System.lineSeparator(); - for (int i = 0; i < countAppointment; i++) { - toPrint += ((i + 1) + ". " + getAppointment(i)); + for (int i = 1; i <= countAppointment; i++) { + toPrint += (i + ". " + getAppointment(i)); } toPrint += ("Now you have " + countAppointment + " appointments recorded in the system." + System.lineSeparator() + boundary + System.lineSeparator()); return toPrint; } -} +} \ No newline at end of file diff --git a/src/main/java/tp/DoctorList.java b/src/main/java/tp/DoctorList.java index 10d31fa57..867beffd1 100644 --- a/src/main/java/tp/DoctorList.java +++ b/src/main/java/tp/DoctorList.java @@ -10,7 +10,7 @@ public class DoctorList { public static String boundary = "____________________________________________________________" + System.lineSeparator(); protected ArrayList doctors = new ArrayList<>(); - protected int size; + protected int size = 0; public DoctorList() { size = 0; @@ -31,7 +31,7 @@ public void addDoctor(Doctor doctor) { public void deleteDoctor(int index) { System.out.println(boundary + "Noted. I've removed this doctor:"); - System.out.println(doctors.get(index)); + System.out.println(doctors.get(index - 1)); System.out.print("Now you have " + (size - 1) + " doctors in the system." + System.lineSeparator() + boundary); doctors.remove(index - 1); @@ -41,11 +41,11 @@ public void deleteDoctor(int index) { @Override public String toString() { String toPrint = boundary + "Here are the doctors in this hospital:" + System.lineSeparator(); - for (int i = 0; i < size; i++) { - toPrint += ((i + 1) + ". " + getDoctor(i)); + for (int i = 1; i <= size; i++) { + toPrint += (i + ". " + getDoctor(i)); } toPrint += ("You have " + size + " doctors recorded in the system." + System.lineSeparator() + boundary + System.lineSeparator()); return toPrint; } -} +} \ No newline at end of file diff --git a/src/main/java/tp/ExitCommand.java b/src/main/java/tp/ExitCommand.java new file mode 100644 index 000000000..7440eea6e --- /dev/null +++ b/src/main/java/tp/ExitCommand.java @@ -0,0 +1,14 @@ +package tp; + +public class ExitCommand extends Command { + public ExitCommand() { + + } + + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + return; + } +} \ No newline at end of file diff --git a/src/main/java/tp/Parser.java b/src/main/java/tp/Parser.java index d9b0bb84e..26d40d901 100644 --- a/src/main/java/tp/Parser.java +++ b/src/main/java/tp/Parser.java @@ -59,16 +59,16 @@ public Command parse(String fullCommand) throws IHospitalException { } else if (fullCommand.contains("add appointment")) { String time; String dummy = fullCommand.trim(); - int timeIndex = dummy.indexOf("/t"); + int timeIndex = dummy.indexOf("/t") + 3; int doctorIndex = dummy.indexOf("/d"); - time = dummy.substring(timeIndex, doctorIndex); + time = dummy.substring(timeIndex, doctorIndex).trim(); int patientIndex = dummy.indexOf("/p"); - String s = dummy.substring(doctorIndex, patientIndex); + String s = dummy.substring(doctorIndex + 3, patientIndex); - doctorIndex = Integer.parseInt(s); + doctorIndex = Integer.parseInt(s.trim()); patientIndex += 3; s = dummy.substring(patientIndex); - patientIndex = Integer.parseInt(s); + patientIndex = Integer.parseInt(s.trim()); return new AddAppointmentCommand(doctorIndex, patientIndex, time); } else if (fullCommand.contains("delete doctor")) { String dummy = fullCommand.trim(); @@ -88,9 +88,11 @@ public Command parse(String fullCommand) throws IHospitalException { return new ListAppointmentListCommand(); } else if (fullCommand.contains("list patient")) { return new ListPatientListCommand(); + } else if (fullCommand.contains("bye")) { + return new ExitCommand(); } return null; } -} +} \ No newline at end of file diff --git a/src/main/java/tp/PatientList.java b/src/main/java/tp/PatientList.java index 6fbc52516..4d7950bfd 100644 --- a/src/main/java/tp/PatientList.java +++ b/src/main/java/tp/PatientList.java @@ -36,7 +36,7 @@ public void addPatient(Patient patient) { */ public void deletePatient(int index) { System.out.println(boundary + "Noted. I've removed this patient:"); - System.out.println(patients.get(index)); + System.out.println(patients.get(index - 1)); System.out.print("Now you have " + (countPatient - 1) + " patients recorded in the system." + System.lineSeparator() + boundary); patients.remove(index - 1); @@ -46,12 +46,11 @@ public void deletePatient(int index) { @Override public String toString() { String toPrint = boundary + "Here are the patients recorded:" + System.lineSeparator(); - for (int i = 0; i < countPatient; i++) { - toPrint += ((i + 1) + ". " + getPatient(i) + System.lineSeparator()); + for (int i = 1; i <= countPatient; i++) { + toPrint += (i + ". " + getPatient(i) + System.lineSeparator()); } toPrint += ("You have " + countPatient + " patients recorded in the system." - + System.lineSeparator() + boundary + System.lineSeparator()); + + System.lineSeparator() + boundary + System.lineSeparator()); return toPrint; } } - From 0bbdb256309366a521d4905f89062dfd5d1b9b9f Mon Sep 17 00:00:00 2001 From: Zhou Qi <> Date: Wed, 30 Mar 2022 20:49:14 +0800 Subject: [PATCH 20/20] update in wk10 --- docs/AboutUs.md | 9 ++ docs/ByeCommand.png | Bin 0 -> 14544 bytes docs/ByeCommand.puml | 13 ++ docs/ClassDiagram.puml | 40 +++++ docs/DeveloperGuide.md | 47 ++++++ docs/README.md | 201 +------------------------ docs/UserGuide.md | 42 ++++++ src/main/java/tp/IHospital.java | 36 ----- src/main/java/tp/Parser.java | 98 ++++++------ src/main/java/tp/Storage.java | 2 +- src/test/tp/AddPatientCommandTest.java | 4 - src/test/tp/person/DoctorTest.java | 15 ++ src/test/tp/person/PatientTest.java | 16 ++ src/test/tp/person/PersonTest.java | 36 +++++ 14 files changed, 276 insertions(+), 283 deletions(-) create mode 100644 docs/AboutUs.md create mode 100644 docs/ByeCommand.png create mode 100644 docs/ByeCommand.puml create mode 100644 docs/ClassDiagram.puml create mode 100644 docs/DeveloperGuide.md create mode 100644 docs/UserGuide.md delete mode 100644 src/main/java/tp/IHospital.java delete mode 100644 src/test/tp/AddPatientCommandTest.java create mode 100644 src/test/tp/person/DoctorTest.java create mode 100644 src/test/tp/person/PatientTest.java create mode 100644 src/test/tp/person/PersonTest.java diff --git a/docs/AboutUs.md b/docs/AboutUs.md new file mode 100644 index 000000000..0f072953e --- /dev/null +++ b/docs/AboutUs.md @@ -0,0 +1,9 @@ +# About us + +Display | Name | Github Profile | Portfolio +--------|:----:|:--------------:|:---------: +![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) diff --git a/docs/ByeCommand.png b/docs/ByeCommand.png new file mode 100644 index 0000000000000000000000000000000000000000..fa90843be30fff60670a4fb9dd0e7c3fd2222572 GIT binary patch literal 14544 zcmb_@bzD_j*R=^qNQiVJeJJUc20=Qd!9#a9N-HJOEe+Cj04YhOLqXusjdX}K-vae| z@AKUEkN5X}f2auTb@pCs&N;>$bL^K2a*}As1jyH}T|<+W5>vW%?YaZ_gM)Mfe1~v$ z1_J(}a}?KbG_tXEvxFKuUXz4cL+uS5q0h(+-N;NG9c_7;nQbi%tR0=KESZdKtT0)4 zh`DtXmIS=4vg2s_fv! zXJoU}@GgRZLzJHVA-ApG`mcA3j5^#jIX?|2ImBd7TB|<1ua%j|<7^&tpC)mEf83H9L4B`#Yp&z+4g49n-MCz9@f>|SFFqm zjFv&=Ir2$SJ=t7$IOyx@94~k2J8_%J?Vs8r>8qP^DcRDrNc&>nNrU8z5f(BejB!iR zQc4s22b~T@7-Np^Ed<@>%z5L3qTgsM+-0GRhbHh{aAHEXQjSzk;LgI)SY;&5n;Tue z7IWIVEWtYRJoFL0Jgh3>UwR-h55*sHgwpi)=Y;V`jw;6bFutmFCM&+Rp@(9`oyq(i zFN?z5xcD(Xe*!^Ann?rv6X{E0X!CcR?lP=Oy@QW-5_;cQrNBbkF%MnALPGuS)saG2 z^Yq<)0SrS!L*b-C-kTG(4C=)T3k#n_ov=`qFge)Nvr$uJ(dPRrrmPks+G@J6NRO() z&%I6#vU77YuaAw5?JA_)@>3D(?NO!kqfu@>+$(e;JfdVRE-y@C72@RNWM#!fd(JCD zu$az!2O%FkYk?AiJb2b+%`MJdNkeU@CZB-$_iw|d*S=timh|+7-{?XQIvpn z6?~~Xt{*1QJL3M`J>6lM6Xq=kwud{)?9qHbn-5`?hhv&xil6WJxNbY?osx2PtEWvS z{o%;{bz9+;0u_fHq+a=wnH2VZyk82`9VXwqq2PLBker+MCJt+BYr8t8MYm&vb35lW z|FJSwK_i=V5V)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bF ze`7`$FTc+~%R!9-$u4Oe{~>g76i!UQ@s4!phM(<>#q?snEJLb!*)Pxh${^17pMG^? z@CF1450=NASbel<=jPOt*295=Hxm=2eQEL?K33@YmuCG`5r!6Q8-oAliT?ZBK$4n( zEg*c2ds|jzUWMpu|Xg|%= z&oAGTQsl!@h4Ofxa(|%(uQPoup(97u;Ty?k5fT5wqLUq(EQ|Ik+C&GgVfx@*moKKA zyE|{OKcqblBcRx2O9d~T!aTlMNkT3MLAUe-A7BhZp&;U*_Uc|DS#tFx?h|zrAwyUwX@_&j-p3 W)WbeB3h-{>HED4 ":Duke": bye +":Duke" -> ":parser": getCommand() +":parser" --> ":Duke": fullCommand +":Duke" -> ":Ui": sayGoodbye() +":Ui" --> ":Duke": Goodbye message +":Duke" --> User: Goodbye message + + +@enduml \ No newline at end of file diff --git a/docs/ClassDiagram.puml b/docs/ClassDiagram.puml new file mode 100644 index 000000000..b101c5c19 --- /dev/null +++ b/docs/ClassDiagram.puml @@ -0,0 +1,40 @@ +@startuml +'https://plantuml.com/class-diagram + +abstract class AbstractList +abstract AbstractCollection +interface List +interface Collection + +List <|-- AbstractList +Collection <|-- AbstractCollection + +Collection <|- List +AbstractCollection <|- AbstractList +AbstractList <|-- ArrayList + +class DoctorList { +doctors: ArrayList +size: Integer +DoctorList() +getDoctor(index: Integer): Person +addDoctor(doctor: Doctor) +deleteDoctor(index: Integer) +toString(): String +} + +class Person { + +} + +class Doctor { + +} + +enum TimeUnit { +DAYS +HOURS +MINUTES +} + +@enduml \ No newline at end of file diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md new file mode 100644 index 000000000..f7adbc951 --- /dev/null +++ b/docs/DeveloperGuide.md @@ -0,0 +1,47 @@ +# Developer Guide + +## Acknowledgements + +{list here sources of all reused/adapted ideas, code, documentation, and third-party libraries -- include links to the original source as well} + +## Design & implementation + +{Describe the design and implementation of the product. Use UML diagrams and short code snippets where applicable.} + +### Exit program +Step 1: User type "bye" as input to exit the program. Duke will call Parser#getCommand() +to return the user command received. + +Step 2: After checking the user command is "bye", Duke will +call Ui#sayGoodbye to print Goodbye message + +The following sequence diagram shows how the exit operation works: +![](ByeCommand.png) + +## Product scope +### Target user profile +Hospital admin staff + +### Value proposition +IHospital is a desktop application meant for staff in hospitals. Its main purpose is to manage patients, +doctors, nurses, appointments and operation rooms data, and it’s optimised for use via a Command Line Interface (CLI). +If you can type fast, this application allows you to access relevant hospital information faster than traditional GUI applications. + +## User Stories + +|Version| As a ... | I want to ... | So that I can ...| +|--------|----------|---------------|------------------| +|v1.0|new user|see usage instructions|refer to them when I forget how to use the application| +|v2.0|user|find a to-do item by name|locate a to-do without having to go through the entire list| + +## Non-Functional Requirements + +{Give non-functional requirements} + +## Glossary + +* *glossary item* - Definition + +## Instructions for manual testing + +{Give instructions on how to do a manual product testing e.g., how to load sample data to be used for testing} diff --git a/docs/README.md b/docs/README.md index c9543d6a6..c85cbae1f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,197 +1,8 @@ -# User Guide +# IHospital -Duke is a desktop app for managing tasks, optimized for use via a Command Line Interface (CLI). +{Give product intro here} -## Quick Start - -1. Ensure you have Java `11` or above installed in your Computer. -2. Download the latest duke.jar from [here](https://github.com/cczhouqi/ip/releases). -3. Copy the file to the folder you want to use as the home folder for your Duke. -4. Run the command `java -jar ip.jar` in the same folder as the jar file. - -## Features - -### Add task - -Add different type of tasks by using `todo`, `deadline`, and `event`. - -### Delete task - -Delete existing task by using `delete` - -### View task - -View existing tasks by using `list` - -### Find task - -Search for tasks with a keyword by using `find` - -### Mark task - -Mark a task as finished/unfinished by using `mark` and `unmark` - -## Usage - -### `list` - View current task list - -Example of usage: - -`list` - -Expected outcome: -The tasks you have in your current task list. -``` -____________________________________________________________ -Here are the tasks in your list: -1. [E][X] that event (at: this time) -2. [T][ ] something -3. [D][ ] java practice (by: Sep 1 2023) -Now you have 3 tasks in the list. -____________________________________________________________ -``` - -### `todo` - Add a Todo task - -Add a Todo task with description to the task list. - -Format: `todo DESCRIPTION` - -Example of usage: - -`todo CS2113 assignment` - -Expected outcome: -Message showing the task is added successfully. -``` -____________________________________________________________ -Got it. I've added this task: -[T][ ] CS2113 assignment -Now you have 4 tasks in the list. -____________________________________________________________ -``` - -### `event` - Add an Event - -Add an Event task with description and event time. - -Format: `event EVENTDESCRIPTION /at TIMEDESCRIPTION` - -Example of usage: - -`event CS2113 lecture /at this afternoon` - -Expected outcome: -Message showing the task is added successfully. -``` -____________________________________________________________ -Got it. I've added this task: -[E][ ] CS2113 lecture (at: this afternoon) -Now you have 5 tasks in the list. -____________________________________________________________ -``` - -### `deadline` - Add a deadline - -Add a deadline task with description and due date. - -Format: `deadline DESCRIPTION /by YYYY-MM-DD` - -Example of usage: - -`deadline CS2113 quiz /by 2022-3-5` - -Expected outcome: -Message showing the task is added successfully. -``` -____________________________________________________________ -Got it. I've added this task: -[D][ ] CS2113 quiz (by: Mar 5 2022) -Now you have 6 tasks in the list. -____________________________________________________________ -``` - -### `mark` - Mark a task as done - -Mark the task with the given index as finished. - -Format: `mark INDEX` - -Example of usage: - -`mark 6` - -Expected outcome: -Message showing the task is marked as done. -``` -____________________________________________________________ -Nice! I've marked this task as done: -[D][X] CS2113 quiz (by: Mar 5 2022) -____________________________________________________________ -``` - -### `unmark` - Mark a task as not done yet - -Mark the task with the given index as not finished. - -Format: `unmark INDEX` - -Example of usage: - -`unmark 6` - -Expected outcome: -Message showing the task is marked as not done yet. -``` -____________________________________________________________ -OK, I've marked this task as not done yet: -[D][ ] CS2113 quiz (by: Mar 5 2022) -____________________________________________________________ -``` - -### `find` - Find tasks with keyword - -Find tasks by searching for a keyword. - -Format: `find KEYWORD` - -Example of usage: - -`find 2113` - -Expected outcome: -The list of matching tasks in current task list. -``` -____________________________________________________________ -Here are the matching tasks in your list: -[T][ ] CS2113 assignment -[E][ ] CS2113 lecture (at: this afternoon) -[D][ ] CS2113 quiz (by: Mar 5 2022) -____________________________________________________________ -``` - -### `delete` - Delete a task - -Delete the task with the given index. - -Format: `delete INDEX` - -Example of usage: - -`delete 3` - -Expected outcome: -Message showing the task is deleted successfully. -``` -____________________________________________________________ -Noted. I've removed this task: -[T][ ] something -Now you have 5 tasks in the list. -____________________________________________________________ -``` - -### `bye` - Exit - -Exit the program. - -Format: `bye` +Useful links: +* [User Guide](UserGuide.md) +* [Developer Guide](DeveloperGuide.md) +* [About Us](AboutUs.md) diff --git a/docs/UserGuide.md b/docs/UserGuide.md new file mode 100644 index 000000000..abd9fbe89 --- /dev/null +++ b/docs/UserGuide.md @@ -0,0 +1,42 @@ +# User Guide + +## Introduction + +{Give a product intro} + +## Quick Start + +{Give steps to get started quickly} + +1. Ensure that you have Java 11 or above installed. +1. Down the latest version of `Duke` from [here](http://link.to/duke). + +## Features + +{Give detailed description of each feature} + +### Adding a todo: `todo` +Adds a new item to the list of todo items. + +Format: `todo n/TODO_NAME d/DEADLINE` + +* The `DEADLINE` can be in a natural language format. +* The `TODO_NAME` cannot contain punctuation. + +Example of usage: + +`todo n/Write the rest of the User Guide d/next week` + +`todo n/Refactor the User Guide to remove passive voice d/13/04/2020` + +## FAQ + +**Q**: How do I transfer my data to another computer? + +**A**: {your answer here} + +## Command Summary + +{Give a 'cheat sheet' of commands here} + +* Add todo `todo n/TODO_NAME d/DEADLINE` diff --git a/src/main/java/tp/IHospital.java b/src/main/java/tp/IHospital.java deleted file mode 100644 index 4a8c9720d..000000000 --- a/src/main/java/tp/IHospital.java +++ /dev/null @@ -1,36 +0,0 @@ -package tp; - -public class IHospital { - private static final Ui ui = new Ui(); - private static final Parser parser = new Parser(); - - private static DoctorList doctors = new DoctorList(); - private static PatientList patients = new PatientList(); - private static AppointmentList appointments = new AppointmentList(); - - public IHospital() { - } - - public void run() { - ui.sayHello(); - String fullCommand = Parser.getCommand(); - Storage storage; - - while (!fullCommand.equals("bye")) { - try { - Command c = parser.parse(fullCommand); - // System.out.println(c.execute(doctors, patients, appointments, ui, storage)); - fullCommand = Parser.getCommand(); - } catch (IHospitalException e) { - System.out.println(e.getMessage()); - fullCommand = Parser.getCommand(); - } - } - ui.sayGoodbye(); - } - - public static void main(String[] args) { - new IHospital().run(); - } - -} diff --git a/src/main/java/tp/Parser.java b/src/main/java/tp/Parser.java index 26d40d901..e52df641c 100644 --- a/src/main/java/tp/Parser.java +++ b/src/main/java/tp/Parser.java @@ -19,57 +19,61 @@ public Command parse(String fullCommand) throws IHospitalException { if (fullCommand.contains("add doctor")) { String id; String dummy = fullCommand.trim(); - int idIndex = dummy.indexOf("/id") + 4; - int nameIndex = dummy.indexOf("/n"); - id = dummy.substring(idIndex, nameIndex); - nameIndex += 3; - int phoneNumberIndex = dummy.indexOf("/ph"); - String name = dummy.substring(nameIndex, phoneNumberIndex); - phoneNumberIndex += 4; - int emailIndex = dummy.indexOf("/e"); - String phoneNumber = dummy.substring(phoneNumberIndex, emailIndex); - emailIndex += 3; + try { + int idIndex = dummy.indexOf("/id") + 4; + int nameIndex = dummy.indexOf("/n"); + id = dummy.substring(idIndex, nameIndex); + nameIndex += 3; + int phoneNumberIndex = dummy.indexOf("/ph"); + String name = dummy.substring(nameIndex, phoneNumberIndex); + phoneNumberIndex += 4; + int emailIndex = dummy.indexOf("/e"); + String phoneNumber = dummy.substring(phoneNumberIndex, emailIndex); + emailIndex += 3; + String email = dummy.substring(emailIndex); + return new AddDoctorCommand(id, name, phoneNumber, email, false); + } catch (Exception e) { + System.out.println("The input format of the doctor information is wrong."); + } - String email = dummy.substring(emailIndex); - - return new AddDoctorCommand(id, name, phoneNumber, email, false); } else if (fullCommand.contains("add patient")) { String id; String dummy = fullCommand.trim(); - int idIndex = dummy.indexOf("/id") + 4; - int nameIndex = dummy.indexOf("/n"); - id = dummy.substring(idIndex, nameIndex); - - nameIndex += 3; - - int phoneNumberIndex = dummy.indexOf("/ph"); - - String name = dummy.substring(nameIndex, phoneNumberIndex); - - phoneNumberIndex += 4; + try { + int idIndex = dummy.indexOf("/id") + 4; + int nameIndex = dummy.indexOf("/n"); + id = dummy.substring(idIndex, nameIndex); + nameIndex += 3; + int phoneNumberIndex = dummy.indexOf("/ph"); + String name = dummy.substring(nameIndex, phoneNumberIndex); + phoneNumberIndex += 4; + int emailIndex = dummy.indexOf("/e"); + String phoneNumber = dummy.substring(phoneNumberIndex, emailIndex); + emailIndex += 3; + String email = dummy.substring(emailIndex); + return new AddPatientCommand(id, name, phoneNumber, email); + } catch (Exception e) { + System.out.println("The input format of the patient information is wrong."); + } - int emailIndex = dummy.indexOf("/e"); - String phoneNumber = dummy.substring(phoneNumberIndex, emailIndex); - - emailIndex += 3; - - String email = dummy.substring(emailIndex); - - return new AddPatientCommand(id, name, phoneNumber, email); } else if (fullCommand.contains("add appointment")) { String time; String dummy = fullCommand.trim(); - int timeIndex = dummy.indexOf("/t") + 3; - int doctorIndex = dummy.indexOf("/d"); - time = dummy.substring(timeIndex, doctorIndex).trim(); - int patientIndex = dummy.indexOf("/p"); - String s = dummy.substring(doctorIndex + 3, patientIndex); - - doctorIndex = Integer.parseInt(s.trim()); - patientIndex += 3; - s = dummy.substring(patientIndex); - patientIndex = Integer.parseInt(s.trim()); - return new AddAppointmentCommand(doctorIndex, patientIndex, time); + try { + int timeIndex = dummy.indexOf("/t"); + int doctorIndex = dummy.indexOf("/d"); + time = dummy.substring(timeIndex, doctorIndex); + int patientIndex = dummy.indexOf("/p"); + String s = dummy.substring(doctorIndex, patientIndex); + + doctorIndex = Integer.parseInt(s); + patientIndex += 3; + s = dummy.substring(patientIndex); + patientIndex = Integer.parseInt(s); + return new AddAppointmentCommand(doctorIndex, patientIndex, time); + } catch (Exception e) { + System.out.println("The input format of the appointment information is wrong."); + } } else if (fullCommand.contains("delete doctor")) { String dummy = fullCommand.trim(); int index = Integer.parseInt(dummy.substring(dummy.length() - 1)); @@ -88,11 +92,11 @@ public Command parse(String fullCommand) throws IHospitalException { return new ListAppointmentListCommand(); } else if (fullCommand.contains("list patient")) { return new ListPatientListCommand(); - } else if (fullCommand.contains("bye")) { - return new ExitCommand(); - } + } else + throw new IHospitalException("Invalid command given"); + return null; } +} -} \ No newline at end of file diff --git a/src/main/java/tp/Storage.java b/src/main/java/tp/Storage.java index ff554ad47..78516042d 100644 --- a/src/main/java/tp/Storage.java +++ b/src/main/java/tp/Storage.java @@ -2,4 +2,4 @@ public class Storage { -} +} \ No newline at end of file diff --git a/src/test/tp/AddPatientCommandTest.java b/src/test/tp/AddPatientCommandTest.java deleted file mode 100644 index 77b283894..000000000 --- a/src/test/tp/AddPatientCommandTest.java +++ /dev/null @@ -1,4 +0,0 @@ -import static org.junit.jupiter.api.Assertions.*; -class AddPatientCommandTest { - -} \ No newline at end of file diff --git a/src/test/tp/person/DoctorTest.java b/src/test/tp/person/DoctorTest.java new file mode 100644 index 000000000..ec3f31de7 --- /dev/null +++ b/src/test/tp/person/DoctorTest.java @@ -0,0 +1,15 @@ +package tp.person; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class DoctorTest { + private final Doctor doctor = new Doctor("1234", "john", + "12341234", "3600@gmail.com"); + @Test + void testToString() { + assertEquals("* DOCTOR " + "[1234] || Name: john " + + "|| Contact No.: 12341234 || Email: 3600@gmail.com", doctor.toString()); + } +} \ No newline at end of file diff --git a/src/test/tp/person/PatientTest.java b/src/test/tp/person/PatientTest.java new file mode 100644 index 000000000..542e0cdb9 --- /dev/null +++ b/src/test/tp/person/PatientTest.java @@ -0,0 +1,16 @@ +package tp.person; + +import org.junit.jupiter.api.Test; +import tp.PatientList; + +import static org.junit.jupiter.api.Assertions.*; + +class PatientTest { + private final Patient patient = new Patient("1234", "john", + "12341234", "3600@gmail.com"); + @Test + void testToString() { + assertEquals("* PATIENT " + "[1234] || Name: john " + + "|| Contact No.: 12341234 || Email: 3600@gmail.com", patient.toString()); + } +} \ No newline at end of file diff --git a/src/test/tp/person/PersonTest.java b/src/test/tp/person/PersonTest.java new file mode 100644 index 000000000..a4a059548 --- /dev/null +++ b/src/test/tp/person/PersonTest.java @@ -0,0 +1,36 @@ +package tp.person; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class PersonTest { + private final Person person = new Person("1234", "john", + "12341234", "3600@gmail.com"); + + @Test + void getId() { + assertEquals("1234", person.getId()); + } + + @Test + void getName() { + assertEquals("john", person.getName()); + } + + @Test + void getPhoneNumber() { + assertEquals("12341234", person.getPhoneNumber()); + } + + @Test + void getEmail() { + assertEquals("3600@gmail.com", person.getEmail()); + } + + @Test + void testToString() { + assertEquals("[1234] || Name: john " + + "|| Contact No.: 12341234 || Email: 3600@gmail.com", person.toString()); + } +} \ No newline at end of file