From 0775ed9dec1829b9cd012e580855590944ce01a4 Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Thu, 25 Jan 2024 22:18:39 +0800 Subject: [PATCH 01/28] step one --- src/main/java/Duke.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..8f96a2d97 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,5 @@ public class Duke { public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + System.out.println(""); } } From 8fe89116b3e99127fa7f8929079d69abee075e63 Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Thu, 25 Jan 2024 22:33:19 +0800 Subject: [PATCH 02/28] step one point five --- src/main/java/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 8f96a2d97..a30d68699 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,5 +1,5 @@ public class Duke { public static void main(String[] args) { - System.out.println(""); + System.out.println("Hello"); } } From 318b7c840f6195967d5147496b6188e749e86c7c Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Thu, 25 Jan 2024 22:35:00 +0800 Subject: [PATCH 03/28] test class --- src/main/java/test.java | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/main/java/test.java diff --git a/src/main/java/test.java b/src/main/java/test.java new file mode 100644 index 000000000..53ba7f616 --- /dev/null +++ b/src/main/java/test.java @@ -0,0 +1,2 @@ +public class test { +} From 2928ccdc2dd3ba34d3c5bb04f8b5ef5971a07f9d Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Thu, 25 Jan 2024 22:37:22 +0800 Subject: [PATCH 04/28] deleted test class --- src/main/java/test.java | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 src/main/java/test.java diff --git a/src/main/java/test.java b/src/main/java/test.java deleted file mode 100644 index 53ba7f616..000000000 --- a/src/main/java/test.java +++ /dev/null @@ -1,2 +0,0 @@ -public class test { -} From 0ff2890cf9673fa58a351ff2bd5450cecf06836f Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Thu, 25 Jan 2024 22:42:35 +0800 Subject: [PATCH 05/28] Level 0 --- src/main/java/Duke.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index a30d68699..9463d50e9 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,5 +1,7 @@ public class Duke { public static void main(String[] args) { - System.out.println("Hello"); + System.out.println("Hello! I'm Nocturne!"); + System.out.println("What can I do for you?"); + System.out.println("Bye. Hope to see you again soon!"); } } From 9109f7b9119b96faff23d0fa672b6b5bf109f41f Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Wed, 7 Feb 2024 00:38:23 +0800 Subject: [PATCH 06/28] Level 0 --- src/main/java/Duke.java | 51 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 9463d50e9..c4f942273 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,7 +1,52 @@ +import java.util.Scanner; public class Duke { + private static String[] tasks = new String[100]; + private static int taskCount = 0; + + public static void addTask(String task){ + tasks[taskCount] = task; + taskCount++; + } + + public static void printTasks() { + int originalCount = taskCount; + for (String s: tasks){ + if (taskCount > 0) { + System.out.println(s); + taskCount--; + } else { + break; + } + } + taskCount = originalCount; + } + public static void main(String[] args) { - System.out.println("Hello! I'm Nocturne!"); - System.out.println("What can I do for you?"); - System.out.println("Bye. Hope to see you again soon!"); + String input; + Scanner in = new Scanner(System.in); + + System.out.println("Good evening. I'm Nocturne."); + System.out.println("What ails you on this fine day?"); + input = in.nextLine(); + + while (!input.equals("bye")) { + if (input.equals("enter task mode")) { + System.out.println("Entered task mode."); + while (!input.equals("exit task mode")) { + input = in.nextLine(); + if (input.equals("list")) { + printTasks(); + continue; + } + addTask(input); + System.out.println("added: " + input); + } + System.out.println("Exited task mode."); + } else { + System.out.println(input); + input = in.nextLine(); + } + } + System.out.println("Farewell, and may the fortunes be ever in your favour."); } } From b1b84516670644a20f13d0b46472598a5eabd19b Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Wed, 7 Feb 2024 13:15:46 +0800 Subject: [PATCH 07/28] Level 1 --- src/main/java/Duke.java | 23 +++++++++++++++++++---- src/main/java/Task.java | 23 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index c4f942273..88b4edfae 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,16 +1,17 @@ import java.util.Scanner; + public class Duke { - private static String[] tasks = new String[100]; + private static Task[] tasks = new Task[100]; private static int taskCount = 0; public static void addTask(String task){ - tasks[taskCount] = task; + tasks[taskCount] = new Task(task); taskCount++; } public static void printTasks() { int originalCount = taskCount; - for (String s: tasks){ + for (Task s: tasks){ if (taskCount > 0) { System.out.println(s); taskCount--; @@ -32,16 +33,28 @@ public static void main(String[] args) { while (!input.equals("bye")) { if (input.equals("enter task mode")) { System.out.println("Entered task mode."); - while (!input.equals("exit task mode")) { + while (true) { input = in.nextLine(); + if (input.equals("exit task mode")) { + break; + } if (input.equals("list")) { printTasks(); continue; } + else if (input.startsWith("mark")) { + tasks[Integer.parseInt(input.substring(5))].setDone(true); + continue; + } + if (input.startsWith("unmark")) { + tasks[Integer.parseInt(input.substring(7))].setDone(false); + continue; + } addTask(input); System.out.println("added: " + input); } System.out.println("Exited task mode."); + input = in.nextLine(); } else { System.out.println(input); input = in.nextLine(); @@ -50,3 +63,5 @@ public static void main(String[] args) { System.out.println("Farewell, and may the fortunes be ever in your favour."); } } + + diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..dd2b1ba52 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,23 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String task) { + this.description = task; + isDone = false; + } + + public void setDone(boolean done) { + isDone = done; + } + + public String toString() { + String status = null; + if (isDone){ + status = "[X] "; + } else { + status = "[ ] "; + } + return String.format(status + description); + } +} \ No newline at end of file From 4dbe8ccb6b31d137c0f5d231b13adf3205afc85c Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Thu, 15 Feb 2024 20:05:00 +0800 Subject: [PATCH 08/28] Create chatbot --- src/main/java/Duke.java | 61 +---------------------------------------- 1 file changed, 1 insertion(+), 60 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 88b4edfae..b91347aa6 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,67 +1,8 @@ import java.util.Scanner; - public class Duke { - private static Task[] tasks = new Task[100]; - private static int taskCount = 0; - - public static void addTask(String task){ - tasks[taskCount] = new Task(task); - taskCount++; - } - - public static void printTasks() { - int originalCount = taskCount; - for (Task s: tasks){ - if (taskCount > 0) { - System.out.println(s); - taskCount--; - } else { - break; - } - } - taskCount = originalCount; - } - public static void main(String[] args) { - String input; - Scanner in = new Scanner(System.in); - System.out.println("Good evening. I'm Nocturne."); System.out.println("What ails you on this fine day?"); - input = in.nextLine(); - - while (!input.equals("bye")) { - if (input.equals("enter task mode")) { - System.out.println("Entered task mode."); - while (true) { - input = in.nextLine(); - if (input.equals("exit task mode")) { - break; - } - if (input.equals("list")) { - printTasks(); - continue; - } - else if (input.startsWith("mark")) { - tasks[Integer.parseInt(input.substring(5))].setDone(true); - continue; - } - if (input.startsWith("unmark")) { - tasks[Integer.parseInt(input.substring(7))].setDone(false); - continue; - } - addTask(input); - System.out.println("added: " + input); - } - System.out.println("Exited task mode."); - input = in.nextLine(); - } else { - System.out.println(input); - input = in.nextLine(); - } - } System.out.println("Farewell, and may the fortunes be ever in your favour."); } -} - - +} \ No newline at end of file From a97a39d2b9b3718075aa923e5917b9972dba2d58 Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Thu, 15 Feb 2024 20:23:20 +0800 Subject: [PATCH 09/28] Create Nocturne --- src/main/java/Duke.java | 1 - src/main/java/Task.java | 23 ----------------------- 2 files changed, 24 deletions(-) delete mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index b91347aa6..9f8b242f3 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,4 +1,3 @@ -import java.util.Scanner; public class Duke { public static void main(String[] args) { System.out.println("Good evening. I'm Nocturne."); diff --git a/src/main/java/Task.java b/src/main/java/Task.java deleted file mode 100644 index dd2b1ba52..000000000 --- a/src/main/java/Task.java +++ /dev/null @@ -1,23 +0,0 @@ -public class Task { - protected String description; - protected boolean isDone; - - public Task(String task) { - this.description = task; - isDone = false; - } - - public void setDone(boolean done) { - isDone = done; - } - - public String toString() { - String status = null; - if (isDone){ - status = "[X] "; - } else { - status = "[ ] "; - } - return String.format(status + description); - } -} \ No newline at end of file From 2ac814f377cc8e97f431510214aeb78afee3b74b Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Thu, 15 Feb 2024 20:34:40 +0800 Subject: [PATCH 10/28] Increment Level --- src/main/java/Duke.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 9f8b242f3..4def52e2b 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,7 +1,15 @@ +import java.util.Scanner; public class Duke { public static void main(String[] args) { + String input; + Scanner in = new Scanner(System.in); System.out.println("Good evening. I'm Nocturne."); System.out.println("What ails you on this fine day?"); + input = in.nextLine(); + while (!input.equals("bye")) { + System.out.println(input); + input = in.nextLine(); + } System.out.println("Farewell, and may the fortunes be ever in your favour."); } } \ No newline at end of file From eacad4522b1e0f593487f68e7cc6d5d949d14191 Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Thu, 15 Feb 2024 20:46:38 +0800 Subject: [PATCH 11/28] Increment Level --- src/main/java/Duke.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 4def52e2b..3cde284ab 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,13 +1,27 @@ import java.util.Scanner; public class Duke { public static void main(String[] args) { + String[] list = new String[100]; + + int COUNT = 0; + String input; Scanner in = new Scanner(System.in); System.out.println("Good evening. I'm Nocturne."); System.out.println("What ails you on this fine day?"); + input = in.nextLine(); + while (!input.equals("bye")) { - System.out.println(input); + if (input.equals("list")) { + for (int i = 0; i < COUNT; i++){ + System.out.println((i + 1) + ". " + list[i]); + } + } else { + System.out.println("added: " + input); + list[COUNT] = input; + COUNT++; + } input = in.nextLine(); } System.out.println("Farewell, and may the fortunes be ever in your favour."); From 09a5d4f23afc0656f775b6d82fa7ffb1ba7c6672 Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Thu, 15 Feb 2024 21:14:56 +0800 Subject: [PATCH 12/28] Increment to Level 3 --- src/main/java/Duke.java | 25 ++++++++++++++++++++----- src/main/java/Task.java | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 3cde284ab..1b8dae159 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,8 +1,7 @@ import java.util.Scanner; public class Duke { public static void main(String[] args) { - String[] list = new String[100]; - + Task[] tasks = new Task[100]; int COUNT = 0; String input; @@ -13,13 +12,29 @@ public static void main(String[] args) { input = in.nextLine(); while (!input.equals("bye")) { + String[] commandCheck = input.split(" "); if (input.equals("list")) { for (int i = 0; i < COUNT; i++){ - System.out.println((i + 1) + ". " + list[i]); + System.out.println((i + 1) + ".[" + tasks[i].getStatusIcon() + "] " + tasks[i].getDescription()); } - } else { + } + else if(commandCheck[0].equals("mark")) { + int listIndex = Integer.parseInt(commandCheck[1]); + System.out.println("Nice! I've marked this task as done:"); + System.out.println("[X] " + tasks[listIndex - 1].getDescription()); + tasks[listIndex - 1].isDone = true; + } + + else if(commandCheck[0].equals("unmark")) { + int listIndex = Integer.parseInt(commandCheck[1]); + System.out.println("OK, I've marked this task as not done yet:"); + System.out.println("[ ] " + tasks[listIndex - 1].getDescription()); + tasks[listIndex - 1].isDone = false; + } + + else { System.out.println("added: " + input); - list[COUNT] = input; + tasks[COUNT] = new Task(input); COUNT++; } input = in.nextLine(); diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..7605cf289 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,16 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + public String getDescription() { + return this.description; + } +} \ No newline at end of file From a4717359cb6e35c500e3e592dcbe7d92bd4e725d Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Thu, 15 Feb 2024 21:42:53 +0800 Subject: [PATCH 13/28] Adhering to Coding Standards --- src/main/java/Duke.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 1b8dae159..e96c85442 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,7 +2,7 @@ public class Duke { public static void main(String[] args) { Task[] tasks = new Task[100]; - int COUNT = 0; + int taskCount = 0; String input; Scanner in = new Scanner(System.in); @@ -14,28 +14,28 @@ public static void main(String[] args) { while (!input.equals("bye")) { String[] commandCheck = input.split(" "); if (input.equals("list")) { - for (int i = 0; i < COUNT; i++){ + for (int i = 0; i < taskCount; i++){ System.out.println((i + 1) + ".[" + tasks[i].getStatusIcon() + "] " + tasks[i].getDescription()); } } else if(commandCheck[0].equals("mark")) { int listIndex = Integer.parseInt(commandCheck[1]); - System.out.println("Nice! I've marked this task as done:"); + System.out.println("Congratulations. I have marked this task as finished:"); System.out.println("[X] " + tasks[listIndex - 1].getDescription()); tasks[listIndex - 1].isDone = true; } else if(commandCheck[0].equals("unmark")) { int listIndex = Integer.parseInt(commandCheck[1]); - System.out.println("OK, I've marked this task as not done yet:"); + System.out.println("Do not neglect your duties. I have marked this task as unfinished:"); System.out.println("[ ] " + tasks[listIndex - 1].getDescription()); tasks[listIndex - 1].isDone = false; } else { System.out.println("added: " + input); - tasks[COUNT] = new Task(input); - COUNT++; + tasks[taskCount] = new Task(input); + taskCount++; } input = in.nextLine(); } From 9a83d8bc090e3e743f62cc6aa052e6fbc8bd5e1c Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Thu, 15 Feb 2024 22:44:47 +0800 Subject: [PATCH 14/28] Increment to Level 4 --- src/main/java/Deadline.java | 13 ++++++++++++ src/main/java/Duke.java | 41 +++++++++++++++++++++++++++++++------ src/main/java/Event.java | 15 ++++++++++++++ src/main/java/Todo.java | 11 ++++++++++ 4 files changed, 74 insertions(+), 6 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..aa5b131c7 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,13 @@ +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.getStatusIcon() + "] " + this.description + "(by: " + by + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e96c85442..3b9a0bda9 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -15,27 +15,56 @@ public static void main(String[] args) { String[] commandCheck = input.split(" "); if (input.equals("list")) { for (int i = 0; i < taskCount; i++){ - System.out.println((i + 1) + ".[" + tasks[i].getStatusIcon() + "] " + tasks[i].getDescription()); + System.out.println((i + 1) + "." + tasks[i]); } } else if(commandCheck[0].equals("mark")) { int listIndex = Integer.parseInt(commandCheck[1]); System.out.println("Congratulations. I have marked this task as finished:"); - System.out.println("[X] " + tasks[listIndex - 1].getDescription()); tasks[listIndex - 1].isDone = true; + System.out.println(" " + tasks[listIndex - 1]); } else if(commandCheck[0].equals("unmark")) { int listIndex = Integer.parseInt(commandCheck[1]); System.out.println("Do not neglect your duties. I have marked this task as unfinished:"); - System.out.println("[ ] " + tasks[listIndex - 1].getDescription()); tasks[listIndex - 1].isDone = false; + System.out.println(" " + tasks[listIndex - 1]); } - else { - System.out.println("added: " + input); - tasks[taskCount] = new Task(input); + else if(commandCheck[0].equals("deadline")) { + String[] deadlineSeparated = input.split("/"); + Deadline trueDeadline; + String deadlineName = deadlineSeparated[0].substring(9); + String by = deadlineSeparated[1].substring(3); + trueDeadline = new Deadline(deadlineName, by); + tasks[taskCount] = trueDeadline; taskCount++; + System.out.println("A deadline I see. I have added it:"); + System.out.println(" " + trueDeadline); + } + + else if(commandCheck[0].equals("todo")) { + String todoName = input.substring(5); + Todo trueTodo = new Todo(todoName); + tasks[taskCount] = trueTodo; + taskCount++; + System.out.println("A Todo task I see. I have added it:"); + System.out.println(" " + trueTodo); + } + + else if(commandCheck[0].equals("event")) { + String[] eventSeparated = input.split("/"); + Event trueEvent; + String eventName = eventSeparated[0].substring(6); + String from = eventSeparated[1].trim(); + from = from.substring(5); + String to = eventSeparated[2].substring(3); + trueEvent = new Event(eventName, from, to); + tasks[taskCount] = trueEvent; + taskCount++; + System.out.println("An event I see. I have added it:"); + System.out.println(" " + trueEvent); } input = in.nextLine(); } diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..fd7279149 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,15 @@ +public class Event extends Task{ + protected String from; + protected String to; + + public Event(String name, String from, String to){ + super(name); + this.from = from; + this.to = to; + } + + @Override + public String toString(){ + return "[E]" + "[" + super.getStatusIcon() + "] " + this.description + "(from: " + from + " " + "to: " + to + ")"; + } +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..beec61896 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,11 @@ +public class Todo extends Task { + public Todo(String description){ + super(description); + isDone = false; + } + + @Override + public String toString() { + return "[T]" + "[" + super.getStatusIcon() + "] " + description; + } +} \ No newline at end of file From e112fa9b63d33a00af75db622c631199b9055e8b Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Thu, 15 Feb 2024 23:02:41 +0800 Subject: [PATCH 15/28] Coding Quality Update --- src/main/java/Duke.java | 101 +++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 3b9a0bda9..9bde29673 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,4 +1,5 @@ import java.util.Scanner; + public class Duke { public static void main(String[] args) { Task[] tasks = new Task[100]; @@ -13,58 +14,60 @@ public static void main(String[] args) { while (!input.equals("bye")) { String[] commandCheck = input.split(" "); - if (input.equals("list")) { - for (int i = 0; i < taskCount; i++){ - System.out.println((i + 1) + "." + tasks[i]); - } - } - else if(commandCheck[0].equals("mark")) { - int listIndex = Integer.parseInt(commandCheck[1]); - System.out.println("Congratulations. I have marked this task as finished:"); - tasks[listIndex - 1].isDone = true; - System.out.println(" " + tasks[listIndex - 1]); - } - - else if(commandCheck[0].equals("unmark")) { - int listIndex = Integer.parseInt(commandCheck[1]); - System.out.println("Do not neglect your duties. I have marked this task as unfinished:"); - tasks[listIndex - 1].isDone = false; - System.out.println(" " + tasks[listIndex - 1]); - } + switch (commandCheck[0]) { + case "list": + for (int i = 0; i < taskCount; i++) { + System.out.println((i + 1) + "." + tasks[i]); + } + break; - else if(commandCheck[0].equals("deadline")) { - String[] deadlineSeparated = input.split("/"); - Deadline trueDeadline; - String deadlineName = deadlineSeparated[0].substring(9); - String by = deadlineSeparated[1].substring(3); - trueDeadline = new Deadline(deadlineName, by); - tasks[taskCount] = trueDeadline; - taskCount++; - System.out.println("A deadline I see. I have added it:"); - System.out.println(" " + trueDeadline); - } + case "mark": { + int listIndex = Integer.parseInt(commandCheck[1]); + System.out.println("Congratulations. I have marked this task as finished:"); + tasks[listIndex - 1].isDone = true; + System.out.println(" " + tasks[listIndex - 1]); + break; + } + case "unmark": { + int listIndex = Integer.parseInt(commandCheck[1]); + System.out.println("Do not neglect your duties. I have marked this task as unfinished:"); + tasks[listIndex - 1].isDone = false; + System.out.println(" " + tasks[listIndex - 1]); + break; + } + case "deadline": + String[] deadlineSeparated = input.split("/"); + Deadline trueDeadline; + String deadlineName = deadlineSeparated[0].substring(9); + String by = deadlineSeparated[1].substring(3); + trueDeadline = new Deadline(deadlineName, by); + tasks[taskCount] = trueDeadline; + taskCount++; + System.out.println("A deadline I see. I have added it:"); + System.out.println(" " + trueDeadline); + break; - else if(commandCheck[0].equals("todo")) { - String todoName = input.substring(5); - Todo trueTodo = new Todo(todoName); - tasks[taskCount] = trueTodo; - taskCount++; - System.out.println("A Todo task I see. I have added it:"); - System.out.println(" " + trueTodo); - } + case "todo": + String todoName = input.substring(5); + Todo trueTodo = new Todo(todoName); + tasks[taskCount] = trueTodo; + taskCount++; + System.out.println("A Todo task I see. I have added it:"); + System.out.println(" " + trueTodo); + break; - else if(commandCheck[0].equals("event")) { - String[] eventSeparated = input.split("/"); - Event trueEvent; - String eventName = eventSeparated[0].substring(6); - String from = eventSeparated[1].trim(); - from = from.substring(5); - String to = eventSeparated[2].substring(3); - trueEvent = new Event(eventName, from, to); - tasks[taskCount] = trueEvent; - taskCount++; - System.out.println("An event I see. I have added it:"); - System.out.println(" " + trueEvent); + case "event": + String[] eventSeparated = input.split("/"); + Event trueEvent; + String eventName = eventSeparated[0].substring(6); + String from = eventSeparated[1].trim(); + from = from.substring(5); + String to = eventSeparated[2].substring(3); + trueEvent = new Event(eventName, from, to); + tasks[taskCount] = trueEvent; + taskCount++; + System.out.println("An event I see. I have added it:"); + System.out.println(" " + trueEvent); } input = in.nextLine(); } From dcdc7f7ae3525072e81662a61b62712b131f76b2 Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Thu, 15 Feb 2024 23:55:19 +0800 Subject: [PATCH 16/28] Increment to Level-5 --- src/main/java/{Duke.java => Nocturne.java} | 14 ++++++++++---- src/main/java/NocturneException.java | 5 +++++ 2 files changed, 15 insertions(+), 4 deletions(-) rename src/main/java/{Duke.java => Nocturne.java} (89%) create mode 100644 src/main/java/NocturneException.java diff --git a/src/main/java/Duke.java b/src/main/java/Nocturne.java similarity index 89% rename from src/main/java/Duke.java rename to src/main/java/Nocturne.java index 9bde29673..31e7a9432 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Nocturne.java @@ -1,7 +1,7 @@ import java.util.Scanner; -public class Duke { - public static void main(String[] args) { +public class Nocturne { + public static void main(String[] args) throws NocturneException { Task[] tasks = new Task[100]; int taskCount = 0; @@ -11,11 +11,13 @@ public static void main(String[] args) { System.out.println("What ails you on this fine day?"); input = in.nextLine(); - while (!input.equals("bye")) { String[] commandCheck = input.split(" "); switch (commandCheck[0]) { case "list": + if (taskCount == 0) { + throw new NocturneException("An empty list begets an empty mind."); + } for (int i = 0; i < taskCount; i++) { System.out.println((i + 1) + "." + tasks[i]); } @@ -68,9 +70,13 @@ public static void main(String[] args) { taskCount++; System.out.println("An event I see. I have added it:"); System.out.println(" " + trueEvent); + break; + + default: + throw new NocturneException("Your command is invalid. Try again."); } input = in.nextLine(); } System.out.println("Farewell, and may the fortunes be ever in your favour."); } -} \ No newline at end of file +} diff --git a/src/main/java/NocturneException.java b/src/main/java/NocturneException.java new file mode 100644 index 000000000..9c7595934 --- /dev/null +++ b/src/main/java/NocturneException.java @@ -0,0 +1,5 @@ +public class NocturneException extends Exception { + public NocturneException(String s) { + super(s); + } +} From bb8a3e6677b3e10eece45c24dce39d3433c59ab9 Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Fri, 16 Feb 2024 00:01:21 +0800 Subject: [PATCH 17/28] Added an exception class, NocturneException --- src/main/java/Nocturne.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/Nocturne.java b/src/main/java/Nocturne.java index 31e7a9432..1c1767af5 100644 --- a/src/main/java/Nocturne.java +++ b/src/main/java/Nocturne.java @@ -24,6 +24,9 @@ public static void main(String[] args) throws NocturneException { break; case "mark": { + if (commandCheck.length < 2 | commandCheck.length > taskCount + 1) { + throw new NocturneException("Your list is either empty or your brain is."); + } int listIndex = Integer.parseInt(commandCheck[1]); System.out.println("Congratulations. I have marked this task as finished:"); tasks[listIndex - 1].isDone = true; @@ -31,6 +34,9 @@ public static void main(String[] args) throws NocturneException { break; } case "unmark": { + if (commandCheck.length < 2 | commandCheck.length > taskCount + 1) { + throw new NocturneException("Your list is either empty or your brain is."); + } int listIndex = Integer.parseInt(commandCheck[1]); System.out.println("Do not neglect your duties. I have marked this task as unfinished:"); tasks[listIndex - 1].isDone = false; From bf6f1e3efb159171735248aa5ebe3b606ce8f18a Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Fri, 16 Feb 2024 00:10:06 +0800 Subject: [PATCH 18/28] Increment to Level 5, and added NocturneException Class --- src/main/java/Nocturne.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/Nocturne.java b/src/main/java/Nocturne.java index 1c1767af5..38bdfe4e5 100644 --- a/src/main/java/Nocturne.java +++ b/src/main/java/Nocturne.java @@ -45,6 +45,9 @@ public static void main(String[] args) throws NocturneException { } case "deadline": String[] deadlineSeparated = input.split("/"); + if (deadlineSeparated.length != 3) { + throw new NocturneException("Take your / back, and only put 2!"); + } Deadline trueDeadline; String deadlineName = deadlineSeparated[0].substring(9); String by = deadlineSeparated[1].substring(3); @@ -66,6 +69,9 @@ public static void main(String[] args) throws NocturneException { case "event": String[] eventSeparated = input.split("/"); + if (eventSeparated.length != 3) { + throw new NocturneException("Take your / back, and only put 2!"); + } Event trueEvent; String eventName = eventSeparated[0].substring(6); String from = eventSeparated[1].trim(); From d3102fb0b1ee7a16da5d7e0baba86580ba38582f Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Fri, 16 Feb 2024 00:12:45 +0800 Subject: [PATCH 19/28] Already added NocturneException, so committing an extra to tag as A-Exception --- src/main/java/Nocturne.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Nocturne.java b/src/main/java/Nocturne.java index 38bdfe4e5..92bf57235 100644 --- a/src/main/java/Nocturne.java +++ b/src/main/java/Nocturne.java @@ -67,6 +67,7 @@ public static void main(String[] args) throws NocturneException { System.out.println(" " + trueTodo); break; + case "event": String[] eventSeparated = input.split("/"); if (eventSeparated.length != 3) { From 5fd17b865bba639d31f56e6b166f8abb9a40728b Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Fri, 16 Feb 2024 00:15:52 +0800 Subject: [PATCH 20/28] Added extra exceptions --- src/main/java/Nocturne.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/Nocturne.java b/src/main/java/Nocturne.java index 92bf57235..38bdfe4e5 100644 --- a/src/main/java/Nocturne.java +++ b/src/main/java/Nocturne.java @@ -67,7 +67,6 @@ public static void main(String[] args) throws NocturneException { System.out.println(" " + trueTodo); break; - case "event": String[] eventSeparated = input.split("/"); if (eventSeparated.length != 3) { From 5e7eae384e8c3f806e9fafe950a6406f613315e0 Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Wed, 21 Feb 2024 13:27:38 +0800 Subject: [PATCH 21/28] Minor adjustment --- src/main/java/Nocturne.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/Nocturne.java b/src/main/java/Nocturne.java index 38bdfe4e5..4b5782755 100644 --- a/src/main/java/Nocturne.java +++ b/src/main/java/Nocturne.java @@ -45,9 +45,6 @@ public static void main(String[] args) throws NocturneException { } case "deadline": String[] deadlineSeparated = input.split("/"); - if (deadlineSeparated.length != 3) { - throw new NocturneException("Take your / back, and only put 2!"); - } Deadline trueDeadline; String deadlineName = deadlineSeparated[0].substring(9); String by = deadlineSeparated[1].substring(3); From 8b28a8074ae29531c56353489a598df5b3dffe76 Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Fri, 8 Mar 2024 21:14:46 +0800 Subject: [PATCH 22/28] Refactored and Incremented to Level 6 --- src/main/java/Nocturne.java | 88 ++----------------- .../{ => exceptions}/NocturneException.java | 2 + src/main/java/{ => tasks}/Deadline.java | 4 +- src/main/java/{ => tasks}/Event.java | 4 +- src/main/java/{ => tasks}/Task.java | 12 ++- src/main/java/{ => tasks}/Todo.java | 2 + src/main/java/util/Parser.java | 67 ++++++++++++++ src/main/java/util/TaskList.java | 62 +++++++++++++ 8 files changed, 155 insertions(+), 86 deletions(-) rename src/main/java/{ => exceptions}/NocturneException.java (84%) rename src/main/java/{ => tasks}/Deadline.java (84%) rename src/main/java/{ => tasks}/Event.java (81%) rename src/main/java/{ => tasks}/Task.java (62%) rename src/main/java/{ => tasks}/Todo.java (94%) create mode 100644 src/main/java/util/Parser.java create mode 100644 src/main/java/util/TaskList.java diff --git a/src/main/java/Nocturne.java b/src/main/java/Nocturne.java index 4b5782755..fb8ff450f 100644 --- a/src/main/java/Nocturne.java +++ b/src/main/java/Nocturne.java @@ -1,91 +1,13 @@ -import java.util.Scanner; +import exceptions.NocturneException; +import util.Parser; +import util.TaskList; public class Nocturne { public static void main(String[] args) throws NocturneException { - Task[] tasks = new Task[100]; - int taskCount = 0; - - String input; - Scanner in = new Scanner(System.in); + TaskList list = new TaskList(); System.out.println("Good evening. I'm Nocturne."); System.out.println("What ails you on this fine day?"); - - input = in.nextLine(); - while (!input.equals("bye")) { - String[] commandCheck = input.split(" "); - switch (commandCheck[0]) { - case "list": - if (taskCount == 0) { - throw new NocturneException("An empty list begets an empty mind."); - } - for (int i = 0; i < taskCount; i++) { - System.out.println((i + 1) + "." + tasks[i]); - } - break; - - case "mark": { - if (commandCheck.length < 2 | commandCheck.length > taskCount + 1) { - throw new NocturneException("Your list is either empty or your brain is."); - } - int listIndex = Integer.parseInt(commandCheck[1]); - System.out.println("Congratulations. I have marked this task as finished:"); - tasks[listIndex - 1].isDone = true; - System.out.println(" " + tasks[listIndex - 1]); - break; - } - case "unmark": { - if (commandCheck.length < 2 | commandCheck.length > taskCount + 1) { - throw new NocturneException("Your list is either empty or your brain is."); - } - int listIndex = Integer.parseInt(commandCheck[1]); - System.out.println("Do not neglect your duties. I have marked this task as unfinished:"); - tasks[listIndex - 1].isDone = false; - System.out.println(" " + tasks[listIndex - 1]); - break; - } - case "deadline": - String[] deadlineSeparated = input.split("/"); - Deadline trueDeadline; - String deadlineName = deadlineSeparated[0].substring(9); - String by = deadlineSeparated[1].substring(3); - trueDeadline = new Deadline(deadlineName, by); - tasks[taskCount] = trueDeadline; - taskCount++; - System.out.println("A deadline I see. I have added it:"); - System.out.println(" " + trueDeadline); - break; - - case "todo": - String todoName = input.substring(5); - Todo trueTodo = new Todo(todoName); - tasks[taskCount] = trueTodo; - taskCount++; - System.out.println("A Todo task I see. I have added it:"); - System.out.println(" " + trueTodo); - break; - - case "event": - String[] eventSeparated = input.split("/"); - if (eventSeparated.length != 3) { - throw new NocturneException("Take your / back, and only put 2!"); - } - Event trueEvent; - String eventName = eventSeparated[0].substring(6); - String from = eventSeparated[1].trim(); - from = from.substring(5); - String to = eventSeparated[2].substring(3); - trueEvent = new Event(eventName, from, to); - tasks[taskCount] = trueEvent; - taskCount++; - System.out.println("An event I see. I have added it:"); - System.out.println(" " + trueEvent); - break; - - default: - throw new NocturneException("Your command is invalid. Try again."); - } - input = in.nextLine(); - } + Parser.getInput(list); System.out.println("Farewell, and may the fortunes be ever in your favour."); } } diff --git a/src/main/java/NocturneException.java b/src/main/java/exceptions/NocturneException.java similarity index 84% rename from src/main/java/NocturneException.java rename to src/main/java/exceptions/NocturneException.java index 9c7595934..df6a10730 100644 --- a/src/main/java/NocturneException.java +++ b/src/main/java/exceptions/NocturneException.java @@ -1,3 +1,5 @@ +package exceptions; + public class NocturneException extends Exception { public NocturneException(String s) { super(s); diff --git a/src/main/java/Deadline.java b/src/main/java/tasks/Deadline.java similarity index 84% rename from src/main/java/Deadline.java rename to src/main/java/tasks/Deadline.java index aa5b131c7..8211a46fc 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/tasks/Deadline.java @@ -1,3 +1,5 @@ +package tasks; + public class Deadline extends Task { protected String by; @@ -8,6 +10,6 @@ public Deadline(String description, String by) { @Override public String toString() { - return "[D]" + "[" + super.getStatusIcon() + "] " + this.description + "(by: " + by + ")"; + return "[D]" + "[" + super.getStatusIcon() + "] " + this.description + " (by: " + by + ")"; } } \ No newline at end of file diff --git a/src/main/java/Event.java b/src/main/java/tasks/Event.java similarity index 81% rename from src/main/java/Event.java rename to src/main/java/tasks/Event.java index fd7279149..7616f830f 100644 --- a/src/main/java/Event.java +++ b/src/main/java/tasks/Event.java @@ -1,3 +1,5 @@ +package tasks; + public class Event extends Task{ protected String from; protected String to; @@ -10,6 +12,6 @@ public Event(String name, String from, String to){ @Override public String toString(){ - return "[E]" + "[" + super.getStatusIcon() + "] " + this.description + "(from: " + from + " " + "to: " + to + ")"; + return "[E]" + "[" + super.getStatusIcon() + "] " + this.description + " (from: " + from + " " + "to: " + to + ")"; } } diff --git a/src/main/java/Task.java b/src/main/java/tasks/Task.java similarity index 62% rename from src/main/java/Task.java rename to src/main/java/tasks/Task.java index 7605cf289..093dc3e69 100644 --- a/src/main/java/Task.java +++ b/src/main/java/tasks/Task.java @@ -1,3 +1,5 @@ +package tasks; + public class Task { protected String description; protected boolean isDone; @@ -8,7 +10,15 @@ public Task(String description) { } public String getStatusIcon() { - return (isDone ? "X" : " "); // mark done task with X + return (isDone ? "X" : " "); + } + + public void markAsDone() { + this.isDone = true; + } + + public void markAsUndone() { + this.isDone = false; } public String getDescription() { return this.description; diff --git a/src/main/java/Todo.java b/src/main/java/tasks/Todo.java similarity index 94% rename from src/main/java/Todo.java rename to src/main/java/tasks/Todo.java index beec61896..e85a02a26 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/tasks/Todo.java @@ -1,3 +1,5 @@ +package tasks; + public class Todo extends Task { public Todo(String description){ super(description); diff --git a/src/main/java/util/Parser.java b/src/main/java/util/Parser.java new file mode 100644 index 000000000..130d1bfe5 --- /dev/null +++ b/src/main/java/util/Parser.java @@ -0,0 +1,67 @@ +package util; + +import tasks.Deadline; +import tasks.Event; +import tasks.Todo; + +import java.util.Scanner; + +public class Parser { + public static String getCommand(String input) { + return input.split(" ")[0].toLowerCase(); + } + + public static String getTask(String input) { + String[] splitInput = input.split(" ", 2); + return splitInput.length > 1 ? splitInput[1] : ""; + } + + private static void getResponse(String input, TaskList tasks) { + String command = getCommand(input); + String task = getTask(input); + try { + switch (command) { + case "list": + tasks.listTasks(); + break; + case "mark": + tasks.markTask(Integer.parseInt(task)); + break; + case "unmark": + tasks.unmarkTask(Integer.parseInt(task)); + break; + case "todo": + tasks.addTask(new Todo(task.trim())); + break; + case "deadline": + String[] deadlineSplit = task.split("/"); + tasks.addTask(new Deadline(deadlineSplit[0].trim(), + deadlineSplit[1].substring(3).trim())); + break; + case "event": + String[] eventSplit = task.split("/"); + tasks.addTask(new Event(eventSplit[0].trim(), + eventSplit[1].substring(5).trim(), + eventSplit[2].substring(3).trim())); + break; + case "delete": + tasks.deleteTask(Integer.parseInt(task)); + break; + default: + System.out.println("Your command is invalid, invalid. Try again."); + } + } catch (IndexOutOfBoundsException e) { + System.out.println("You are missing a /. Do not let this happen again."); + } + + } + + public static void getInput(TaskList tasks) { + Scanner in = new Scanner(System.in); + String line = in.nextLine(); + while (!line.equals("bye")) { + getResponse(line, tasks); + line = in.nextLine(); + } + } +} \ No newline at end of file diff --git a/src/main/java/util/TaskList.java b/src/main/java/util/TaskList.java new file mode 100644 index 000000000..276c1dbf5 --- /dev/null +++ b/src/main/java/util/TaskList.java @@ -0,0 +1,62 @@ +package util; + +import tasks.Task; + +import java.util.ArrayList; + +public class TaskList { + protected ArrayList tasks = new ArrayList<>(); + + public TaskList() { + } + + public void addTask (Task task) { + System.out.println("A task I see. I have added it."); + System.out.println(" " + task); + tasks.add(task); + } + + public void deleteTask(int index) { + try { + System.out.println("Should all acquaintance be forgot..." ); + System.out.println(" " + tasks.get(index - 1)); + tasks.remove(index - 1); + System.out.println(tasks.size() + " task(s) remain."); + } catch (IndexOutOfBoundsException e) { + System.out.println("You are trying to access forbidden territory. Tread carefully."); + } + + } + + public void listTasks () { + if (tasks.isEmpty()) { + System.out.println("Your list is empty. Try again, when you have become more productive."); + } + for (int i = 0; i < tasks.size(); i++) { + System.out.print((i + 1) + "."); + System.out.println(tasks.get(i)); + } + } + + public void markTask (int index) { + try { + tasks.get(index - 1).markAsDone(); + System.out.println("Congratulations. I have marked this task as finished:"); + System.out.println(" " + tasks.get(index - 1)); + } catch (IndexOutOfBoundsException e) { + System.out.println("You are trying to access forbidden territory. Tread carefully."); + } + + } + + public void unmarkTask (int index) { + try { + tasks.get(index - 1).markAsUndone(); + System.out.println("Do not neglect your duties. I have marked this task as unfinished:"); + System.out.println(" " + tasks.get(index - 1)); + } catch (IndexOutOfBoundsException e) { + System.out.println("You are trying to access forbidden territory. Tread carefully."); + + } + } +} \ No newline at end of file From 99801a2d09bb178d4f2b43e9f76a432ad278525b Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Sat, 9 Mar 2024 02:08:08 +0800 Subject: [PATCH 23/28] Increment to Level 7 --- data/nocturne.txt | 3 + src/main/java/Deadline.java | 13 --- src/main/java/Event.java | 15 --- src/main/java/Nocturne.java | 95 ++----------------- src/main/java/Todo.java | 11 --- .../{ => exceptions}/NocturneException.java | 2 + src/main/java/tasks/Deadline.java | 22 +++++ src/main/java/tasks/Event.java | 30 ++++++ src/main/java/{ => tasks}/Task.java | 15 ++- src/main/java/tasks/Todo.java | 17 ++++ src/main/java/util/Parser.java | 71 ++++++++++++++ src/main/java/util/Storage.java | 72 ++++++++++++++ src/main/java/util/TaskList.java | 88 +++++++++++++++++ src/main/java/util/Ui.java | 31 ++++++ 14 files changed, 359 insertions(+), 126 deletions(-) create mode 100644 data/nocturne.txt delete mode 100644 src/main/java/Deadline.java delete mode 100644 src/main/java/Event.java delete mode 100644 src/main/java/Todo.java rename src/main/java/{ => exceptions}/NocturneException.java (84%) create mode 100644 src/main/java/tasks/Deadline.java create mode 100644 src/main/java/tasks/Event.java rename src/main/java/{ => tasks}/Task.java (62%) create mode 100644 src/main/java/tasks/Todo.java create mode 100644 src/main/java/util/Parser.java create mode 100644 src/main/java/util/Storage.java create mode 100644 src/main/java/util/TaskList.java create mode 100644 src/main/java/util/Ui.java diff --git a/data/nocturne.txt b/data/nocturne.txt new file mode 100644 index 000000000..cbaba7e42 --- /dev/null +++ b/data/nocturne.txt @@ -0,0 +1,3 @@ +[E][ ] delimit (from: 2pm to: 4pm) +[D][X] finish cs2113t (by: 2359) +[T][X] help diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java deleted file mode 100644 index aa5b131c7..000000000 --- a/src/main/java/Deadline.java +++ /dev/null @@ -1,13 +0,0 @@ -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.getStatusIcon() + "] " + this.description + "(by: " + by + ")"; - } -} \ No newline at end of file diff --git a/src/main/java/Event.java b/src/main/java/Event.java deleted file mode 100644 index fd7279149..000000000 --- a/src/main/java/Event.java +++ /dev/null @@ -1,15 +0,0 @@ -public class Event extends Task{ - protected String from; - protected String to; - - public Event(String name, String from, String to){ - super(name); - this.from = from; - this.to = to; - } - - @Override - public String toString(){ - return "[E]" + "[" + super.getStatusIcon() + "] " + this.description + "(from: " + from + " " + "to: " + to + ")"; - } -} diff --git a/src/main/java/Nocturne.java b/src/main/java/Nocturne.java index 1c1767af5..251ee9df6 100644 --- a/src/main/java/Nocturne.java +++ b/src/main/java/Nocturne.java @@ -1,88 +1,13 @@ -import java.util.Scanner; +import exceptions.NocturneException; +import util.Parser; +import util.TaskList; +import util.Ui; public class Nocturne { - public static void main(String[] args) throws NocturneException { - Task[] tasks = new Task[100]; - int taskCount = 0; - - String input; - Scanner in = new Scanner(System.in); - System.out.println("Good evening. I'm Nocturne."); - System.out.println("What ails you on this fine day?"); - - input = in.nextLine(); - while (!input.equals("bye")) { - String[] commandCheck = input.split(" "); - switch (commandCheck[0]) { - case "list": - if (taskCount == 0) { - throw new NocturneException("An empty list begets an empty mind."); - } - for (int i = 0; i < taskCount; i++) { - System.out.println((i + 1) + "." + tasks[i]); - } - break; - - case "mark": { - if (commandCheck.length < 2 | commandCheck.length > taskCount + 1) { - throw new NocturneException("Your list is either empty or your brain is."); - } - int listIndex = Integer.parseInt(commandCheck[1]); - System.out.println("Congratulations. I have marked this task as finished:"); - tasks[listIndex - 1].isDone = true; - System.out.println(" " + tasks[listIndex - 1]); - break; - } - case "unmark": { - if (commandCheck.length < 2 | commandCheck.length > taskCount + 1) { - throw new NocturneException("Your list is either empty or your brain is."); - } - int listIndex = Integer.parseInt(commandCheck[1]); - System.out.println("Do not neglect your duties. I have marked this task as unfinished:"); - tasks[listIndex - 1].isDone = false; - System.out.println(" " + tasks[listIndex - 1]); - break; - } - case "deadline": - String[] deadlineSeparated = input.split("/"); - Deadline trueDeadline; - String deadlineName = deadlineSeparated[0].substring(9); - String by = deadlineSeparated[1].substring(3); - trueDeadline = new Deadline(deadlineName, by); - tasks[taskCount] = trueDeadline; - taskCount++; - System.out.println("A deadline I see. I have added it:"); - System.out.println(" " + trueDeadline); - break; - - case "todo": - String todoName = input.substring(5); - Todo trueTodo = new Todo(todoName); - tasks[taskCount] = trueTodo; - taskCount++; - System.out.println("A Todo task I see. I have added it:"); - System.out.println(" " + trueTodo); - break; - - case "event": - String[] eventSeparated = input.split("/"); - Event trueEvent; - String eventName = eventSeparated[0].substring(6); - String from = eventSeparated[1].trim(); - from = from.substring(5); - String to = eventSeparated[2].substring(3); - trueEvent = new Event(eventName, from, to); - tasks[taskCount] = trueEvent; - taskCount++; - System.out.println("An event I see. I have added it:"); - System.out.println(" " + trueEvent); - break; - - default: - throw new NocturneException("Your command is invalid. Try again."); - } - input = in.nextLine(); - } - System.out.println("Farewell, and may the fortunes be ever in your favour."); + public static void main(String[] args) { + TaskList list = new TaskList(); + Ui.greetingMessage(); + Parser.getInput(list); + Ui.farewellMessage(); } -} +} \ No newline at end of file diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java deleted file mode 100644 index beec61896..000000000 --- a/src/main/java/Todo.java +++ /dev/null @@ -1,11 +0,0 @@ -public class Todo extends Task { - public Todo(String description){ - super(description); - isDone = false; - } - - @Override - public String toString() { - return "[T]" + "[" + super.getStatusIcon() + "] " + description; - } -} \ No newline at end of file diff --git a/src/main/java/NocturneException.java b/src/main/java/exceptions/NocturneException.java similarity index 84% rename from src/main/java/NocturneException.java rename to src/main/java/exceptions/NocturneException.java index 9c7595934..df6a10730 100644 --- a/src/main/java/NocturneException.java +++ b/src/main/java/exceptions/NocturneException.java @@ -1,3 +1,5 @@ +package exceptions; + public class NocturneException extends Exception { public NocturneException(String s) { super(s); diff --git a/src/main/java/tasks/Deadline.java b/src/main/java/tasks/Deadline.java new file mode 100644 index 000000000..cfcbf728c --- /dev/null +++ b/src/main/java/tasks/Deadline.java @@ -0,0 +1,22 @@ +package tasks; + +public class Deadline extends Task { + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + public Deadline(String description, String by, boolean isDone) { + super(description); + this.by = by; + this.isDone = isDone; + } + + public String toString() { + return "[D][" + super.getStatusIcon() + + "] " + this.description + + " (by: " + this.by + ")"; + } +} diff --git a/src/main/java/tasks/Event.java b/src/main/java/tasks/Event.java new file mode 100644 index 000000000..c954dc4cf --- /dev/null +++ b/src/main/java/tasks/Event.java @@ -0,0 +1,30 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package tasks; + +public class Event extends Task { + protected String from; + protected String to; + + public Event(String description, String from, String to) { + super(description); + this.from = from; + this.to = to; + } + + public Event(String description, String from, String to, boolean isDone) { + super(description); + this.from = from; + this.to = to; + this.isDone = isDone; + } + + public String toString() { + return "[E][" + super.getStatusIcon() + + "] " + this.description + + " (from: " + this.from + " to: " + this.to + ")"; + } +} diff --git a/src/main/java/Task.java b/src/main/java/tasks/Task.java similarity index 62% rename from src/main/java/Task.java rename to src/main/java/tasks/Task.java index 7605cf289..831e2add3 100644 --- a/src/main/java/Task.java +++ b/src/main/java/tasks/Task.java @@ -1,3 +1,5 @@ +package tasks; + public class Task { protected String description; protected boolean isDone; @@ -8,9 +10,18 @@ public Task(String description) { } public String getStatusIcon() { - return (isDone ? "X" : " "); // mark done task with X + return this.isDone ? "X" : " "; + } + + public void markAsDone() { + this.isDone = true; } + + public void markAsUndone() { + this.isDone = false; + } + public String getDescription() { return this.description; } -} \ No newline at end of file +} diff --git a/src/main/java/tasks/Todo.java b/src/main/java/tasks/Todo.java new file mode 100644 index 000000000..bb9097fe5 --- /dev/null +++ b/src/main/java/tasks/Todo.java @@ -0,0 +1,17 @@ +package tasks; + +public class Todo extends Task { + public Todo(String description) { + super(description); + this.isDone = false; + } + + public Todo(String description, boolean isDone) { + super(description); + this.isDone = isDone; + } + + public String toString() { + return "[T][" + super.getStatusIcon() + "] " + this.description; + } +} \ No newline at end of file diff --git a/src/main/java/util/Parser.java b/src/main/java/util/Parser.java new file mode 100644 index 000000000..e02c042c6 --- /dev/null +++ b/src/main/java/util/Parser.java @@ -0,0 +1,71 @@ +package util; + +import java.util.Scanner; +import tasks.Deadline; +import tasks.Event; +import tasks.Todo; + +public class Parser { + public Parser() { + } + + public static String getCommand(String input) { + return input.split(" ")[0].toLowerCase(); + } + + public static String getTask(String input) { + String[] splitInput = input.split(" ", 2); + return splitInput.length > 1 ? splitInput[1] : ""; + } + + private static void getResponse(String input, TaskList tasks) { + String command = getCommand(input); + String task = getTask(input); + try { + switch (command) { + case "list": + tasks.listTasks(); + break; + case "mark": + tasks.markTask(Integer.parseInt(task)); + break; + case "unmark": + tasks.unmarkTask(Integer.parseInt(task)); + break; + case "todo": + tasks.addTask(new Todo(task.trim())); + break; + case "deadline": + String[] deadlineSplit = task.split("/"); + tasks.addTask(new Deadline(deadlineSplit[0].trim(), + deadlineSplit[1].substring(3).trim())); + break; + case "event": + String[] eventSplit = task.split("/"); + tasks.addTask(new Event(eventSplit[0].trim(), + eventSplit[1].substring(5).trim(), + eventSplit[2].substring(3).trim())); + break; + case "find": + tasks.findTask(task); + break; + case "delete": + tasks.deleteTask(Integer.parseInt(task)); + break; + default: + System.out.println("Your command is invalid, invalid. Try again."); + } + } catch (IndexOutOfBoundsException e) { + Ui.missingSlashMessage(); + } catch (NumberFormatException e) { + System.out.println("Ensure that you include a number after your delete/find/mark command."); + } + } + + public static void getInput(TaskList tasks) { + Scanner in = new Scanner(System.in); + for(String line = in.nextLine(); !line.equals("bye"); line = in.nextLine()) { + getResponse(line, tasks); + } + } +} diff --git a/src/main/java/util/Storage.java b/src/main/java/util/Storage.java new file mode 100644 index 000000000..aa8ceb2f3 --- /dev/null +++ b/src/main/java/util/Storage.java @@ -0,0 +1,72 @@ +package util; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; +import tasks.Deadline; +import tasks.Event; +import tasks.Task; +import tasks.Todo; + +public class Storage { + private final String PATH = "./data/nocturne.txt"; + private File f; + + public Storage() { + File dir = new File("./data"); + if (!dir.exists()) { + dir.mkdir(); + } + this.f = new File(PATH); + } + + public void saveToFile(TaskList taskList) { + try { + FileWriter fileWriter = new FileWriter(this.f); + fileWriter.write(""); + for (Task task : taskList.tasks) { + fileWriter.append(task.toString()).append("\n"); + } + fileWriter.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public void readFromFile(TaskList tasks) { + try { + Scanner sc = new Scanner(this.f); + + while(sc.hasNextLine()) { + String data = sc.nextLine(); + String task = data.substring(6); + task = task.replace('(', ' '); + task = task.replace(')', ' '); + boolean isDone = data.charAt(4) == 'X'; + switch (data.charAt(1)) { + case 'D': + String[] deadlineSplit = task.split("by:"); + tasks.addTaskStealth(new Deadline(deadlineSplit[0].trim(), + deadlineSplit[1].trim(), + isDone)); + break; + case 'E': + String[] eventSplit = task.split(":"); + tasks.addTaskStealth(new Event(eventSplit[0].substring(0, + eventSplit[0].length() - 4).trim(), + eventSplit[1].substring(0, eventSplit[1].length() - 2).trim(), + eventSplit[2].trim(), + isDone)); + break; + case 'T': + tasks.addTaskStealth(new Todo(task.trim(), isDone)); + } + } + sc.close(); + } catch (IndexOutOfBoundsException | FileNotFoundException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/util/TaskList.java b/src/main/java/util/TaskList.java new file mode 100644 index 000000000..b88f99698 --- /dev/null +++ b/src/main/java/util/TaskList.java @@ -0,0 +1,88 @@ +package util; + +import java.util.ArrayList; +import tasks.Task; + +public class TaskList { + protected ArrayList tasks = new ArrayList<>(); + protected Storage storage = new Storage(); + + public TaskList() { + this.storage.readFromFile(this); + } + + public void addTask(Task task) { + System.out.println("A task I see. I have added it."); + Ui.printTask(task); + this.tasks.add(task); + this.storage.saveToFile(this); + } + + public void addTaskStealth(Task task) { + this.tasks.add(task); + this.storage.saveToFile(this); + } + + public void deleteTask(int index) { + try { + System.out.println("Should all acquaintance be forgot..."); + Ui.printTask(this.tasks.get(index - 1)); + this.tasks.remove(index - 1); + System.out.println(this.tasks.size() + " task(s) remain."); + } catch (IndexOutOfBoundsException e) { + Ui.indexOutOfBoundsMessage(); + } + this.storage.saveToFile(this); + } + + public void listTasks() { + if (this.tasks.isEmpty()) { + Ui.emptyListMessage(); + } + + for(int i = 0; i < this.tasks.size(); ++i) { + System.out.print(i + 1 + "."); + System.out.println(this.tasks.get(i)); + } + + } + + public void markTask(int index) { + try { + (this.tasks.get(index - 1)).markAsDone(); + System.out.println("Congratulations. I have marked this task as finished:"); + Ui.printTask(this.tasks.get(index - 1)); + } catch (IndexOutOfBoundsException var3) { + Ui.indexOutOfBoundsMessage(); + } + + this.storage.saveToFile(this); + } + + public void unmarkTask(int index) { + try { + (this.tasks.get(index - 1)).markAsUndone(); + System.out.println("Do not neglect your duties. I have marked this task as unfinished:"); + Ui.printTask(this.tasks.get(index - 1)); + } catch (IndexOutOfBoundsException e) { + Ui.indexOutOfBoundsMessage(); + } + + this.storage.saveToFile(this); + } + + public void findTask(String keyFind) { + try { + System.out.println("Here is what you are looking for: "); + int count = 1; + for (Task task : this.tasks) { + if (task.getDescription().contains(keyFind)) { + System.out.println(count + ". " + task); + ++count; + } + } + } catch (IndexOutOfBoundsException e) { + Ui.indexOutOfBoundsMessage(); + } + } +} diff --git a/src/main/java/util/Ui.java b/src/main/java/util/Ui.java new file mode 100644 index 000000000..e7338f069 --- /dev/null +++ b/src/main/java/util/Ui.java @@ -0,0 +1,31 @@ +package util; + +import tasks.Task; + +public class Ui { + + public static void greetingMessage() { + System.out.println("Good evening. I'm Nocturne."); + System.out.println("What ails you on this fine day?"); + } + + public static void farewellMessage() { + System.out.println("Farewell. And may the fortunes be ever in your favour."); + } + + public static void indexOutOfBoundsMessage() { + System.out.println("You are trying to access forbidden territory. Tread carefully."); + } + + public static void emptyListMessage() { + System.out.println("Your list is empty. Try again, when you have become more productive."); + } + + public static void missingSlashMessage() { + System.out.println("You are missing a /. Do not let this happen again."); + } + + public static void printTask(Task task) { + System.out.println(" " + task); + } +} From 6516db0b0cbb3b8024096e2e09717f12f5260d55 Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Sat, 9 Mar 2024 02:40:51 +0800 Subject: [PATCH 24/28] Increment to Level 7 --- data/nocturne.txt | 3 --- src/main/java/META-INF/MANIFEST.MF | 3 +++ src/main/java/tasks/Deadline.java | 1 - src/main/java/tasks/Event.java | 13 ++++++++++--- src/main/java/tasks/Todo.java | 1 - src/main/java/util/Storage.java | 5 +++++ 6 files changed, 18 insertions(+), 8 deletions(-) delete mode 100644 data/nocturne.txt create mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/data/nocturne.txt b/data/nocturne.txt deleted file mode 100644 index cbaba7e42..000000000 --- a/data/nocturne.txt +++ /dev/null @@ -1,3 +0,0 @@ -[E][ ] delimit (from: 2pm to: 4pm) -[D][X] finish cs2113t (by: 2359) -[T][X] help diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..a4f239d2c --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Nocturne + diff --git a/src/main/java/tasks/Deadline.java b/src/main/java/tasks/Deadline.java index 445f52c49..c48584944 100644 --- a/src/main/java/tasks/Deadline.java +++ b/src/main/java/tasks/Deadline.java @@ -13,7 +13,6 @@ public Deadline(String description, String by, boolean isDone) { this.by = by; this.isDone = isDone; } - @Override public String toString() { return "[D]" + "[" + super.getStatusIcon() + "] " + this.description + " (by: " + by + ")"; diff --git a/src/main/java/tasks/Event.java b/src/main/java/tasks/Event.java index 4ead4d12b..c1458f012 100644 --- a/src/main/java/tasks/Event.java +++ b/src/main/java/tasks/Event.java @@ -1,3 +1,8 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + package tasks; public class Event extends Task { @@ -16,9 +21,11 @@ public Event(String description, String from, String to, boolean isDone) { this.to = to; this.isDone = isDone; } - + @Override - public String toString(){ - return "[E]" + "[" + super.getStatusIcon() + "] " + this.description + " (from: " + from + " " + "to: " + to + ")"; + public String toString() { + return "[E][" + super.getStatusIcon() + + "] " + this.description + + " (from: " + this.from + " to: " + this.to + ")"; } } diff --git a/src/main/java/tasks/Todo.java b/src/main/java/tasks/Todo.java index 5a0e5c6ef..c3a6ecd6e 100644 --- a/src/main/java/tasks/Todo.java +++ b/src/main/java/tasks/Todo.java @@ -12,7 +12,6 @@ public Todo(String description, boolean isDone) { this.isDone = isDone; } - @Override public String toString() { return "[T]" + "[" + super.getStatusIcon() + "] " + description; diff --git a/src/main/java/util/Storage.java b/src/main/java/util/Storage.java index aa8ceb2f3..6a58c526b 100644 --- a/src/main/java/util/Storage.java +++ b/src/main/java/util/Storage.java @@ -20,6 +20,11 @@ public Storage() { dir.mkdir(); } this.f = new File(PATH); + try { + f.createNewFile(); + } catch (IOException e) { + throw new RuntimeException(e); + } } public void saveToFile(TaskList taskList) { From 9f18a5ac74a6b1f8c5ee98eb2c14920ec994f708 Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Sat, 9 Mar 2024 02:47:53 +0800 Subject: [PATCH 25/28] Increment to Level 9 --- src/main/java/tasks/Event.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/tasks/Event.java b/src/main/java/tasks/Event.java index c1458f012..ae113135b 100644 --- a/src/main/java/tasks/Event.java +++ b/src/main/java/tasks/Event.java @@ -1,8 +1,3 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by FernFlower decompiler) -// - package tasks; public class Event extends Task { From b473729fa9867ed5f40a6857a1f9f4a125e520ec Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Sat, 9 Mar 2024 03:42:59 +0800 Subject: [PATCH 26/28] JavaDoc Increment --- src/main/java/Nocturne.java | 4 +++ src/main/java/tasks/Deadline.java | 24 ++++++++++++++++ src/main/java/tasks/Event.java | 25 ++++++++++++++++ src/main/java/tasks/Task.java | 24 ++++++++++++++++ src/main/java/tasks/Todo.java | 21 ++++++++++++++ src/main/java/util/Parser.java | 30 ++++++++++++++++++++ src/main/java/util/Storage.java | 22 +++++++++++++++ src/main/java/util/TaskList.java | 47 +++++++++++++++++++++++++++++++ src/main/java/util/Ui.java | 25 ++++++++++++++++ 9 files changed, 222 insertions(+) diff --git a/src/main/java/Nocturne.java b/src/main/java/Nocturne.java index 251ee9df6..299fb4496 100644 --- a/src/main/java/Nocturne.java +++ b/src/main/java/Nocturne.java @@ -4,6 +4,10 @@ import util.Ui; public class Nocturne { + + /** + * The main function of the Chatbot, Nocturne. + */ public static void main(String[] args) { TaskList list = new TaskList(); Ui.greetingMessage(); diff --git a/src/main/java/tasks/Deadline.java b/src/main/java/tasks/Deadline.java index c48584944..7f859a7ca 100644 --- a/src/main/java/tasks/Deadline.java +++ b/src/main/java/tasks/Deadline.java @@ -1,18 +1,42 @@ package tasks; +/** + * Deadline subclass of Task. Requiring a by input. + */ public class Deadline extends Task { protected String by; + /** + * Constructor for the deadline object. + * + * @param description The description of the deadline. + * @param by The due date of the deadline. + */ public Deadline(String description, String by) { super(description); this.by = by; } + /** + * Constructor for the deadline object when reconstructing the list + * from nocturne.txt, which includes the completion status of the deadline. + * + * @param description The description of the deadline. + * @param by The due date of the deadline. + * @param isDone The boolean variable of whether the deadline is done or not. + */ public Deadline(String description, String by, boolean isDone) { super(description); this.by = by; this.isDone = isDone; } + + /** + * Override of the deadline class when it is printed, + * resulting in the format shown in the list. + * + * @return The string that will be printed. + */ @Override public String toString() { return "[D]" + "[" + super.getStatusIcon() + "] " + this.description + " (by: " + by + ")"; diff --git a/src/main/java/tasks/Event.java b/src/main/java/tasks/Event.java index ae113135b..89ccdce68 100644 --- a/src/main/java/tasks/Event.java +++ b/src/main/java/tasks/Event.java @@ -1,15 +1,34 @@ package tasks; +/** + * Event subclass of Task. Requires a from and to input. + */ public class Event extends Task { protected String from; protected String to; + /** + * Constructor for the event object. + * + * @param description The description of the event. + * @param from The start time of the event. + * @param to The end time of the event. + */ public Event(String description, String from, String to) { super(description); this.from = from; this.to = to; } + /** + * Constructor for event when restructuring the list from + * nocturne.txt, which includes the completion status of the event. + * + * @param description The description of the event. + * @param from The start time of the event. + * @param to The end time of the event. + * @param isDone The boolean variable of whether the event is done or not. + */ public Event(String description, String from, String to, boolean isDone) { super(description); this.from = from; @@ -17,6 +36,12 @@ public Event(String description, String from, String to, boolean isDone) { this.isDone = isDone; } + /** + * Override of the event class when printed, + * resulting in the format shown in the list. + * + * @return The string that will be printed. + */ @Override public String toString() { return "[E][" + super.getStatusIcon() + diff --git a/src/main/java/tasks/Task.java b/src/main/java/tasks/Task.java index 4932d7758..2efac36f1 100644 --- a/src/main/java/tasks/Task.java +++ b/src/main/java/tasks/Task.java @@ -1,26 +1,50 @@ package tasks; +/** + * The base class of deadline, event and todo. + */ public class Task { protected String description; protected boolean isDone; + /** + * Constructor for the task object. + * + * @param description The description of the task. + */ public Task(String description) { this.description = description; this.isDone = false; } + /** + * The string showing the completion status of the task. + * + * @return X when the task is completed, one blank space otherwise. + */ public String getStatusIcon() { return (isDone ? "X" : " "); } + /** + * Marks a task as done. + */ public void markAsDone() { this.isDone = true; } + /** + * Marks a task as not done. + */ public void markAsUndone() { this.isDone = false; } + /** + * Gets the description of a task. + * + * @return The description of a task. + */ public String getDescription() { return this.description; } diff --git a/src/main/java/tasks/Todo.java b/src/main/java/tasks/Todo.java index c3a6ecd6e..e13407359 100644 --- a/src/main/java/tasks/Todo.java +++ b/src/main/java/tasks/Todo.java @@ -1,17 +1,38 @@ package tasks; +/** + * The Todo subclass of Task. Requires no additional inputs. + */ public class Todo extends Task { + /** + * Constructor for the todo object. + * + * @param description The description of the todo. + */ public Todo(String description) { super(description); this.isDone = false; } + /** + * Constructor for the todo object when restructuring the list + * from nocturne.txt, which includes the completion status of the todo. + * + * @param description The description of the todo. + * @param isDone The boolean variable of whether the todo is done or not. + */ public Todo(String description, boolean isDone) { super(description); this.isDone = isDone; } + /** + * Override of the todo class when it is printed, + * resulting in the format shown in the list. + * + * @return The string that will be printed. + */ @Override public String toString() { return "[T]" + "[" + super.getStatusIcon() + "] " + description; diff --git a/src/main/java/util/Parser.java b/src/main/java/util/Parser.java index ae94c368a..d7f331b74 100644 --- a/src/main/java/util/Parser.java +++ b/src/main/java/util/Parser.java @@ -5,16 +5,40 @@ import tasks.Todo; import java.util.Scanner; +/** + * The class that handles user input and processes for the commands. + */ public class Parser { + + /** + * Takes the first word of any input as the command. + * + * @param input The user's line input. + * @return Command string. + */ public static String getCommand(String input) { return input.split(" ")[0].toLowerCase(); } + /** + * Obtains the non-command part of the input, which contains both + * the description and the timings for deadline and event. + * + * @param input The user's line input. + * @return Non-command string. + */ public static String getTask(String input) { String[] splitInput = input.split(" ", 2); return splitInput.length > 1 ? splitInput[1] : ""; } + /** + * Generates a response based on the user's input. + * + * @param input The user's line input. + * @param tasks The array list of tasks that will be modified + * based on the command. + */ private static void getResponse(String input, TaskList tasks) { String command = getCommand(input); String task = getTask(input); @@ -60,6 +84,12 @@ private static void getResponse(String input, TaskList tasks) { } } + /** + * Takes in the user's input from the command line interface, + * running it through the response method. + * + * @param tasks The array list of tasks that will be modified. + */ public static void getInput(TaskList tasks) { Scanner in = new Scanner(System.in); String line = in.nextLine(); diff --git a/src/main/java/util/Storage.java b/src/main/java/util/Storage.java index 6a58c526b..84c898762 100644 --- a/src/main/java/util/Storage.java +++ b/src/main/java/util/Storage.java @@ -11,9 +11,16 @@ import tasks.Todo; public class Storage { + /** + * Directory constant. + */ private final String PATH = "./data/nocturne.txt"; private File f; + /** + * Constructor for the Storage, creating the directory and file that + * Nocturne will read and write to. + */ public Storage() { File dir = new File("./data"); if (!dir.exists()) { @@ -27,6 +34,12 @@ public Storage() { } } + /** + * Writes to the file specified above. + * + * @param taskList The list of tasks that will be updated on call. + * @throws IOException if the file cannot be access or written to. + */ public void saveToFile(TaskList taskList) { try { FileWriter fileWriter = new FileWriter(this.f); @@ -40,12 +53,21 @@ public void saveToFile(TaskList taskList) { } } + /** + * Reads from the file in the directory specified above. + * + * @param tasks The new instance of the list of tasks that will be shown when + * list is called. + */ public void readFromFile(TaskList tasks) { try { Scanner sc = new Scanner(this.f); while(sc.hasNextLine()) { String data = sc.nextLine(); + + //Deserialization of the strings in the file occur here. + String task = data.substring(6); task = task.replace('(', ' '); task = task.replace(')', ' '); diff --git a/src/main/java/util/TaskList.java b/src/main/java/util/TaskList.java index b88f99698..69c27ab7e 100644 --- a/src/main/java/util/TaskList.java +++ b/src/main/java/util/TaskList.java @@ -3,14 +3,29 @@ import java.util.ArrayList; import tasks.Task; +/** + * This class handles the array list of tasks. + * + */ public class TaskList { + /** + * ArrayList is initialised here. Storage is also initialised at the same time. + */ protected ArrayList tasks = new ArrayList<>(); protected Storage storage = new Storage(); + /** + * Storage reading is done along with the constructor. + */ public TaskList() { this.storage.readFromFile(this); } + /** + * Adds a task to the array list, while updating nocturne.txt. + * + * @param task A task that will be added. Can be of type deadline, event or todo. + */ public void addTask(Task task) { System.out.println("A task I see. I have added it."); Ui.printTask(task); @@ -18,11 +33,25 @@ public void addTask(Task task) { this.storage.saveToFile(this); } + /** + * Adds a task without printing a message, which is done + * on initialisation when reading from nocturne.txt file, + * while updating nocturne.txt. + * + * @param task The task that will be added to the array list. + */ public void addTaskStealth(Task task) { this.tasks.add(task); this.storage.saveToFile(this); } + /** + * Deletes a task in the array list, while updating nocturne.txt. + * + * @param index The index of the entry that will get deleted. + * Starts from 1 to be more intuitive, requiring -1 + * in the accessing. + */ public void deleteTask(int index) { try { System.out.println("Should all acquaintance be forgot..."); @@ -35,6 +64,9 @@ public void deleteTask(int index) { this.storage.saveToFile(this); } + /** + * Lists out all the tasks recorded in the array list thus far. + */ public void listTasks() { if (this.tasks.isEmpty()) { Ui.emptyListMessage(); @@ -47,6 +79,11 @@ public void listTasks() { } + /** + * Marks a task as done, while updating nocturne.txt. + * + * @param index The index of the task that will be updated as done. + */ public void markTask(int index) { try { (this.tasks.get(index - 1)).markAsDone(); @@ -59,6 +96,11 @@ public void markTask(int index) { this.storage.saveToFile(this); } + /** + * Marks a task as undone, while updating nocturne.txt. + * + * @param index The index of the task that will be updated as undone. + */ public void unmarkTask(int index) { try { (this.tasks.get(index - 1)).markAsUndone(); @@ -71,6 +113,11 @@ public void unmarkTask(int index) { this.storage.saveToFile(this); } + /** + * Finds tasks that contain the keyword and prints out any matches. + * + * @param keyFind The string that will be used to find matches. + */ public void findTask(String keyFind) { try { System.out.println("Here is what you are looking for: "); diff --git a/src/main/java/util/Ui.java b/src/main/java/util/Ui.java index e7338f069..616a11b0a 100644 --- a/src/main/java/util/Ui.java +++ b/src/main/java/util/Ui.java @@ -2,29 +2,54 @@ import tasks.Task; +/** + * The class that interacts with the user. General messages are placed here. + */ public class Ui { + /** + * Prints on initialisation. + */ public static void greetingMessage() { System.out.println("Good evening. I'm Nocturne."); System.out.println("What ails you on this fine day?"); } + /** + * Prints on exit. + */ public static void farewellMessage() { System.out.println("Farewell. And may the fortunes be ever in your favour."); } + /** + * Prints to let the user know that they are accessing and index that is out of + * bounds, through the mark, unmark or delete methods. + */ public static void indexOutOfBoundsMessage() { System.out.println("You are trying to access forbidden territory. Tread carefully."); } + /** + * Prints a message to let the user know that their list is empty. + */ public static void emptyListMessage() { System.out.println("Your list is empty. Try again, when you have become more productive."); } + /** + * Prints to let the user know that they are missing / in the deadline and + * event inputs. + */ public static void missingSlashMessage() { System.out.println("You are missing a /. Do not let this happen again."); } + /** + * Prints out a task with indentation. + * + * @param task: a singular task that can be printed, T, D or E. + */ public static void printTask(Task task) { System.out.println(" " + task); } From dba37e0575f5b18374ef46e2323d6837f09a91ef Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Sat, 9 Mar 2024 04:15:48 +0800 Subject: [PATCH 27/28] A-UserGuide --- README.md | 85 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 8715d4d91..26d67c65f 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,61 @@ -# Duke project template - -This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. - -## Setting up in Intellij - -Prerequisites: JDK 11, update Intellij to the most recent version. - -1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) -1. Open the project into Intellij as follows: - 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 1. If there are any further prompts, accept the defaults. -1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
- In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: - ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +# Nocturne v0.2 + +Welcome to the User Guide for Nocturne. + +![The eternal nightmare... Now a servant?](https://pbs.twimg.com/media/E4FchwcVIAIfb4h?format=jpg&name=4096x4096) + +## Setting up the ChatBot + +Ensure that you have the ip.jar file downloaded. Take note of which directory this file is located. A convenient location would be in Downloads, or the Desktop. + +Now, open up the command prompt. You can do this by pressing the Windows key and searching 'Command Prompt'. For Mac users, you can press 'Command + Space' to open up the search bar. From there you can open the Terminal by searching for it on the search bar. + +Once in the terminal, type in *cd Downloads* or *cd Desktop*. This will place you in the directory where you placed Nocturne. Now, simply type +> java -jar ip.jar + +And this will initialize Nocturne. + +## Nocturne's Features + +Primarily, Nocturne is there to help you record tasks you need to do, as well as their completion status. To utilize them, you will need to enter the commands below. In particular, keep the commands in lowercase, and as much as possible, do not deviate from the command structure. Error messages will be thrown at you if you mess up, but not to worry, Nocturne will usually tell you what you did wrong. + +For the features below, Words in UPPER_CASE are the parameters to be supplied by the user. +e.g. in *todo TASK*, *TASK* is a parameter which can be used as *todo pay the bills*. + +### Adding a Todo task: **todo STRING** +Adds a Todo task to the list. +For example: >*todo do the laundry* + +### Adding a deadline task: **deadline STRING /by TIME** +Adds a deadline to the list. +For example: >*deadline return books /by Friday 5pm* + +### Adding an event task: **event STRING /from START /to END** +Adds an event to the list. +For example: >*event Brian's birthday /from Saturday 2pm /to Saturday 10pm + +### Marking a task as complete: **mark NUMBER** +Marks a task as complete. +For example: >*mark 2* + +### Marking a task as incomplete: **unmark NUMBER** +Marks a task as incomplete. +For example: >*unmark 2* + +### Deleting a task: **delete NUMBER** +Deletes a task already on the list. +For example: >*delete 1* + +### Finding a task: **find KEYWORD** +Finds any tasks that have your keyword and shows them to you. Does not include the TIME, START or END inputs from deadline or event. +For example: >*find swim* + +### Listing all tasks: **list** +Lists all the tasks you have accummulated thus far, showing them in a numbered list, displaying their type (T for Todo, D for deadline and E for event) as well as their completion status. + +### Closing the bot: **bye** +Causes the bot to exit. + +Be aware that running the bot in the first place creates a text file, nocturne.txt, within the directory that your ip.jar file is placed in. This holds all of the tasks that you have inputted, which Nocturne will remember on startup once again. There is no need for manual saving, as Nocturne updates it every time you add, delete or mark tasks. + +Thank you for using Nocturne. \ No newline at end of file From 398312997e73b8bbffcf5f1eab676f006728c139 Mon Sep 17 00:00:00 2001 From: nicknamenic Date: Sat, 9 Mar 2024 04:37:35 +0800 Subject: [PATCH 28/28] A-UserGuide --- docs/README.md | 64 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..2f566823f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,61 @@ -# User Guide +# Nocturne v0.2 -## Features +Welcome to the User Guide for Nocturne. -### Feature-ABC +![The eternal nightmare... Now a servant?](https://pbs.twimg.com/media/E4FchwcVIAIfb4h?format=jpg&name=4096x4096) -Description of the feature. +## Setting up the ChatBot -### Feature-XYZ +Ensure that you have the ip.jar file downloaded. Take note of which directory this file is located. A convenient location would be in Downloads, or the Desktop. -Description of the feature. +Now, open up the command prompt. You can do this by pressing the Windows key and searching 'Command Prompt'. For Mac users, you can press 'Command + Space' to open up the search bar. From there you can open the Terminal by searching for it on the search bar. -## Usage +Once in the terminal, type in *cd Downloads* or *cd Desktop*. This will place you in the directory where you placed Nocturne. Now, simply type +> java -jar ip.jar -### `Keyword` - Describe action +And this will initialize Nocturne. -Describe the action and its outcome. +## Nocturne's Features -Example of usage: +Primarily, Nocturne is there to help you record tasks you need to do, as well as their completion status. To utilize them, you will need to enter the commands below. In particular, keep the commands in lowercase, and as much as possible, do not deviate from the command structure. Error messages will be thrown at you if you mess up, but not to worry, Nocturne will usually tell you what you did wrong. -`keyword (optional arguments)` +For the features below, Words in UPPER_CASE are the parameters to be supplied by the user. +e.g. in *todo TASK*, *TASK* is a parameter which can be used as *todo pay the bills*. -Expected outcome: +### Adding a Todo task: **todo STRING** +Adds a Todo task to the list. +For example: >*todo do the laundry* -Description of the outcome. +### Adding a deadline task: **deadline STRING /by TIME** +Adds a deadline to the list. +For example: >*deadline return books /by Friday 5pm* -``` -expected output -``` +### Adding an event task: **event STRING /from START /to END** +Adds an event to the list. +For example: >*event Brian's birthday /from Saturday 2pm /to Saturday 10pm + +### Marking a task as complete: **mark NUMBER** +Marks a task as complete. +For example: >*mark 2* + +### Marking a task as incomplete: **unmark NUMBER** +Marks a task as incomplete. +For example: >*unmark 2* + +### Deleting a task: **delete NUMBER** +Deletes a task already on the list. +For example: >*delete 1* + +### Finding a task: **find KEYWORD** +Finds any tasks that have your keyword and shows them to you. Does not include the TIME, START or END inputs from deadline or event. +For example: >*find swim* + +### Listing all tasks: **list** +Lists all the tasks you have accummulated thus far, showing them in a numbered list, displaying their type (T for Todo, D for deadline and E for event) as well as their completion status. + +### Closing the bot: **bye** +Causes the bot to exit. + +Be aware that running the bot in the first place creates a text file, nocturne.txt, within the directory that your ip.jar file is placed in. This holds all of the tasks that you have inputted, which Nocturne will remember on startup once again. There is no need for manual saving, as Nocturne updates it every time you add, delete or mark tasks. + +Thank you for using Nocturne. \ No newline at end of file