From 817846f44654d995add07306ddc12d3dddeaefae Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Sat, 8 Feb 2025 19:55:37 +0800 Subject: [PATCH 01/28] level 0 --- src/main/java/Duke.java | 10 ---------- src/main/java/Rick.java | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 10 deletions(-) delete mode 100644 src/main/java/Duke.java create mode 100644 src/main/java/Rick.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334c..000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/Rick.java b/src/main/java/Rick.java new file mode 100644 index 000000000..df6af66ee --- /dev/null +++ b/src/main/java/Rick.java @@ -0,0 +1,16 @@ +public class Rick { + public static void main(String[] args) { + String logo = + " ____ _ _ \n" + + "| _ \\(_) ___| | __\n" + + "| |_) | |/ __| |/ /\n" + + "| _ <| | (__| < \n" + + "|_| \\_\\_|\\___|_|\\_\\"; + System.out.println("Hello from\n" + logo); + System.out.println(""" + Hello, I'm rick + What can I do for you? + Bye. Hope to see you again soon!"""); + + } +} From c5fd4555e197445b8638ee4e3b4cec6d754acdcf Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Sat, 8 Feb 2025 22:29:47 +0800 Subject: [PATCH 02/28] level 1 --- src/main/java/Rick.java | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/Rick.java b/src/main/java/Rick.java index df6af66ee..904f78808 100644 --- a/src/main/java/Rick.java +++ b/src/main/java/Rick.java @@ -1,16 +1,33 @@ +import java.util.Scanner ; + public class Rick { public static void main(String[] args) { String logo = " ____ _ _ \n" + - "| _ \\(_) ___| | __\n" + - "| |_) | |/ __| |/ /\n" + - "| _ <| | (__| < \n" + - "|_| \\_\\_|\\___|_|\\_\\"; + "| _ \\(_) ___| | __\n" + + "| |_) | |/ __| |/ /\n" + + "| _ <| | (__| < \n" + + "|_| \\_\\_|\\___|_|\\_\\"; System.out.println("Hello from\n" + logo); System.out.println(""" Hello, I'm rick What can I do for you? - Bye. Hope to see you again soon!"""); + """); + Scanner s = new Scanner(System.in); + + while (true) { + System.out.print(">"); + String input = s.nextLine(); + + if (input.equalsIgnoreCase("bye")) { + System.out.println("bye bye! Hope to see you soon ^-^ "); + break; + } + + + System.out.println(input); + } } } + From 50c81a9edd9dd96543fdaa24f3286e44ce6ca5cb Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Sat, 15 Feb 2025 14:44:43 +0800 Subject: [PATCH 03/28] level 2 --- src/main/java/Rick.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/Rick.java b/src/main/java/Rick.java index 904f78808..84654658e 100644 --- a/src/main/java/Rick.java +++ b/src/main/java/Rick.java @@ -14,6 +14,8 @@ public static void main(String[] args) { What can I do for you? """); Scanner s = new Scanner(System.in); + String[] tasks = new String[100]; + int i = 0; while (true) { System.out.print(">"); @@ -24,9 +26,24 @@ public static void main(String[] args) { System.out.println("bye bye! Hope to see you soon ^-^ "); break; } + if (input.equalsIgnoreCase("list")){ + if (i ==0) { + System.out.println(" No tasks added."); + } else { + for (int j = 0; j < i; j++) { + System.out.println(" " + (j + 1) + ". " + tasks[j]); + + } + } + continue; + } + System.out.println("added: " + input); + + tasks[i] = input; + i++; + - System.out.println(input); } } } From 4e9d8242ed9cf34ea37b51a0dfd2c18454c5cb32 Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Fri, 28 Feb 2025 00:16:36 +0800 Subject: [PATCH 04/28] level 3 --- src/main/java/Rick.java | 48 +++++++++++++++++++++++++++++++++++------ src/main/java/Task.java | 21 ++++++++++++++++++ 2 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Rick.java b/src/main/java/Rick.java index 84654658e..2a9d6aa21 100644 --- a/src/main/java/Rick.java +++ b/src/main/java/Rick.java @@ -1,6 +1,10 @@ import java.util.Scanner ; public class Rick { + private static final String DIVIDER = " ____________________________________________________________"; + private static void printDivider() { + System.out.println(DIVIDER); + } public static void main(String[] args) { String logo = " ____ _ _ \n" + @@ -14,12 +18,12 @@ public static void main(String[] args) { What can I do for you? """); Scanner s = new Scanner(System.in); - String[] tasks = new String[100]; + Task[] tasks = new Task[100]; //create an Task array called tasks that hold 100 Task elements; int i = 0; while (true) { System.out.print(">"); - String input = s.nextLine(); + String input = s.nextLine(); //enter string element; if (input.equalsIgnoreCase("bye")) { @@ -28,23 +32,53 @@ public static void main(String[] args) { } if (input.equalsIgnoreCase("list")){ if (i ==0) { - System.out.println(" No tasks added."); + System.out.println(" No tasks added."); //tasks array is empty } else { + System.out.println("Here are the items in your list:"); for (int j = 0; j < i; j++) { - System.out.println(" " + (j + 1) + ". " + tasks[j]); + System.out.println((j + 1) + ".[" + tasks[j].getStatusIcon()+ "]"+ tasks[j].description); //iterate through tasks array; } } continue; } - System.out.println("added: " + input); + if(input.startsWith("mark ")){ + int taskIndex = Integer.parseInt(input.substring(5))-1; //finding the index to mark; + if (taskIndex >= 0 && taskIndex < i) { + tasks[taskIndex].markAsDone(); + printDivider(); + System.out.println(" Nice! I've marked this task as done:"); + System.out.println("[" + tasks[taskIndex].getStatusIcon()+"]" + tasks[taskIndex].description); + printDivider(); + } else { + System.out.println("Invalid task number!"); + } + continue; + } + if(input.startsWith("unmark ")){ + int taskIndex = Integer.parseInt(input.substring(7))-1; + if (taskIndex >= 0 && taskIndex < i) { + tasks[taskIndex].markAsUndone(); + printDivider(); + System.out.println(" Nice! I've marked this task as done:"); + System.out.println("[" + tasks[taskIndex].getStatusIcon()+"]" + tasks[taskIndex].description); + printDivider(); + } else { + System.out.println("Invalid task number!"); + } + continue; + } - tasks[i] = input; + + tasks[i] = new Task(input); //fill in element in tasks array of type Task; + printDivider(); + System.out.println("ok! I've added " + input); + printDivider(); i++; } } -} +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..394e86bf8 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,21 @@ +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 void markAsDone(){ + this.isDone = true; + } + + public void markAsUndone(){ + this.isDone = false; + } +} \ No newline at end of file From 340187b07bf11b10666524ebe7547a57d920daac Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Sat, 1 Mar 2025 22:04:20 +0800 Subject: [PATCH 05/28] level 4 --- src/main/java/Deadline.java | 12 +++++++++ src/main/java/Event.java | 14 +++++++++++ src/main/java/Rick.java | 49 +++++++++++++++++++++++++++++++------ src/main/java/Task.java | 4 +++ src/main/java/Todo.java | 9 +++++++ 5 files changed, 81 insertions(+), 7 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..a115632d0 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,12 @@ +public class Deadline extends Task{ + protected String description; + protected String date; + public Deadline(String description, String date){ + super(description); + this.date = date; + } + @Override + public String toString(){ + return "[D]" + super.toString() + " (by: " + date + ")"; + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..7b2e8d860 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,14 @@ +public class Event extends Task{ + protected String description; + protected String time1; + protected String time2; + public Event(String description, String time1, String time2){ + super(description); + this.time1 = time1; + this.time2 = time2; + } + @Override + public String toString(){ + return "[E]" + super.toString() + " (from: " + time1 + " to: " + time2 + ")"; + } +} diff --git a/src/main/java/Rick.java b/src/main/java/Rick.java index 2a9d6aa21..9683998b9 100644 --- a/src/main/java/Rick.java +++ b/src/main/java/Rick.java @@ -5,6 +5,7 @@ public class Rick { private static void printDivider() { System.out.println(DIVIDER); } + public static void main(String[] args) { String logo = " ____ _ _ \n" + @@ -36,7 +37,8 @@ public static void main(String[] args) { } else { System.out.println("Here are the items in your list:"); for (int j = 0; j < i; j++) { - System.out.println((j + 1) + ".[" + tasks[j].getStatusIcon()+ "]"+ tasks[j].description); //iterate through tasks array; + System.out.print(j + 1+"."); //iterate through tasks array; + System.out.println(tasks[j]); } } @@ -48,7 +50,7 @@ public static void main(String[] args) { tasks[taskIndex].markAsDone(); printDivider(); System.out.println(" Nice! I've marked this task as done:"); - System.out.println("[" + tasks[taskIndex].getStatusIcon()+"]" + tasks[taskIndex].description); + System.out.println(tasks[taskIndex]); printDivider(); } else { System.out.println("Invalid task number!"); @@ -61,23 +63,56 @@ public static void main(String[] args) { tasks[taskIndex].markAsUndone(); printDivider(); System.out.println(" Nice! I've marked this task as done:"); - System.out.println("[" + tasks[taskIndex].getStatusIcon()+"]" + tasks[taskIndex].description); + System.out.println(tasks[taskIndex]); printDivider(); } else { System.out.println("Invalid task number!"); } continue; } + if(input.startsWith("todo")){ + System.out.println("Got it, added to task:"); + String inputTodo = input.substring(5); + tasks[i] = new Todo(inputTodo); + } + if(input.startsWith("deadline")){ + System.out.println("Got it, added to task:"); + int firstSpace = input.indexOf(" "); + String modifiedInput = input.substring(firstSpace+1);//remove the word deadline; + String[] part = modifiedInput.split("/by",2); //split modified string to description and date; + String Deadline_description = part[0].trim(); + String Deadline_date = part[1].trim(); + tasks[i] = new Deadline(Deadline_description,Deadline_date); - tasks[i] = new Task(input); //fill in element in tasks array of type Task; - printDivider(); - System.out.println("ok! I've added " + input); - printDivider(); + } + if(input.startsWith("event")){ + System.out.println("Got it, added to task:"); + int firstSpace = input.indexOf(" "); + String modifiedInput = input.substring(firstSpace+1); + String[] part = modifiedInput.split("/from|/to", 3); + String description = part[0].trim(); + String time1 = part[1].trim(); + String time2 = part[2].trim(); + int eventIndex = i + 1; + tasks[i] = new Event(description, time1, time2); + + + } + + System.out.println(tasks[i]); + System.out.println("Now you have "+ String.valueOf(i + 1)+ " tasks in list"); i++; + + + + + + + } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 394e86bf8..784de4375 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -18,4 +18,8 @@ public void markAsDone(){ public void markAsUndone(){ this.isDone = false; } + @Override + public String toString(){ + return "[" + getStatusIcon() +"] " + description; + } } \ No newline at end of file diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..fa6290b39 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,9 @@ +public class Todo extends Task{ + public Todo(String description){ + super(description); + } + @Override + public String toString(){ + return "[T]" + super.toString(); + } +} From b56022f4ec1402196f1528bb33ed003f1951d6f3 Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Mon, 3 Mar 2025 20:32:38 +0800 Subject: [PATCH 06/28] removing spaces in input --- src/main/java/Rick.java | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/main/java/Rick.java b/src/main/java/Rick.java index 9683998b9..cac66912a 100644 --- a/src/main/java/Rick.java +++ b/src/main/java/Rick.java @@ -25,6 +25,7 @@ public static void main(String[] args) { while (true) { System.out.print(">"); String input = s.nextLine(); //enter string element; + input = input.replaceAll("\\s","");//remove all spaces in user input. if (input.equalsIgnoreCase("bye")) { @@ -44,8 +45,8 @@ public static void main(String[] args) { } continue; } - if(input.startsWith("mark ")){ - int taskIndex = Integer.parseInt(input.substring(5))-1; //finding the index to mark; + if(input.startsWith("mark")){ + int taskIndex = Integer.parseInt(input.substring(4))-1; //finding the index to mark; if (taskIndex >= 0 && taskIndex < i) { tasks[taskIndex].markAsDone(); printDivider(); @@ -57,8 +58,8 @@ public static void main(String[] args) { } continue; } - if(input.startsWith("unmark ")){ - int taskIndex = Integer.parseInt(input.substring(7))-1; + if(input.startsWith("unmark")){ + int taskIndex = Integer.parseInt(input.substring(6))-1; if (taskIndex >= 0 && taskIndex < i) { tasks[taskIndex].markAsUndone(); printDivider(); @@ -71,14 +72,11 @@ public static void main(String[] args) { continue; } if(input.startsWith("todo")){ - System.out.println("Got it, added to task:"); - String inputTodo = input.substring(5); - tasks[i] = new Todo(inputTodo); + input = input.substring(4); + tasks[i] = new Todo(input); } if(input.startsWith("deadline")){ - System.out.println("Got it, added to task:"); - int firstSpace = input.indexOf(" "); - String modifiedInput = input.substring(firstSpace+1);//remove the word deadline; + String modifiedInput = input.substring(8);//remove the word deadline; String[] part = modifiedInput.split("/by",2); //split modified string to description and date; String Deadline_description = part[0].trim(); String Deadline_date = part[1].trim(); @@ -87,9 +85,7 @@ public static void main(String[] args) { } if(input.startsWith("event")){ - System.out.println("Got it, added to task:"); - int firstSpace = input.indexOf(" "); - String modifiedInput = input.substring(firstSpace+1); + String modifiedInput = input.substring(5); String[] part = modifiedInput.split("/from|/to", 3); String description = part[0].trim(); String time1 = part[1].trim(); @@ -99,20 +95,12 @@ public static void main(String[] args) { } - + System.out.println("Got it, added to task:"); System.out.println(tasks[i]); System.out.println("Now you have "+ String.valueOf(i + 1)+ " tasks in list"); i++; - - - - - - - - } } From 487f813b79b74ae2d3a42a6b75b6ac37373f1d5e Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Mon, 3 Mar 2025 21:28:23 +0800 Subject: [PATCH 07/28] added exception for todo, deadline and event --- src/main/java/Rick.java | 31 +++++++++++++++++++++++++++---- src/main/java/RickException.java | 3 +++ 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 src/main/java/RickException.java diff --git a/src/main/java/Rick.java b/src/main/java/Rick.java index cac66912a..28b2050ab 100644 --- a/src/main/java/Rick.java +++ b/src/main/java/Rick.java @@ -6,6 +6,7 @@ private static void printDivider() { System.out.println(DIVIDER); } + public static void main(String[] args) { String logo = " ____ _ _ \n" + @@ -28,11 +29,11 @@ public static void main(String[] args) { input = input.replaceAll("\\s","");//remove all spaces in user input. - if (input.equalsIgnoreCase("bye")) { + if (input.startsWith("bye")) { System.out.println("bye bye! Hope to see you soon ^-^ "); break; } - if (input.equalsIgnoreCase("list")){ + if (input.startsWith("list")){ if (i ==0) { System.out.println(" No tasks added."); //tasks array is empty } else { @@ -73,10 +74,24 @@ public static void main(String[] args) { } if(input.startsWith("todo")){ input = input.substring(4); + try{ + if(input.isEmpty()){ + throw new RickException(); + }}catch(RickException e){ + System.out.println("Add your description for todo! ಠ益ಠ"); + continue; + } tasks[i] = new Todo(input); } if(input.startsWith("deadline")){ String modifiedInput = input.substring(8);//remove the word deadline; + try{ + if(modifiedInput.isEmpty()){ + throw new RickException(); + }}catch(RickException e){ + System.out.println("WHERE IS THE DESCRIPTION FOR DEADLINE?! (╯°□°)╯︵ ┻━┻ "); + continue; + } String[] part = modifiedInput.split("/by",2); //split modified string to description and date; String Deadline_description = part[0].trim(); String Deadline_date = part[1].trim(); @@ -86,6 +101,13 @@ public static void main(String[] args) { } if(input.startsWith("event")){ String modifiedInput = input.substring(5); + try{ + if(modifiedInput.isEmpty()){ + throw new RickException(); + }}catch(RickException e) { + System.out.println("No description for event? Brilliant! ಠ_ಠ"); + continue; + } String[] part = modifiedInput.split("/from|/to", 3); String description = part[0].trim(); String time1 = part[1].trim(); @@ -95,9 +117,10 @@ public static void main(String[] args) { } - System.out.println("Got it, added to task:"); + + System.out.println("Okie doki, added to task! ʕ•ᴥ•ʔ "); System.out.println(tasks[i]); - System.out.println("Now you have "+ String.valueOf(i + 1)+ " tasks in list"); + System.out.println("Now you have "+ String.valueOf(i + 1)+ " tasks in list ✿"); i++; diff --git a/src/main/java/RickException.java b/src/main/java/RickException.java new file mode 100644 index 000000000..322d7cf1c --- /dev/null +++ b/src/main/java/RickException.java @@ -0,0 +1,3 @@ +public class RickException extends Exception{ + //empty; +} From ea54e99910303d8bd8a195aaa8d681404839c4d7 Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Mon, 3 Mar 2025 22:41:43 +0800 Subject: [PATCH 08/28] added exception for mark, unmark & invalid input --- src/main/java/Rick.java | 66 +++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/src/main/java/Rick.java b/src/main/java/Rick.java index 28b2050ab..dc34c50a2 100644 --- a/src/main/java/Rick.java +++ b/src/main/java/Rick.java @@ -16,7 +16,7 @@ public static void main(String[] args) { "|_| \\_\\_|\\___|_|\\_\\"; System.out.println("Hello from\n" + logo); System.out.println(""" - Hello, I'm rick + Hello, I'm rick (´。• ᵕ •。`) What can I do for you? """); Scanner s = new Scanner(System.in); @@ -30,14 +30,14 @@ public static void main(String[] args) { if (input.startsWith("bye")) { - System.out.println("bye bye! Hope to see you soon ^-^ "); + System.out.println("bye bye! Hope to see you soon (づ ̄ ³ ̄)づ"); break; } if (input.startsWith("list")){ if (i ==0) { - System.out.println(" No tasks added."); //tasks array is empty + System.out.println(" No tasks added (;ↀ⌓ↀ)"); //tasks array is empty } else { - System.out.println("Here are the items in your list:"); + System.out.println("Here are the items in your list ᕦ(ò_óˇ)ᕤ :"); for (int j = 0; j < i; j++) { System.out.print(j + 1+"."); //iterate through tasks array; System.out.println(tasks[j]); @@ -47,28 +47,38 @@ public static void main(String[] args) { continue; } if(input.startsWith("mark")){ - int taskIndex = Integer.parseInt(input.substring(4))-1; //finding the index to mark; - if (taskIndex >= 0 && taskIndex < i) { - tasks[taskIndex].markAsDone(); - printDivider(); - System.out.println(" Nice! I've marked this task as done:"); - System.out.println(tasks[taskIndex]); - printDivider(); - } else { - System.out.println("Invalid task number!"); + int taskIndex = 0;//declare and initialise outside try-catch block; + try { + taskIndex = Integer.parseInt(input.substring(4)) - 1; //finding the index to mark; + if (taskIndex >= 0 && taskIndex < i) { + tasks[taskIndex].markAsDone(); + printDivider(); + System.out.println(" Nicee! I've marked this task as done ᕕ( ᐛ )ᕗ :"); + System.out.println(tasks[taskIndex]); + printDivider(); + } else { + System.out.println("Invalid task number!"); + } + }catch(NumberFormatException e){ + System.out.println("only a number after mark! O_o"); } continue; } if(input.startsWith("unmark")){ - int taskIndex = Integer.parseInt(input.substring(6))-1; - if (taskIndex >= 0 && taskIndex < i) { - tasks[taskIndex].markAsUndone(); - printDivider(); - System.out.println(" Nice! I've marked this task as done:"); - System.out.println(tasks[taskIndex]); - printDivider(); - } else { - System.out.println("Invalid task number!"); + int taskIndex = 0; + try { + taskIndex = Integer.parseInt(input.substring(6)) - 1; + if (taskIndex >= 0 && taskIndex < i) { + tasks[taskIndex].markAsUndone(); + printDivider(); + System.out.println(" Gotcha! I've unmarked this task (≧▽≦)"); + System.out.println(tasks[taskIndex]); + printDivider(); + } else { + System.out.println("Invalid task number!"); + } + }catch(NumberFormatException e){ + System.out.println("only a number after unmark! o_O"); } continue; } @@ -78,7 +88,7 @@ public static void main(String[] args) { if(input.isEmpty()){ throw new RickException(); }}catch(RickException e){ - System.out.println("Add your description for todo! ಠ益ಠ"); + System.out.println("Your todo task needs a description with keyword: todo"+ System.lineSeparator()+"E.g. todo borrow books"); continue; } tasks[i] = new Todo(input); @@ -89,7 +99,7 @@ public static void main(String[] args) { if(modifiedInput.isEmpty()){ throw new RickException(); }}catch(RickException e){ - System.out.println("WHERE IS THE DESCRIPTION FOR DEADLINE?! (╯°□°)╯︵ ┻━┻ "); + System.out.println("Your deadline task needs a description with keywords: deadline, /by" + System.lineSeparator()+" E.g. deadline return book /by sunday "); continue; } String[] part = modifiedInput.split("/by",2); //split modified string to description and date; @@ -105,7 +115,7 @@ public static void main(String[] args) { if(modifiedInput.isEmpty()){ throw new RickException(); }}catch(RickException e) { - System.out.println("No description for event? Brilliant! ಠ_ಠ"); + System.out.println(" Your event task needs a description with keywords: event, /from & /to" +System.lineSeparator()+"E.g. event project meeting /from Mon 2pm /to 4pm "); continue; } String[] part = modifiedInput.split("/from|/to", 3); @@ -117,10 +127,14 @@ public static void main(String[] args) { } + if(tasks[i] ==null){ + System.out.println("sorry pal, not a recognized command ಸ‿ಸ "); + continue; + } System.out.println("Okie doki, added to task! ʕ•ᴥ•ʔ "); System.out.println(tasks[i]); - System.out.println("Now you have "+ String.valueOf(i + 1)+ " tasks in list ✿"); + System.out.println("Now you have "+ String.valueOf(i + 1)+ " tasks in list ᕙ(⇀‸↼‶)ᕗ"); i++; From 278b61f08de0c612c7076544399241b832163ddd Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Mon, 3 Mar 2025 22:44:28 +0800 Subject: [PATCH 09/28] all exceptions added, level 5 complete From 073a2020df4d920570052075736f70b96969b70c Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Wed, 5 Mar 2025 07:58:41 +0800 Subject: [PATCH 10/28] added delete command --- src/main/java/Rick.java | 96 +++++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 27 deletions(-) diff --git a/src/main/java/Rick.java b/src/main/java/Rick.java index dc34c50a2..ed4970358 100644 --- a/src/main/java/Rick.java +++ b/src/main/java/Rick.java @@ -1,4 +1,5 @@ import java.util.Scanner ; +import java.util.ArrayList; public class Rick { private static final String DIVIDER = " ____________________________________________________________"; @@ -20,13 +21,14 @@ public static void main(String[] args) { What can I do for you? """); Scanner s = new Scanner(System.in); - Task[] tasks = new Task[100]; //create an Task array called tasks that hold 100 Task elements; + ArrayList tasks = new ArrayList<>(); int i = 0; + while (true) { System.out.print(">"); - String input = s.nextLine(); //enter string element; - input = input.replaceAll("\\s","");//remove all spaces in user input. + String originalInput = s.nextLine(); //enter string element; + String input = originalInput.replaceAll("\\s","");//remove all spaces in user input. if (input.startsWith("bye")) { @@ -34,13 +36,15 @@ public static void main(String[] args) { break; } if (input.startsWith("list")){ - if (i ==0) { + if (tasks.isEmpty()) { System.out.println(" No tasks added (;ↀ⌓ↀ)"); //tasks array is empty } else { System.out.println("Here are the items in your list ᕦ(ò_óˇ)ᕤ :"); - for (int j = 0; j < i; j++) { - System.out.print(j + 1+"."); //iterate through tasks array; - System.out.println(tasks[j]); + int arrayIndex = 0; + for (Task task :tasks) { + System.out.print(arrayIndex + 1+"."); //iterate through tasks array; + System.out.println(task.toString()); + arrayIndex++; } } @@ -51,10 +55,10 @@ public static void main(String[] args) { try { taskIndex = Integer.parseInt(input.substring(4)) - 1; //finding the index to mark; if (taskIndex >= 0 && taskIndex < i) { - tasks[taskIndex].markAsDone(); + tasks.get(taskIndex).markAsDone(); printDivider(); System.out.println(" Nicee! I've marked this task as done ᕕ( ᐛ )ᕗ :"); - System.out.println(tasks[taskIndex]); + System.out.println(tasks.get(taskIndex)); printDivider(); } else { System.out.println("Invalid task number!"); @@ -69,10 +73,10 @@ public static void main(String[] args) { try { taskIndex = Integer.parseInt(input.substring(6)) - 1; if (taskIndex >= 0 && taskIndex < i) { - tasks[taskIndex].markAsUndone(); + tasks.get(taskIndex).markAsUndone(); printDivider(); System.out.println(" Gotcha! I've unmarked this task (≧▽≦)"); - System.out.println(tasks[taskIndex]); + System.out.println(tasks.get(taskIndex)); printDivider(); } else { System.out.println("Invalid task number!"); @@ -91,31 +95,43 @@ public static void main(String[] args) { System.out.println("Your todo task needs a description with keyword: todo"+ System.lineSeparator()+"E.g. todo borrow books"); continue; } - tasks[i] = new Todo(input); + tasks.add(new Todo(input)); } if(input.startsWith("deadline")){ String modifiedInput = input.substring(8);//remove the word deadline; try{ if(modifiedInput.isEmpty()){ throw new RickException(); - }}catch(RickException e){ - System.out.println("Your deadline task needs a description with keywords: deadline, /by" + System.lineSeparator()+" E.g. deadline return book /by sunday "); - continue; - } + } + if (!modifiedInput.contains("/by")) {//check if user input contains keyword "/by" + throw new RickException(); + }}catch(RickException e) { + System.out.println("Your deadline task needs a description with keywords: deadline, /by" + System.lineSeparator() + " E.g. deadline return book /by sunday "); + continue; + } catch(ArrayIndexOutOfBoundsException e){ + System.out.println("Please provide both a description and a date using the /by keyword."); + } String[] part = modifiedInput.split("/by",2); //split modified string to description and date; String Deadline_description = part[0].trim(); String Deadline_date = part[1].trim(); - tasks[i] = new Deadline(Deadline_description,Deadline_date); + tasks.add(new Deadline(Deadline_description,Deadline_date)); } - if(input.startsWith("event")){ + if(input.startsWith("event")) { String modifiedInput = input.substring(5); - try{ - if(modifiedInput.isEmpty()){ + try { + if (modifiedInput.isEmpty()) { throw new RickException(); - }}catch(RickException e) { - System.out.println(" Your event task needs a description with keywords: event, /from & /to" +System.lineSeparator()+"E.g. event project meeting /from Mon 2pm /to 4pm "); + } + if (!modifiedInput.contains("/from") | !modifiedInput.contains("/to")) { + throw new RickException(); + } + } catch (RickException e) { + System.out.println(" Your event task needs a description with keywords: event, /from & /to" + System.lineSeparator() + "E.g. event project meeting /from Mon 2pm /to 4pm "); + continue; + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Please provide both a description and a date using the /from & /to keyword."); continue; } String[] part = modifiedInput.split("/from|/to", 3); @@ -123,17 +139,43 @@ public static void main(String[] args) { String time1 = part[1].trim(); String time2 = part[2].trim(); int eventIndex = i + 1; - tasks[i] = new Event(description, time1, time2); - + tasks.add(new Event(description, time1, time2)); } - if(tasks[i] ==null){ - System.out.println("sorry pal, not a recognized command ಸ‿ಸ "); + if(input.startsWith("delete")) { + String modified = input.substring(6).trim(); + try { + if (modified.isEmpty()) { + throw new RickException(); + } + int deleteIndex = Integer.parseInt(modified) - 1; + tasks.remove(deleteIndex); + } catch (RickException e) { + System.out.println("what do I help you delete?"); + continue; + } catch (IndexOutOfBoundsException e) { + System.out.println("Invalid Number!"); + continue; + } catch (NumberFormatException e) { + System.out.print("Enter a number!"); + continue; + } + System.out.println("okie deleted!"); + continue; + } + + + + try { + Task task = tasks.get(i); + + } catch (IndexOutOfBoundsException e) { + System.out.println("sorry pal, not a recognized command"); continue; } System.out.println("Okie doki, added to task! ʕ•ᴥ•ʔ "); - System.out.println(tasks[i]); + System.out.println(tasks.get(i).toString()); System.out.println("Now you have "+ String.valueOf(i + 1)+ " tasks in list ᕙ(⇀‸↼‶)ᕗ"); i++; From 6973f03a4fc454ed71007c78dc0e2e6ea852fb5a Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Sat, 8 Mar 2025 20:11:44 +0800 Subject: [PATCH 11/28] Level 7 --- data/Rick.txt | 2 + src/main/java/Deadline.java | 5 ++ src/main/java/Event.java | 5 ++ src/main/java/Rick.java | 27 ++++++++++- src/main/java/Storage.java | 92 +++++++++++++++++++++++++++++++++++++ src/main/java/Task.java | 4 ++ src/main/java/Todo.java | 5 ++ 7 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 data/Rick.txt create mode 100644 src/main/java/Storage.java diff --git a/data/Rick.txt b/data/Rick.txt new file mode 100644 index 000000000..3d7064b8c --- /dev/null +++ b/data/Rick.txt @@ -0,0 +1,2 @@ +T | 0 | kfjrgkre +D | 0 | null | cnjb diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index a115632d0..2df7e828b 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -9,4 +9,9 @@ public Deadline(String description, String date){ public String toString(){ return "[D]" + super.toString() + " (by: " + date + ")"; } + @Override + public String toDataString() { + // Format: D | 1/0 | description | date + return "D | " + (isDone ? "1" : "0") + " | " + this.description + " | " + this.date; + } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 7b2e8d860..596471ce0 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -11,4 +11,9 @@ public Event(String description, String time1, String time2){ public String toString(){ return "[E]" + super.toString() + " (from: " + time1 + " to: " + time2 + ")"; } + @Override + public String toDataString() { + // Format: E | 1/0 | description | time1 | time2 + return "E | " + (isDone ? "1" : "0") + " | " + this.description + " | " + this.time1 + " | " + this.time2; + } } diff --git a/src/main/java/Rick.java b/src/main/java/Rick.java index ed4970358..9b979d5f3 100644 --- a/src/main/java/Rick.java +++ b/src/main/java/Rick.java @@ -20,9 +20,14 @@ public static void main(String[] args) { Hello, I'm rick (´。• ᵕ •。`) What can I do for you? """); + + Storage storage = new Storage(); + ArrayList tasks = storage.loadTasks(); + int i = tasks.size(); + Scanner s = new Scanner(System.in); - ArrayList tasks = new ArrayList<>(); - int i = 0; + + while (true) { @@ -60,6 +65,8 @@ public static void main(String[] args) { System.out.println(" Nicee! I've marked this task as done ᕕ( ᐛ )ᕗ :"); System.out.println(tasks.get(taskIndex)); printDivider(); + storage.saveTasks(tasks); + } else { System.out.println("Invalid task number!"); } @@ -78,6 +85,8 @@ public static void main(String[] args) { System.out.println(" Gotcha! I've unmarked this task (≧▽≦)"); System.out.println(tasks.get(taskIndex)); printDivider(); + storage.saveTasks(tasks); + } else { System.out.println("Invalid task number!"); } @@ -96,6 +105,8 @@ public static void main(String[] args) { continue; } tasks.add(new Todo(input)); + storage.saveTasks(tasks); + } if(input.startsWith("deadline")){ String modifiedInput = input.substring(8);//remove the word deadline; @@ -115,6 +126,8 @@ public static void main(String[] args) { String Deadline_description = part[0].trim(); String Deadline_date = part[1].trim(); tasks.add(new Deadline(Deadline_description,Deadline_date)); + storage.saveTasks(tasks); + } @@ -140,6 +153,8 @@ public static void main(String[] args) { String time2 = part[2].trim(); int eventIndex = i + 1; tasks.add(new Event(description, time1, time2)); + storage.saveTasks(tasks); + } if(input.startsWith("delete")) { @@ -160,7 +175,15 @@ public static void main(String[] args) { System.out.print("Enter a number!"); continue; } + storage.saveTasks(tasks); System.out.println("okie deleted!"); + int arrayIndex = 0; + for (Task task :tasks) { + System.out.print(arrayIndex + 1+"."); //iterate through tasks array; + System.out.println(task.toString()); + arrayIndex++; + + } continue; } diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 000000000..8e1664ded --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,92 @@ +import java.io.*; +import java.util.ArrayList; +import java.util.Scanner; + +public class Storage { + private File dataFolder; + private File dataFile; + + // Constructor: sets up the folder and file + public Storage() { + // Relative path: "./data/duke.txt" + dataFolder = new File("data"); // folder named 'data' + dataFile = new File(dataFolder, "Rick.txt"); // file named 'duke.txt' in that folder + + // Create the folder if it doesn't exist + if (!dataFolder.exists()) { + dataFolder.mkdirs(); + } + + // Create the file if it doesn't exist + try { + if (!dataFile.exists()) { + dataFile.createNewFile(); + } + } catch (IOException e) { + System.out.println("Error creating file: " + e.getMessage()); + } + } + + /** + * Loads tasks from the file (duke.txt). + * @return An ArrayList of tasks read from the file. + */ + public ArrayList loadTasks() { + ArrayList tasks = new ArrayList<>(); + try (Scanner fileScanner = new Scanner(dataFile)) { + while (fileScanner.hasNextLine()) { + String line = fileScanner.nextLine(); + // Example line: "T | 1 | read book" + String[] parts = line.split("\\|"); + // Trim each part to remove leading/trailing spaces + for (int i = 0; i < parts.length; i++) { + parts[i] = parts[i].trim(); + } + // parts[0] = T/D/E, parts[1] = 1/0, the rest are description/time fields + switch (parts[0]) { + case "T": + Todo todo = new Todo(parts[2]); + if (parts[1].equals("1")) { + todo.markAsDone(); + } + tasks.add(todo); + break; + case "D": + Deadline deadline = new Deadline(parts[2], parts[3]); + if (parts[1].equals("1")) { + deadline.markAsDone(); + } + tasks.add(deadline); + break; + case "E": + Event event = new Event(parts[2], parts[3], parts[4]); + if (parts[1].equals("1")) { + event.markAsDone(); + } + tasks.add(event); + break; + default: + // Unrecognized type + System.out.println("Warning: Unrecognized task type in file: " + line); + } + } + } catch (FileNotFoundException e) { + System.out.println("Error: File not found - " + e.getMessage()); + } + return tasks; + } + + /** + * Saves the current tasks to the file (duke.txt). + * @param tasks The list of tasks to be saved. + */ + public void saveTasks(ArrayList tasks) { + try (PrintWriter writer = new PrintWriter(new FileWriter(dataFile))) { + for (Task task : tasks) { + writer.println(task.toDataString()); + } + } catch (IOException e) { + System.out.println("Error saving tasks: " + e.getMessage()); + } + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 784de4375..9783327a3 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -22,4 +22,8 @@ public void markAsUndone(){ public String toString(){ return "[" + getStatusIcon() +"] " + description; } + public String toDataString() { + return ""; + } + } \ No newline at end of file diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index fa6290b39..dd789b202 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -6,4 +6,9 @@ public Todo(String description){ public String toString(){ return "[T]" + super.toString(); } + @Override + public String toDataString() { + // Format: T | 1/0 | description + return "T | " + (isDone ? "1" : "0") + " | " + this.description; + } } From 59e4fd5fdbd28c2cef368b047b43abdace8c5a92 Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Sun, 9 Mar 2025 13:32:34 +0800 Subject: [PATCH 12/28] A-MoreOOP --- data/Rick.txt | 2 +- src/main/java/META-INF/MANIFEST.MF | 3 + src/main/java/Parser.java | 97 ++++++++++++++ src/main/java/Rick.java | 208 +---------------------------- src/main/java/Storage.java | 10 +- src/main/java/TaskList.java | 34 +++++ src/main/java/Ui.java | 86 ++++++++++++ 7 files changed, 230 insertions(+), 210 deletions(-) create mode 100644 src/main/java/META-INF/MANIFEST.MF create mode 100644 src/main/java/Parser.java create mode 100644 src/main/java/TaskList.java create mode 100644 src/main/java/Ui.java diff --git a/data/Rick.txt b/data/Rick.txt index 3d7064b8c..2b94d0705 100644 --- a/data/Rick.txt +++ b/data/Rick.txt @@ -1,2 +1,2 @@ T | 0 | kfjrgkre -D | 0 | null | cnjb +T | 0 | knfkr diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..33ef12644 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Rick + diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 000000000..a26e3df40 --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,97 @@ +public class Parser { + + /** + * Parses and executes the user command. + * + * @param input The full user input. + * @param taskList The TaskList instance. + * @param storage The Storage instance. + * @param ui The Ui instance. + * @return true if the command is "bye" (to exit), false otherwise. + */ + public static boolean parse(String input, TaskList taskList, Storage storage, Ui ui) { + String trimmedInput = input.trim(); + + if (trimmedInput.equals("bye")) { + ui.showGoodbye(); + return true; // signal to exit the program + } else if (trimmedInput.equals("list")) { + ui.showTaskList(taskList.getTasks()); + } else if (trimmedInput.startsWith("mark")) { + try { + String noSpace = trimmedInput.replaceAll("\\s",""); + int index = Integer.parseInt(noSpace.substring(4)) - 1; + Task task = taskList.getTask(index); + task.markAsDone(); + ui.showTaskDone(task); + storage.saveTasks(taskList.getTasks()); + } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + ui.showError("Invalid task number for marking!"); + } + } else if (trimmedInput.startsWith("unmark")) { + try { + String noSpace = trimmedInput.replaceAll("\\s",""); + int index = Integer.parseInt(noSpace.substring(6)) - 1; + Task task = taskList.getTask(index); + task.markAsUndone(); + ui.showTaskUndone(task); + storage.saveTasks(taskList.getTasks()); + } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + ui.showError("Invalid task number for unmarking!"); + } + } else if (trimmedInput.startsWith("delete")) { + try { + String noSpace = trimmedInput.replaceAll("\\s",""); + int index = Integer.parseInt(noSpace.substring(6)) - 1; + taskList.deleteTask(index); + ui.showTaskDeleted(); + storage.saveTasks(taskList.getTasks()); + } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + ui.showError("Invalid task number for deletion!"); + } + } else if (trimmedInput.startsWith("todo")) { + String description = trimmedInput.substring(4).trim(); + if (description.isEmpty()) { + ui.showError("The description of a todo cannot be empty."); + } else { + Task task = new Todo(description); + taskList.addTask(task); + ui.showTaskAdded(task, taskList.size()); + storage.saveTasks(taskList.getTasks()); + } + } else if (trimmedInput.startsWith("deadline")) { + String[] parts = trimmedInput.substring(8).split("/by", 2); + if (parts.length < 2 || parts[0].trim().isEmpty() || parts[1].trim().isEmpty()) { + ui.showError("Your deadline task needs a description and a due date.\nFormat: deadline /by "); + } else { + String description = parts[0].trim(); + String by = parts[1].trim(); + Task task = new Deadline(description, by); + taskList.addTask(task); + ui.showTaskAdded(task, taskList.size()); + storage.saveTasks(taskList.getTasks()); + } + } else if (trimmedInput.startsWith("event")) { + // Expecting format: event /from /to + String[] parts = trimmedInput.substring(5).split("/from|/to"); + if (parts.length < 3 || + parts[0].trim().isEmpty() || + parts[1].trim().isEmpty() || + parts[2].trim().isEmpty()) { + ui.showError("Your event task needs a description and times.\nFormat: event /from /to "); + } else { + String description = parts[0].trim(); + String from = parts[1].trim(); + String to = parts[2].trim(); + Task task = new Event(description, from, to); + taskList.addTask(task); + ui.showTaskAdded(task, taskList.size()); + storage.saveTasks(taskList.getTasks()); + } + } else { + ui.showError("I'm sorry, but I don't know what that means."); + } + return false; + } +} + diff --git a/src/main/java/Rick.java b/src/main/java/Rick.java index 9b979d5f3..c5449eb56 100644 --- a/src/main/java/Rick.java +++ b/src/main/java/Rick.java @@ -1,209 +1,15 @@ -import java.util.Scanner ; -import java.util.ArrayList; - public class Rick { - private static final String DIVIDER = " ____________________________________________________________"; - private static void printDivider() { - System.out.println(DIVIDER); - } - - public static void main(String[] args) { - String logo = - " ____ _ _ \n" + - "| _ \\(_) ___| | __\n" + - "| |_) | |/ __| |/ /\n" + - "| _ <| | (__| < \n" + - "|_| \\_\\_|\\___|_|\\_\\"; - System.out.println("Hello from\n" + logo); - System.out.println(""" - Hello, I'm rick (´。• ᵕ •。`) - What can I do for you? - """); - + Ui ui = new Ui(); Storage storage = new Storage(); - ArrayList tasks = storage.loadTasks(); - int i = tasks.size(); - - Scanner s = new Scanner(System.in); - - - - - while (true) { - System.out.print(">"); - String originalInput = s.nextLine(); //enter string element; - String input = originalInput.replaceAll("\\s","");//remove all spaces in user input. - - - if (input.startsWith("bye")) { - System.out.println("bye bye! Hope to see you soon (づ ̄ ³ ̄)づ"); - break; - } - if (input.startsWith("list")){ - if (tasks.isEmpty()) { - System.out.println(" No tasks added (;ↀ⌓ↀ)"); //tasks array is empty - } else { - System.out.println("Here are the items in your list ᕦ(ò_óˇ)ᕤ :"); - int arrayIndex = 0; - for (Task task :tasks) { - System.out.print(arrayIndex + 1+"."); //iterate through tasks array; - System.out.println(task.toString()); - arrayIndex++; - - } - } - continue; - } - if(input.startsWith("mark")){ - int taskIndex = 0;//declare and initialise outside try-catch block; - try { - taskIndex = Integer.parseInt(input.substring(4)) - 1; //finding the index to mark; - if (taskIndex >= 0 && taskIndex < i) { - tasks.get(taskIndex).markAsDone(); - printDivider(); - System.out.println(" Nicee! I've marked this task as done ᕕ( ᐛ )ᕗ :"); - System.out.println(tasks.get(taskIndex)); - printDivider(); - storage.saveTasks(tasks); - - } else { - System.out.println("Invalid task number!"); - } - }catch(NumberFormatException e){ - System.out.println("only a number after mark! O_o"); - } - continue; - } - if(input.startsWith("unmark")){ - int taskIndex = 0; - try { - taskIndex = Integer.parseInt(input.substring(6)) - 1; - if (taskIndex >= 0 && taskIndex < i) { - tasks.get(taskIndex).markAsUndone(); - printDivider(); - System.out.println(" Gotcha! I've unmarked this task (≧▽≦)"); - System.out.println(tasks.get(taskIndex)); - printDivider(); - storage.saveTasks(tasks); - - } else { - System.out.println("Invalid task number!"); - } - }catch(NumberFormatException e){ - System.out.println("only a number after unmark! o_O"); - } - continue; - } - if(input.startsWith("todo")){ - input = input.substring(4); - try{ - if(input.isEmpty()){ - throw new RickException(); - }}catch(RickException e){ - System.out.println("Your todo task needs a description with keyword: todo"+ System.lineSeparator()+"E.g. todo borrow books"); - continue; - } - tasks.add(new Todo(input)); - storage.saveTasks(tasks); - - } - if(input.startsWith("deadline")){ - String modifiedInput = input.substring(8);//remove the word deadline; - try{ - if(modifiedInput.isEmpty()){ - throw new RickException(); - } - if (!modifiedInput.contains("/by")) {//check if user input contains keyword "/by" - throw new RickException(); - }}catch(RickException e) { - System.out.println("Your deadline task needs a description with keywords: deadline, /by" + System.lineSeparator() + " E.g. deadline return book /by sunday "); - continue; - } catch(ArrayIndexOutOfBoundsException e){ - System.out.println("Please provide both a description and a date using the /by keyword."); - } - String[] part = modifiedInput.split("/by",2); //split modified string to description and date; - String Deadline_description = part[0].trim(); - String Deadline_date = part[1].trim(); - tasks.add(new Deadline(Deadline_description,Deadline_date)); - storage.saveTasks(tasks); - - - - } - if(input.startsWith("event")) { - String modifiedInput = input.substring(5); - try { - if (modifiedInput.isEmpty()) { - throw new RickException(); - } - if (!modifiedInput.contains("/from") | !modifiedInput.contains("/to")) { - throw new RickException(); - } - } catch (RickException e) { - System.out.println(" Your event task needs a description with keywords: event, /from & /to" + System.lineSeparator() + "E.g. event project meeting /from Mon 2pm /to 4pm "); - continue; - } catch (ArrayIndexOutOfBoundsException e) { - System.out.println("Please provide both a description and a date using the /from & /to keyword."); - continue; - } - String[] part = modifiedInput.split("/from|/to", 3); - String description = part[0].trim(); - String time1 = part[1].trim(); - String time2 = part[2].trim(); - int eventIndex = i + 1; - tasks.add(new Event(description, time1, time2)); - storage.saveTasks(tasks); - - - } - if(input.startsWith("delete")) { - String modified = input.substring(6).trim(); - try { - if (modified.isEmpty()) { - throw new RickException(); - } - int deleteIndex = Integer.parseInt(modified) - 1; - tasks.remove(deleteIndex); - } catch (RickException e) { - System.out.println("what do I help you delete?"); - continue; - } catch (IndexOutOfBoundsException e) { - System.out.println("Invalid Number!"); - continue; - } catch (NumberFormatException e) { - System.out.print("Enter a number!"); - continue; - } - storage.saveTasks(tasks); - System.out.println("okie deleted!"); - int arrayIndex = 0; - for (Task task :tasks) { - System.out.print(arrayIndex + 1+"."); //iterate through tasks array; - System.out.println(task.toString()); - arrayIndex++; - - } - continue; - } - - - - try { - Task task = tasks.get(i); - - } catch (IndexOutOfBoundsException e) { - System.out.println("sorry pal, not a recognized command"); - continue; - } - - System.out.println("Okie doki, added to task! ʕ•ᴥ•ʔ "); - System.out.println(tasks.get(i).toString()); - System.out.println("Now you have "+ String.valueOf(i + 1)+ " tasks in list ᕙ(⇀‸↼‶)ᕗ"); - i++; + TaskList taskList = new TaskList(storage.loadTasks()); + ui.showWelcome(); + boolean exit = false; + while (!exit) { + String input = ui.readCommand(); + exit = Parser.parse(input, taskList, storage, ui); } } - } diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 8e1664ded..bf769a45e 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -27,10 +27,7 @@ public Storage() { } } - /** - * Loads tasks from the file (duke.txt). - * @return An ArrayList of tasks read from the file. - */ + public ArrayList loadTasks() { ArrayList tasks = new ArrayList<>(); try (Scanner fileScanner = new Scanner(dataFile)) { @@ -76,10 +73,7 @@ public ArrayList loadTasks() { return tasks; } - /** - * Saves the current tasks to the file (duke.txt). - * @param tasks The list of tasks to be saved. - */ + public void saveTasks(ArrayList tasks) { try (PrintWriter writer = new PrintWriter(new FileWriter(dataFile))) { for (Task task : tasks) { diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 000000000..5a1015f1a --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,34 @@ +import java.util.ArrayList; + +public class TaskList { + private ArrayList tasks; + + public TaskList() { + this.tasks = new ArrayList<>(); + } + + public TaskList(ArrayList tasks) { + this.tasks = tasks; + } + + public ArrayList getTasks() { + return tasks; + } + + public void addTask(Task task) { + tasks.add(task); + } + + public Task deleteTask(int index) { + return tasks.remove(index); + } + + public Task getTask(int index) { + return tasks.get(index); + } + + public int size() { + return tasks.size(); + } +} + diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 000000000..a5f51ac5b --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,86 @@ +import java.util.ArrayList; +import java.util.Scanner; + +public class Ui { + private static final String DIVIDER = " ____________________________________________________________"; + private Scanner scanner; + + public Ui() { + scanner = new Scanner(System.in); + } + + public void showWelcome() { + String logo = + " ____ _ _ \n" + + "| _ \\(_) ___| | __\n" + + "| |_) | |/ __| |/ /\n" + + "| _ <| | (__| < \n" + + "|_| \\_\\_|\\___|_|\\_\\"; + System.out.println("Hello from\n" + logo); + System.out.println("Hello, I'm rick (´。• ᵕ •。`)\nWhat can I do for you?"); + showDivider(); + } + + public void showGoodbye() { + System.out.println("bye bye! Hope to see you soon (づ ̄ ³ ̄)づ"); + showDivider(); + } + + public String readCommand() { + System.out.print(">"); + return scanner.nextLine(); + } + + public void showDivider() { + System.out.println(DIVIDER); + } + + public void showError(String message) { + System.out.println(message); + showDivider(); + } + + public void showMessage(String message) { + System.out.println(message); + showDivider(); + } + + public void showTaskAdded(Task task, int totalTasks) { + System.out.println("Okie doki, added to task! ʕ•ᴥ•ʔ "); + System.out.println(task); + System.out.println("Now you have " + totalTasks + " tasks in list ᕙ(⇀‸↼‶)ᕗ"); + showDivider(); + } + + public void showTaskDone(Task task) { + System.out.println("Nicee! I've marked this task as done ᕕ( ᐛ )ᕗ :"); + System.out.println(task); + showDivider(); + } + + public void showTaskUndone(Task task) { + System.out.println("Gotcha! I've unmarked this task (≧▽≦)"); + System.out.println(task); + showDivider(); + } + + public void showTaskDeleted() { + System.out.println("okie deleted!"); + showDivider(); + } + + public void showTaskList(ArrayList tasks) { + if (tasks.isEmpty()) { + System.out.println(" No tasks added (;ↀ⌓ↀ)"); + } else { + System.out.println("Here are the items in your list ᕦ(ò_óˇ)ᕤ :"); + int index = 1; + for (Task task : tasks) { + System.out.println(index + ". " + task); + index++; + } + } + showDivider(); + } +} + From e87ecaa3c3da585f19a84ecd69c7ccc9cc141053 Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Mon, 10 Mar 2025 00:48:21 +0800 Subject: [PATCH 13/28] Level-9 --- data/Rick.txt | 3 +-- src/main/java/Parser.java | 25 +++++++++++++++---------- src/main/java/TaskList.java | 10 ++++++++++ src/main/java/Ui.java | 13 +++++++++++++ 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/data/Rick.txt b/data/Rick.txt index 2b94d0705..3a93883af 100644 --- a/data/Rick.txt +++ b/data/Rick.txt @@ -1,2 +1 @@ -T | 0 | kfjrgkre -T | 0 | knfkr +T | 1 | aplle diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index a26e3df40..c5868d772 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,14 +1,8 @@ +import java.util.ArrayList; + public class Parser { - /** - * Parses and executes the user command. - * - * @param input The full user input. - * @param taskList The TaskList instance. - * @param storage The Storage instance. - * @param ui The Ui instance. - * @return true if the command is "bye" (to exit), false otherwise. - */ + public static boolean parse(String input, TaskList taskList, Storage storage, Ui ui) { String trimmedInput = input.trim(); @@ -17,7 +11,18 @@ public static boolean parse(String input, TaskList taskList, Storage storage, Ui return true; // signal to exit the program } else if (trimmedInput.equals("list")) { ui.showTaskList(taskList.getTasks()); - } else if (trimmedInput.startsWith("mark")) { + } + else if (trimmedInput.startsWith("find")) { // NEW: find command + String keyword = trimmedInput.substring(4).trim(); + if (keyword.isEmpty()) { + ui.showError("The search keyword cannot be empty."); + } else { + // Use TaskList's findTasks method to search for tasks containing the keyword + ArrayList foundTasks = taskList.findTasks(keyword); + ui.showFoundTasks(foundTasks); + } + } + else if (trimmedInput.startsWith("mark")) { try { String noSpace = trimmedInput.replaceAll("\\s",""); int index = Integer.parseInt(noSpace.substring(4)) - 1; diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 5a1015f1a..76bd22d9c 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -30,5 +30,15 @@ public Task getTask(int index) { public int size() { return tasks.size(); } + + public ArrayList findTasks(String keyword) { + ArrayList matchingTasks = new ArrayList<>(); + for (Task task : tasks) { + if (task.description.toLowerCase().contains(keyword.toLowerCase())) { + matchingTasks.add(task); + } + } + return matchingTasks; + } } diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index a5f51ac5b..51b95117f 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -82,5 +82,18 @@ public void showTaskList(ArrayList tasks) { } showDivider(); } + public void showFoundTasks(ArrayList tasks) { + if (tasks.isEmpty()) { + System.out.println("No matching tasks found."); + } else { + System.out.println("Here are the matching tasks in your list:"); + int index = 1; + for (Task task : tasks) { + System.out.println(index + ". " + task); + index++; + } + } + showDivider(); + } } From d1b02451acaa6f15588f863851be7799021f3987 Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Mon, 10 Mar 2025 01:20:55 +0800 Subject: [PATCH 14/28] solved error --- data/Rick.txt | 2 ++ src/main/java/Parser.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/data/Rick.txt b/data/Rick.txt index 3a93883af..82d58c3a1 100644 --- a/data/Rick.txt +++ b/data/Rick.txt @@ -1 +1,3 @@ T | 1 | aplle +D | 1 | null | jbfjrbf +E | 1 | null | ebbej | jje diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index c5868d772..a48693aa2 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -30,7 +30,7 @@ else if (trimmedInput.startsWith("mark")) { task.markAsDone(); ui.showTaskDone(task); storage.saveTasks(taskList.getTasks()); - } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + } catch (NumberFormatException | IndexOutOfBoundsException e) { ui.showError("Invalid task number for marking!"); } } else if (trimmedInput.startsWith("unmark")) { @@ -41,7 +41,7 @@ else if (trimmedInput.startsWith("mark")) { task.markAsUndone(); ui.showTaskUndone(task); storage.saveTasks(taskList.getTasks()); - } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + } catch (NumberFormatException | IndexOutOfBoundsException e) { ui.showError("Invalid task number for unmarking!"); } } else if (trimmedInput.startsWith("delete")) { From 17cf10a13b3500f9e62058b9aff070423c4ef619 Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Tue, 11 Mar 2025 13:42:56 +0800 Subject: [PATCH 15/28] resolve exception error --- data/Rick.txt | 4 ++-- src/main/java/Parser.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/data/Rick.txt b/data/Rick.txt index 82d58c3a1..c828b04f0 100644 --- a/data/Rick.txt +++ b/data/Rick.txt @@ -1,3 +1,3 @@ -T | 1 | aplle D | 1 | null | jbfjrbf -E | 1 | null | ebbej | jje +E | 0 | null | ebbej | jje +T | 0 | palle diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index a48693aa2..27a8e43a1 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -51,7 +51,7 @@ else if (trimmedInput.startsWith("mark")) { taskList.deleteTask(index); ui.showTaskDeleted(); storage.saveTasks(taskList.getTasks()); - } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + } catch (NumberFormatException | IndexOutOfBoundsException e) { ui.showError("Invalid task number for deletion!"); } } else if (trimmedInput.startsWith("todo")) { From 6eec05dc0475d6a9857fe9a424f4e3a27008fc45 Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Wed, 12 Mar 2025 19:35:27 +0800 Subject: [PATCH 16/28] checked for code quality --- data/Rick.txt | 6 ++++-- src/main/java/Event.java | 16 ++++++++-------- src/main/java/Parser.java | 12 +++++++++++- src/main/java/Storage.java | 3 +++ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/data/Rick.txt b/data/Rick.txt index c828b04f0..ad078ed83 100644 --- a/data/Rick.txt +++ b/data/Rick.txt @@ -1,3 +1,5 @@ -D | 1 | null | jbfjrbf -E | 0 | null | ebbej | jje T | 0 | palle +E | 0 | null | frj | nn +T | 0 | appe +D | 0 | null | jn +T | 0 | nrfkr diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 596471ce0..4ba6d6a17 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,19 +1,19 @@ public class Event extends Task{ protected String description; - protected String time1; - protected String time2; - public Event(String description, String time1, String time2){ + protected String startTime; + protected String endTime; + public Event(String description, String startTime, String endTime){ super(description); - this.time1 = time1; - this.time2 = time2; + this.startTime = startTime; + this.endTime = endTime; } @Override public String toString(){ - return "[E]" + super.toString() + " (from: " + time1 + " to: " + time2 + ")"; + return "[E]" + super.toString() + " (from: " + startTime + " to: " + endTime + ")"; } @Override public String toDataString() { - // Format: E | 1/0 | description | time1 | time2 - return "E | " + (isDone ? "1" : "0") + " | " + this.description + " | " + this.time1 + " | " + this.time2; + // Format: E | 1/0 | description | startTime| endTime + return "E | " + (isDone ? "1" : "0") + " | " + this.description + " | " + this.startTime + " | " + this.endTime; } } diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 27a8e43a1..299374b24 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,8 +1,18 @@ import java.util.ArrayList; +/** + *Identify key command words such as "bye", "list", "find", "mark", "unmark", "delete", "todo", "deadline" and "event". + */ public class Parser { - + /** + * + * @param input + * @param taskList + * @param storage + * @param ui + * @return true to exit program. If return false, while loop in Rick class will keep running parse method. + */ public static boolean parse(String input, TaskList taskList, Storage storage, Ui ui) { String trimmedInput = input.trim(); diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index bf769a45e..5091a727f 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -2,6 +2,9 @@ import java.util.ArrayList; import java.util.Scanner; +/** + * Stores task elements in hard drive + */ public class Storage { private File dataFolder; private File dataFile; From 65581d72e06ff7f1924c66aa7b7d58586227b8dd Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Thu, 13 Mar 2025 00:40:39 +0800 Subject: [PATCH 17/28] added javadoc comments --- data/Rick.txt | 7 +++---- src/main/java/Parser.java | 12 ++++++------ src/main/java/Rick.java | 6 ++++++ src/main/java/Storage.java | 9 ++++++--- src/main/java/Task.java | 7 +++++++ src/main/java/TaskList.java | 3 +++ src/main/java/Ui.java | 16 +++++++++++----- 7 files changed, 42 insertions(+), 18 deletions(-) diff --git a/data/Rick.txt b/data/Rick.txt index ad078ed83..f512030d7 100644 --- a/data/Rick.txt +++ b/data/Rick.txt @@ -1,5 +1,4 @@ -T | 0 | palle E | 0 | null | frj | nn -T | 0 | appe -D | 0 | null | jn -T | 0 | nrfkr +T | 1 | appe +T | 1 | nrfkr +T | 0 | fjfnr diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 299374b24..ff6a2cbb7 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -25,7 +25,7 @@ public static boolean parse(String input, TaskList taskList, Storage storage, Ui else if (trimmedInput.startsWith("find")) { // NEW: find command String keyword = trimmedInput.substring(4).trim(); if (keyword.isEmpty()) { - ui.showError("The search keyword cannot be empty."); + ui.showError("The search keyword cannot be empty. (✖╭╮✖)\n"); } else { // Use TaskList's findTasks method to search for tasks containing the keyword ArrayList foundTasks = taskList.findTasks(keyword); @@ -41,7 +41,7 @@ else if (trimmedInput.startsWith("mark")) { ui.showTaskDone(task); storage.saveTasks(taskList.getTasks()); } catch (NumberFormatException | IndexOutOfBoundsException e) { - ui.showError("Invalid task number for marking!"); + ui.showError("Invalid task number for marking! (✖ _ ✖)\n"); } } else if (trimmedInput.startsWith("unmark")) { try { @@ -52,7 +52,7 @@ else if (trimmedInput.startsWith("mark")) { ui.showTaskUndone(task); storage.saveTasks(taskList.getTasks()); } catch (NumberFormatException | IndexOutOfBoundsException e) { - ui.showError("Invalid task number for unmarking!"); + ui.showError("Invalid task number for unmarking! (´・_・`)"); } } else if (trimmedInput.startsWith("delete")) { try { @@ -62,12 +62,12 @@ else if (trimmedInput.startsWith("mark")) { ui.showTaskDeleted(); storage.saveTasks(taskList.getTasks()); } catch (NumberFormatException | IndexOutOfBoundsException e) { - ui.showError("Invalid task number for deletion!"); + ui.showError("Invalid task number for deletion! (´;︵;`)"); } } else if (trimmedInput.startsWith("todo")) { String description = trimmedInput.substring(4).trim(); if (description.isEmpty()) { - ui.showError("The description of a todo cannot be empty."); + ui.showError("The description of a todo cannot be empty. (。•́︿•̀。)"); } else { Task task = new Todo(description); taskList.addTask(task); @@ -104,7 +104,7 @@ else if (trimmedInput.startsWith("mark")) { storage.saveTasks(taskList.getTasks()); } } else { - ui.showError("I'm sorry, but I don't know what that means."); + ui.showError("I'm sorry, but I don't know what that means. (・・)?"); } return false; } diff --git a/src/main/java/Rick.java b/src/main/java/Rick.java index c5449eb56..0e6b43a84 100644 --- a/src/main/java/Rick.java +++ b/src/main/java/Rick.java @@ -1,3 +1,9 @@ +/** + * The main entry point of the application. + */ + + + public class Rick { public static void main(String[] args) { Ui ui = new Ui(); diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 5091a727f..e8c883d96 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -9,11 +9,14 @@ public class Storage { private File dataFolder; private File dataFile; - // Constructor: sets up the folder and file + /** + * The constructor creates a folder named "data" in the current directory and a file named "Rick.txt" within that folder. + * If the folder or file does not exist, they are automatically created. + */ public Storage() { // Relative path: "./data/duke.txt" dataFolder = new File("data"); // folder named 'data' - dataFile = new File(dataFolder, "Rick.txt"); // file named 'duke.txt' in that folder + dataFile = new File(dataFolder, "Rick.txt"); // file named 'Rick.txt' in that folder // Create the folder if it doesn't exist if (!dataFolder.exists()) { @@ -42,7 +45,7 @@ public ArrayList loadTasks() { for (int i = 0; i < parts.length; i++) { parts[i] = parts[i].trim(); } - // parts[0] = T/D/E, parts[1] = 1/0, the rest are description/time fields + // parts[0] = T/D/E, parts[1] = 1/0, the rest are description/time switch (parts[0]) { case "T": Todo todo = new Todo(parts[2]); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 9783327a3..88497edbe 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,3 +1,10 @@ + +/** + * The Task class provides basic functionalities for handling a task's description, + * marking it as done or undone, and generating string representations of the task. + */ + + public class Task { protected String description; protected boolean isDone; diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 76bd22d9c..f45d07ea2 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -1,4 +1,7 @@ import java.util.ArrayList; +/** + * The TaskList class encapsulates a collection of Task objects + */ public class TaskList { private ArrayList tasks; diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 51b95117f..c42150bb2 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,8 +1,14 @@ import java.util.ArrayList; import java.util.Scanner; - +/** + * Handles user interactions by displaying messages and reading user input. + * The Ui class is responsible for printing the welcome message, task updates, + * and errors. It also reads commands entered by the user. + */ public class Ui { + private static final String DIVIDER = " ____________________________________________________________"; + private Scanner scanner; public Ui() { @@ -22,7 +28,7 @@ public void showWelcome() { } public void showGoodbye() { - System.out.println("bye bye! Hope to see you soon (づ ̄ ³ ̄)づ"); + System.out.println("bye bye! Hope to see you soon (❁´◡`❁)"); showDivider(); } @@ -65,7 +71,7 @@ public void showTaskUndone(Task task) { } public void showTaskDeleted() { - System.out.println("okie deleted!"); + System.out.println("okie deleted! (`・ω・´)"); showDivider(); } @@ -84,9 +90,9 @@ public void showTaskList(ArrayList tasks) { } public void showFoundTasks(ArrayList tasks) { if (tasks.isEmpty()) { - System.out.println("No matching tasks found."); + System.out.println("No matching tasks found. (╥_╥)"); } else { - System.out.println("Here are the matching tasks in your list:"); + System.out.println("Here are the matching tasks in your list (ง'̀-'́)ง :"); int index = 1; for (Task task : tasks) { System.out.println(index + ". " + task); From 5151f5fcd60eb3470626c761b0938edce6e4724a Mon Sep 17 00:00:00 2001 From: limleyhooi <141608116+limleyhooi@users.noreply.github.com> Date: Fri, 14 Mar 2025 19:24:57 +0800 Subject: [PATCH 18/28] Update README.md --- README.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index af0309a9e..2bd520a64 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Duke project template +# Rick 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. +This is a project template for a greenfield Java project. Given below are instructions on how to use it. ## Setting up in Intellij @@ -13,14 +13,16 @@ Prerequisites: JDK 17, update Intellij to the most recent version. 1. If there are any further prompts, accept the defaults. 1. Configure the project to use **JDK 17** (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. -1. 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: +1. After that, locate the `src/main/java/Rick.java` file, right-click it, and choose `Run Rick.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 - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| + ____ _ _ +| _ \(_) ___| | __ +| |_) | |/ __| |/ / +| _ <| | (__| < +|_| \_\_|\___|_|\_\ +Hello, I'm rick (´。• ᵕ •。`) +What can I do for you? ``` **Warning:** Keep the `src\main\java` folder as the root folder for Java files (i.e., don't rename those folders or move Java files to another folder outside of this folder path), as this is the default location some tools (e.g., Gradle) expect to find Java files. From 48fc7c456146de3308da48036cc82f239a054a68 Mon Sep 17 00:00:00 2001 From: limleyhooi <141608116+limleyhooi@users.noreply.github.com> Date: Fri, 14 Mar 2025 19:27:27 +0800 Subject: [PATCH 19/28] Update README.md 2nd time --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2bd520a64..5f32a502f 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,13 @@ Prerequisites: JDK 17, update Intellij to the most recent version. 1. After that, locate the `src/main/java/Rick.java` file, right-click it, and choose `Run Rick.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 - ____ _ _ -| _ \(_) ___| | __ -| |_) | |/ __| |/ / -| _ <| | (__| < -|_| \_\_|\___|_|\_\ -Hello, I'm rick (´。• ᵕ •。`) -What can I do for you? + ____ _ _ + | _ \(_) ___| | __ + | |_) | |/ __| |/ / + | _ <| | (__| < + |_| \_\_|\___|_|\_\ + Hello, I'm rick (´。• ᵕ •。`) + What can I do for you? ``` **Warning:** Keep the `src\main\java` folder as the root folder for Java files (i.e., don't rename those folders or move Java files to another folder outside of this folder path), as this is the default location some tools (e.g., Gradle) expect to find Java files. From 18c5c52847810e965bfdea29b7d322a3c70e9396 Mon Sep 17 00:00:00 2001 From: limleyhooi <141608116+limleyhooi@users.noreply.github.com> Date: Fri, 14 Mar 2025 19:28:31 +0800 Subject: [PATCH 20/28] Update README.md 3rd time --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f32a502f..79baab33c 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Prerequisites: JDK 17, update Intellij to the most recent version. | |_) | |/ __| |/ / | _ <| | (__| < |_| \_\_|\___|_|\_\ - Hello, I'm rick (´。• ᵕ •。`) + Hello, I'm Rick (´。• ᵕ •。`) What can I do for you? ``` From 169974a66fcadc1ae84697f2e1eecf1b00f1afc0 Mon Sep 17 00:00:00 2001 From: limleyhooi <141608116+limleyhooi@users.noreply.github.com> Date: Fri, 14 Mar 2025 20:48:45 +0800 Subject: [PATCH 21/28] Update README.md --- docs/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 47b9f984f..faf27b0f6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,10 +1,13 @@ -# Duke User Guide +# Rick User Guide // Update the title above to match the actual product name // Product screenshot goes here +image + // Product intro goes here +Rick is a chatbot to help you in managing your tasks! ## Adding deadlines @@ -27,4 +30,4 @@ expected output ## Feature XYZ -// Feature details \ No newline at end of file +// Feature details From ef362260723cfe223a4d85b0668c586d8db2709e Mon Sep 17 00:00:00 2001 From: limleyhooi <141608116+limleyhooi@users.noreply.github.com> Date: Fri, 14 Mar 2025 22:50:54 +0800 Subject: [PATCH 22/28] Update UG --- docs/README.md | 70 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 15 deletions(-) diff --git a/docs/README.md b/docs/README.md index faf27b0f6..92fa7ae44 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,31 +1,71 @@ # Rick User Guide -// Update the title above to match the actual product name - -// Product screenshot goes here image +Rick is an expressive and friendly chatbot that helps you manage your tasks. With Rick, you can add tasks, set deadlines, schedule events, and more. This guide explains how to use all of Rick’s features. + +## How to run Rick: +1. Copy the jar file into an empty folder (you can find Rick.jar in the github release mechanism) +2. Open a command window in that folder. +3. Run the command java -jar Rick.jar (i.e., run the command in the same folder as the jar file). + +After starting, Rick will display a welcome message. Yay! you can start interacting with Rick by typing in your command and press enter. + +# Avaiable Commands + +## 1. Existing Rick +command: bye +what it does: closes Rick. +image + +## 2. Listing All Tasks +command: list +what it does: Shows all the tasks you have added. +image + +## 3. Finding Task +command: find +what it does: search for task that contains a specific word. +image + +## 4. Marking Task as Done +command: mark +what it does: mark the task with "X" +image + +## 5. Marking Task as Undone +command: unmark +what it does: remove the "X" mark on task +image + +## 6. Deleting a Task +command: delete +what it does: remove a task from your list +image + +## 7. Adding a Todo Task +command: todo +what it does: Adds a task +image + +## 8. Adding a Deadline Task +command: deadline /by +what it does: Adds a task with deadline +image + +## 9. Adding an Event task +command: event /from /to +what it does: Adds a task with start time and end time +image -// Product intro goes here -Rick is a chatbot to help you in managing your tasks! -## Adding deadlines -// Describe the action and its outcome. -// Give examples of usage -Example: `keyword (optional arguments)` -// A description of the expected outcome goes here -``` -expected output -``` -## Feature ABC -// Feature details ## Feature XYZ From 19ff87502aceb7f596019253620d27d19c46b31b Mon Sep 17 00:00:00 2001 From: limleyhooi <141608116+limleyhooi@users.noreply.github.com> Date: Fri, 14 Mar 2025 22:53:09 +0800 Subject: [PATCH 23/28] Update UG 2nd time --- docs/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/README.md b/docs/README.md index 92fa7ae44..352af8318 100644 --- a/docs/README.md +++ b/docs/README.md @@ -14,8 +14,13 @@ After starting, Rick will display a welcome message. Yay! you can start interact # Avaiable Commands ## 1. Existing Rick + command: bye + + what it does: closes Rick. + + image ## 2. Listing All Tasks From 2d33c751fc53c48600055d454941a9c3ef91cb38 Mon Sep 17 00:00:00 2001 From: limleyhooi <141608116+limleyhooi@users.noreply.github.com> Date: Fri, 14 Mar 2025 22:54:04 +0800 Subject: [PATCH 24/28] testing format for UG --- docs/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 352af8318..362120bc8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -17,15 +17,16 @@ After starting, Rick will display a welcome message. Yay! you can start interact command: bye - what it does: closes Rick. - image ## 2. Listing All Tasks + command: list + what it does: Shows all the tasks you have added. + image ## 3. Finding Task From db1c9b38674a719ec4b0040ceca931b94a3756a4 Mon Sep 17 00:00:00 2001 From: limleyhooi <141608116+limleyhooi@users.noreply.github.com> Date: Fri, 14 Mar 2025 22:55:19 +0800 Subject: [PATCH 25/28] ensure correct format for UG --- docs/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/README.md b/docs/README.md index 362120bc8..58293ffa8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -30,38 +30,59 @@ what it does: Shows all the tasks you have added. image ## 3. Finding Task + command: find + what it does: search for task that contains a specific word. + image ## 4. Marking Task as Done + command: mark + what it does: mark the task with "X" + image ## 5. Marking Task as Undone + command: unmark + what it does: remove the "X" mark on task + image ## 6. Deleting a Task + command: delete + what it does: remove a task from your list + image ## 7. Adding a Todo Task + command: todo + what it does: Adds a task + image ## 8. Adding a Deadline Task + command: deadline /by + what it does: Adds a task with deadline + image ## 9. Adding an Event task + command: event /from /to + what it does: Adds a task with start time and end time + image From 6651a0720628350c1462c52a172b0fd0f5e9169c Mon Sep 17 00:00:00 2001 From: limleyhooi <141608116+limleyhooi@users.noreply.github.com> Date: Fri, 14 Mar 2025 22:55:55 +0800 Subject: [PATCH 26/28] UG formatting --- docs/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 58293ffa8..f2d167c65 100644 --- a/docs/README.md +++ b/docs/README.md @@ -95,6 +95,4 @@ what it does: Adds a task with start time and end time -## Feature XYZ -// Feature details From 1579be436ef77fcc07bc6a824b7da1466238f006 Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Fri, 14 Mar 2025 23:00:36 +0800 Subject: [PATCH 27/28] adjustments --- data/Rick.txt | 8 ++++---- src/main/java/Ui.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/data/Rick.txt b/data/Rick.txt index f512030d7..14566f397 100644 --- a/data/Rick.txt +++ b/data/Rick.txt @@ -1,4 +1,4 @@ -E | 0 | null | frj | nn -T | 1 | appe -T | 1 | nrfkr -T | 0 | fjfnr +T | 0 | math +T | 0 | science hw +D | 0 | null | friday +E | 0 | null | 10:00 | 11:00 diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index c42150bb2..38aadba26 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -23,7 +23,7 @@ public void showWelcome() { "| _ <| | (__| < \n" + "|_| \\_\\_|\\___|_|\\_\\"; System.out.println("Hello from\n" + logo); - System.out.println("Hello, I'm rick (´。• ᵕ •。`)\nWhat can I do for you?"); + System.out.println("Hello, I'm Rick (´。• ᵕ •。`)\nWhat can I do for you?"); showDivider(); } From 16a40003904db7fc87d41e5569302e45cafe3c3f Mon Sep 17 00:00:00 2001 From: limleyhooi Date: Fri, 14 Mar 2025 23:16:13 +0800 Subject: [PATCH 28/28] more edits --- data/Rick.txt | 3 +++ docs/README.md | 2 +- src/main/java/Deadline.java | 2 +- src/main/java/Event.java | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/data/Rick.txt b/data/Rick.txt index 14566f397..c6b7c2364 100644 --- a/data/Rick.txt +++ b/data/Rick.txt @@ -2,3 +2,6 @@ T | 0 | math T | 0 | science hw D | 0 | null | friday E | 0 | null | 10:00 | 11:00 +D | 0 | null | today +D | 0 | apple | today +E | 0 | hw | today | tmr diff --git a/docs/README.md b/docs/README.md index f2d167c65..226e74435 100644 --- a/docs/README.md +++ b/docs/README.md @@ -11,7 +11,7 @@ Rick is an expressive and friendly chatbot that helps you manage your tasks. Wit After starting, Rick will display a welcome message. Yay! you can start interacting with Rick by typing in your command and press enter. -# Avaiable Commands +# Available Commands ## 1. Existing Rick diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 2df7e828b..6c07eb7f4 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,5 +1,5 @@ public class Deadline extends Task{ - protected String description; + protected String date; public Deadline(String description, String date){ super(description); diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 4ba6d6a17..2bd4a4df3 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,5 +1,5 @@ public class Event extends Task{ - protected String description; + protected String startTime; protected String endTime; public Event(String description, String startTime, String endTime){