From a14a7288cd1909c6df573d2fbe16374d32b701aa Mon Sep 17 00:00:00 2001 From: Bryan Lee Date: Sat, 26 Aug 2023 16:14:00 +0800 Subject: [PATCH 01/28] Update Duke.java renamed chatbot from duke to Dom, added the various lines --- src/main/java/Duke.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..9a10124c3 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,14 @@ public class Duke { public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; + String logo = " ____ \n" + + " | _ \\ ___ _ __ ___ \n" + + " | | | |/ _ \\| '_ ` _ \\ \n" + + " | |_| | (_) | | | | | |\n" + + " |____/ \\___/|_| |_| |_|\n"; System.out.println("Hello from\n" + logo); + System.out.println("Hello! I'm Dom"); + System.out.println("What can I do for you?"); + + System.out.println(("Bye. Hope to see you again soon")); } } From cbd58cc55444745d8955ed66a5e2693d7b5c767a Mon Sep 17 00:00:00 2001 From: Bryan Lee Date: Sun, 27 Aug 2023 11:51:26 +0800 Subject: [PATCH 02/28] Level 0 increment, edited code --- 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 9a10124c3..b18e9d794 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -6,7 +6,7 @@ public static void main(String[] args) { + " | |_| | (_) | | | | | |\n" + " |____/ \\___/|_| |_| |_|\n"; System.out.println("Hello from\n" + logo); - System.out.println("Hello! I'm Dom"); + System.out.println("Hello! I'm Dom!"); System.out.println("What can I do for you?"); System.out.println(("Bye. Hope to see you again soon")); From b5b91a42ae50ff04f6d5eed2ab3639dfda848738 Mon Sep 17 00:00:00 2001 From: Bryan Lee Date: Tue, 29 Aug 2023 22:33:26 +0800 Subject: [PATCH 03/28] Level 1 --- .gitignore | 1 + src/main/java/Duke.java | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2873e189e..09df8809c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ bin/ /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT +*.class diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index b18e9d794..bf3bc5105 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,3 +1,5 @@ +import java.util.Scanner; + public class Duke { public static void main(String[] args) { String logo = " ____ \n" @@ -8,7 +10,17 @@ public static void main(String[] args) { System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Dom!"); System.out.println("What can I do for you?"); - - System.out.println(("Bye. Hope to see you again soon")); + Scanner in = new Scanner(System.in); + while (true) { + String command = in.nextLine(); + System.out.println("____________________________________________________________"); + System.out.println(" " + command); + System.out.println("____________________________________________________________"); + if (command.equals("bye")) { + System.out.println(("Bye. Hope to see you again soon")); + break; + } + } } } + From 82224dd3bab19a73cee32c763c3a8f35d7f531dd Mon Sep 17 00:00:00 2001 From: Bryan Lee Date: Wed, 30 Aug 2023 01:29:51 +0800 Subject: [PATCH 04/28] Completed Level 2 increment and updated code --- src/main/java/Duke.java | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index bf3bc5105..64ecee416 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,4 +1,5 @@ import java.util.Scanner; +import java.util.ArrayList; public class Duke { public static void main(String[] args) { @@ -10,17 +11,40 @@ public static void main(String[] args) { System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Dom!"); System.out.println("What can I do for you?"); + Scanner in = new Scanner(System.in); + ArrayList list = new ArrayList<>(); + while (true) { String command = in.nextLine(); System.out.println("____________________________________________________________"); - System.out.println(" " + command); - System.out.println("____________________________________________________________"); - if (command.equals("bye")) { - System.out.println(("Bye. Hope to see you again soon")); + if(command.equalsIgnoreCase("bye")) { + System.out.println("Bye. Hope to see you again soon!"); break; + } else if (command.equalsIgnoreCase("list")) { + System.out.println(" " + getTaskList(list)); + } else { + list.add(command); + System.out.println("added: " + command); + } + //System.out.println(" " + command); + System.out.println("____________________________________________________________"); + //if (command.equals("bye")) { + //System.out.println(("Bye. Hope to see you again soon")); + //break; + } + } + private static String getTaskList(ArrayList list) { + StringBuilder task = new StringBuilder(); + if(list.isEmpty()) { + task.append("There is no task in your list"); + } else { + for(int i = 0; i < list.size(); i++) { + task.append(i + 1).append(".").append(list.get(i)).append("\n"); + } } + return task.toString(); } } -} + From 59939a70b9de1172d3acd701f4e667428d6a2b66 Mon Sep 17 00:00:00 2001 From: Bryan Lee Date: Wed, 30 Aug 2023 21:59:00 +0800 Subject: [PATCH 05/28] Added Task.java file, imporved on level-2 code completed level-3 --- src/main/java/Duke.java | 133 ++++++++++++++++++++++++++++++---------- src/main/java/Task.java | 27 ++++++++ 2 files changed, 128 insertions(+), 32 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 64ecee416..38c54a7e1 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,49 +2,118 @@ import java.util.ArrayList; public class Duke { - public static void main(String[] args) { + /* + * This method prints the greetings message when the user starts the program. + */ + public static void greetings() { String logo = " ____ \n" + " | _ \\ ___ _ __ ___ \n" + " | | | |/ _ \\| '_ ` _ \\ \n" + " | |_| | (_) | | | | | |\n" + " |____/ \\___/|_| |_| |_|\n"; System.out.println("Hello from\n" + logo); - System.out.println("Hello! I'm Dom!"); - System.out.println("What can I do for you?"); + String greetings = "____________________________________________________________" + "\n" + + "Hello! I'm Dom" + "\n" + + "What can I do for you?" + "\n" + + "____________________________________________________________"; + System.out.println(greetings); + } + + /* + * This method prints the goodbye message when the user exits the program. + */ + public static void goodbye() { + String goodbye = "____________________________________________________________" + "\n" + + "Bye. Hope to see you again soon!" + "\n" + + "____________________________________________________________"; + System.out.println(goodbye); + } - Scanner in = new Scanner(System.in); - ArrayList list = new ArrayList<>(); + /* + * This method prints the input message. + */ + public static void echo(String input) { + System.out.println(input); + }; - while (true) { - String command = in.nextLine(); - System.out.println("____________________________________________________________"); - if(command.equalsIgnoreCase("bye")) { - System.out.println("Bye. Hope to see you again soon!"); - break; - } else if (command.equalsIgnoreCase("list")) { - System.out.println(" " + getTaskList(list)); - } else { - list.add(command); - System.out.println("added: " + command); - } - //System.out.println(" " + command); - System.out.println("____________________________________________________________"); - //if (command.equals("bye")) { - //System.out.println(("Bye. Hope to see you again soon")); - //break; + /* + * This method prints the list of tasks. + */ + private static void listTasks(ArrayList tasks) { + if (tasks.isEmpty()) { + System.out.println(" No tasks."); + } else { + System.out.println(" Here are the tasks in your list:"); + for (int i = 0; i < tasks.size(); i++) { + Task task = tasks.get(i); + System.out.println(" " + (i + 1) + "." + task.getStatusIcon() + " " + task.getDescription()); } } - private static String getTaskList(ArrayList list) { - StringBuilder task = new StringBuilder(); - if(list.isEmpty()) { - task.append("There is no task in your list"); - } else { - for(int i = 0; i < list.size(); i++) { - task.append(i + 1).append(".").append(list.get(i)).append("\n"); + } + + public static void main(String[] args) { + greetings(); // when user runs the program, UI greets user + + try (Scanner givenTask = new Scanner(System.in)) { + ArrayList tasks = new ArrayList<>(); + + while (true) { + String command = givenTask.nextLine(); + System.out.println("____________________________________________________________"); + + // if user inputs "bye", UI prints goodbye message and exits the program + if (command.equalsIgnoreCase("bye")) { + goodbye(); + break; + } else if (command.equalsIgnoreCase("list")) { // if user inputs "list", UI prints the list of tasks that is stored in the ArrayList + listTasks(tasks); + + // split the command into two parts, "mark" and the task number + // e.g. "mark 1" will be split into "mark" and "1" + // the task number is then parsed into an integer + // the task number is then used to get the task from the ArrayList + // the task is then marked as done + // the UI prints the task that is marked as done + // if the task number is invalid, the UI prints an error message + } else if (command.startsWith("mark")) { // if user inputs "mark", UI marks the task as done + String[] parts = command.split(" "); + if (parts.length == 2) { + int taskIndex = Integer.parseInt(parts[1]) - 1; + if (taskIndex >= 0 && taskIndex < tasks.size()) { + Task task = tasks.get(taskIndex); + task.markAsDone(true); + System.out.println(" Nice! I've marked this task as done:\n" + " " + task.getStatusIcon() + + " " + task.getDescription()); + } else { + System.out.println(" Invalid task number."); + } + } + // split the command into two parts, "unmark" and the task number + // e.g. "unmark 1" will be split into "unmark" and "1" + // the task number is then parsed into an integer + // the task number is then used to get the task from the ArrayList + // the task is then marked as not done yet + // the UI prints the task that is marked as not done yet + // if the task number is invalid, the UI prints an error message + } else if (command.startsWith("unmark")) { + String[] parts = command.split(" "); + if (parts.length == 2) { + int taskIndex = Integer.parseInt(parts[1]) - 1; + if (taskIndex >= 0 && taskIndex < tasks.size()) { + Task task = tasks.get(taskIndex); + task.markAsUndone(true); + System.out.println("OK, I've marked this task as not done yet:\n" + " " + + task.getStatusIcon() + " " + task.getDescription()); + } else { + System.out.println(" Invalid task number."); + } + } + } else { + tasks.add(new Task(command)); + echo(" added: " + command); } + System.out.println("____________________________________________________________"); } - return task.toString(); } } - - +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..0b589191d --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,27 @@ +public class Task { + protected String description; + protected boolean isDone; + + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getStatusIcon() { + //return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols + return (isDone ? "[X]" : "[ ]"); //return X symbols when done, else return empty space + } + + public void markAsDone(boolean isDone) { + this.isDone = true; + } + + public void markAsUndone(boolean isDone) { + this.isDone = false; + } + + public String getDescription() { + return description; + } +} From 8b1d144a214cc8ced04def62ff6c18e6d13a5bec Mon Sep 17 00:00:00 2001 From: Bryan Lee Date: Tue, 5 Sep 2023 00:34:00 +0800 Subject: [PATCH 06/28] edited code --- src/main/java/Duke.java | 12 +++++++----- src/main/java/Task.java | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 38c54a7e1..23232a4fc 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,11 +1,13 @@ -import java.util.Scanner; + + import java.util.ArrayList; +import java.util.Scanner; public class Duke { /* * This method prints the greetings message when the user starts the program. */ - public static void greetings() { + public static void greet() { String logo = " ____ \n" + " | _ \\ ___ _ __ ___ \n" + " | | | |/ _ \\| '_ ` _ \\ \n" @@ -34,7 +36,7 @@ public static void goodbye() { */ public static void echo(String input) { System.out.println(input); - }; + } /* * This method prints the list of tasks. @@ -52,10 +54,10 @@ private static void listTasks(ArrayList tasks) { } public static void main(String[] args) { - greetings(); // when user runs the program, UI greets user + greet(); // when user runs the program, UI greets user try (Scanner givenTask = new Scanner(System.in)) { - ArrayList tasks = new ArrayList<>(); + ArrayList tasks = new ArrayList(); while (true) { String command = givenTask.nextLine(); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 0b589191d..cff338d6e 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -9,7 +9,6 @@ public Task(String description) { } public String getStatusIcon() { - //return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols return (isDone ? "[X]" : "[ ]"); //return X symbols when done, else return empty space } From cdbc6b6a321c483a5cce7c2502cbd83e314ba4a3 Mon Sep 17 00:00:00 2001 From: Bryan Lee Date: Wed, 6 Sep 2023 00:32:15 +0800 Subject: [PATCH 07/28] level-4 completed, edited code --- src/main/java/Deadline.java | 17 +++++++++++ src/main/java/Duke.java | 59 ++++++++++++++++++++++++++++++++----- src/main/java/Event.java | 23 +++++++++++++++ src/main/java/Task.java | 6 +++- src/main/java/Todo.java | 10 +++++++ 5 files changed, 106 insertions(+), 9 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..ca89bce00 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,17 @@ +public class Deadline extends Task{ + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + public String getBy() { + return this.by; + } + + @Override + public String toString() { + return "[D]" + super.toString() + " (by: " + this.by + ")"; + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 23232a4fc..493f71c26 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,4 +1,4 @@ - +//package main.java; import java.util.ArrayList; import java.util.Scanner; @@ -46,15 +46,24 @@ private static void listTasks(ArrayList tasks) { System.out.println(" No tasks."); } else { System.out.println(" Here are the tasks in your list:"); - for (int i = 0; i < tasks.size(); i++) { - Task task = tasks.get(i); - System.out.println(" " + (i + 1) + "." + task.getStatusIcon() + " " + task.getDescription()); + for (int i = 0; i < tasks.size(); i++) { + Task task = tasks.get(i); + String taskType = task instanceof Todo ? "[T]" : (task instanceof Deadline ? "[D]" : "[E]"); + String statusIcon = task.getStatusIcon(); + String description = task.getDescription(); + + if (task instanceof Deadline) { + description += " (by: " + ((Deadline) task).getBy() + ")"; + } else if (task instanceof Event) { + description += " (from: " + ((Event) task).getFrom() + " to: " + ((Event) task).getTo() + ")"; } + + System.out.println(" " + (i + 1) + "." + taskType + statusIcon + " " + description); } } - +} public static void main(String[] args) { - greet(); // when user runs the program, UI greets user + greet(); try (Scanner givenTask = new Scanner(System.in)) { ArrayList tasks = new ArrayList(); @@ -62,8 +71,7 @@ public static void main(String[] args) { while (true) { String command = givenTask.nextLine(); System.out.println("____________________________________________________________"); - - // if user inputs "bye", UI prints goodbye message and exits the program + if (command.equalsIgnoreCase("bye")) { goodbye(); break; @@ -110,6 +118,41 @@ public static void main(String[] args) { System.out.println(" Invalid task number."); } } + } else if (command.startsWith("todo ")) { + // Handle adding a ToDo task + String description = command.substring(5); // Remove "todo " + tasks.add(new Todo(description)); + System.out.println(" Got it. I've added this task:"); + System.out.println(" " + tasks.get(tasks.size() - 1)); + System.out.println(" Now you have " + tasks.size() + " tasks in the list."); + } else if (command.startsWith("deadline ")) { + String[] parts = command.substring(9).split(" /by "); + if (parts.length == 2) { + // Handle adding a Deadline task + String description = parts[0]; + String by = parts[1]; + tasks.add(new Deadline(description, by)); + System.out.println(" Got it. I've added this task:"); + System.out.println(" " + tasks.get(tasks.size() - 1)); + System.out.println(" Now you have " + tasks.size() + " tasks in the list."); + } else { + System.out.println(" Invalid command."); + } + } else if (command.startsWith("event ")) { + // Handle adding an Event task + String[] parts = command.substring(6).split(" /from "); + if (parts.length == 2) { + String description = parts[0]; + String[] timeParts = parts[1].split(" /to "); + String from = timeParts[0]; + String to = timeParts[1]; + tasks.add(new Event(description, from, to)); + System.out.println(" Got it. I've added this task:"); + System.out.println(" " + tasks.get(tasks.size() - 1)); + System.out.println(" Now you have " + tasks.size() + " tasks in the list."); + } else { + System.out.println(" Invalid event command format."); + } } else { tasks.add(new Task(command)); echo(" added: " + command); diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..0afd4c71a --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,23 @@ +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 String getFrom() { + return this.from; + } + + public String getTo() { + return this.to; + } + + @Override + public String toString() { + return "[E]" + super.toString() + "(from: " + this.from + " to: " + this.to + ")"; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index cff338d6e..1ceabe3c0 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -20,7 +20,11 @@ public void markAsUndone(boolean isDone) { this.isDone = false; } + public String toString() { + return getStatusIcon() + " " + this.description; + } + public String getDescription() { - return description; + return this.description; } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..08ff10ce4 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,10 @@ +public class Todo extends Task { + public Todo (String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} From cb72979821e12cff1523a3f023b316043a1e8812 Mon Sep 17 00:00:00 2001 From: Bryan Lee Date: Wed, 13 Sep 2023 12:45:09 +0800 Subject: [PATCH 08/28] edited code --- src/main/java/Duke.java | 160 ++++++++++++++++++++++++++++------------ src/main/java/Task.java | 2 +- 2 files changed, 113 insertions(+), 49 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 493f71c26..6a7c4c161 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,9 +1,9 @@ -//package main.java; - import java.util.ArrayList; import java.util.Scanner; public class Duke { + public static final String lineDivider = "____________________________________________________________"; + /* * This method prints the greetings message when the user starts the program. */ @@ -14,10 +14,10 @@ public static void greet() { + " | |_| | (_) | | | | | |\n" + " |____/ \\___/|_| |_| |_|\n"; System.out.println("Hello from\n" + logo); - String greetings = "____________________________________________________________" + "\n" + - "Hello! I'm Dom" + "\n" + - "What can I do for you?" + "\n" + - "____________________________________________________________"; + String greetings = lineDivider + + "\nHello! I'm Dom\n" + + "What can I do for you?\n" + + lineDivider; System.out.println(greetings); } @@ -25,12 +25,26 @@ public static void greet() { * This method prints the goodbye message when the user exits the program. */ public static void goodbye() { - String goodbye = "____________________________________________________________" + "\n" + - "Bye. Hope to see you again soon!" + "\n" + - "____________________________________________________________"; + String goodbye = lineDivider + + "\nBye. Hope to see you again soon!\n" + + lineDivider; System.out.println(goodbye); } + public static void getHelp() { + String help = + "\nHere are the list of commands that you can use:\n" + + "bye - exits the program\n" + + "list - lists all the tasks\n" + + "todo - adds a ToDo task\n" + + "deadline /by