From cbe03ba3bd3e407dd9ea03adc02a231940324c8e Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Sat, 28 Jan 2023 22:22:32 +0800 Subject: [PATCH 01/54] Added Increment - Level 0 --- src/main/java/Buddy.java | 13 +++++++++++++ src/main/java/Duke.java | 10 ---------- 2 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 src/main/java/Buddy.java delete mode 100644 src/main/java/Duke.java diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java new file mode 100644 index 000000000..862b036d4 --- /dev/null +++ b/src/main/java/Buddy.java @@ -0,0 +1,13 @@ +public class Buddy { + public static void main(String[] args) { + String greeting = "Hello there! I'm Buddy\n" + + "How may I assist you?"; + String exitMessage = "Hope I was of help to you! Have a great day and see you again, Buddy :)"; + String divider = "________________________________________________________________________________"; + System.out.println(divider); + System.out.println(greeting); + System.out.println(divider); + System.out.println(exitMessage); + + } +} 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); - } -} From f2d0bfe97da4393274fe4606e20cf5f71978e4d1 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Sat, 28 Jan 2023 22:57:06 +0800 Subject: [PATCH 02/54] Added Increment - Level 1 --- src/main/java/Buddy.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 862b036d4..583257394 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -1,13 +1,30 @@ +import java.util.Scanner; + public class Buddy { public static void main(String[] args) { String greeting = "Hello there! I'm Buddy\n" - + "How may I assist you?"; + + "How may I assist you?"; String exitMessage = "Hope I was of help to you! Have a great day and see you again, Buddy :)"; String divider = "________________________________________________________________________________"; + System.out.println(divider); System.out.println(greeting); + System.out.println(divider); + + String command; + Scanner in = new Scanner(System.in); + command = in.nextLine(); + + while (! command.equals("bye")){ + System.out.println(divider); + System.out.println(command); + System.out.println(divider); + command = in.nextLine(); + } + System.out.println(divider); System.out.println(exitMessage); + System.out.println(divider); } } From e5f92822e2f2b1f78f8047dffe0f999892fcc265 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Sun, 29 Jan 2023 00:37:20 +0800 Subject: [PATCH 03/54] Added Increment - Level 2 --- src/main/java/Buddy.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 583257394..d49aaa898 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -1,4 +1,5 @@ import java.util.Scanner; +import java.util.Arrays; public class Buddy { public static void main(String[] args) { @@ -11,15 +12,30 @@ public static void main(String[] args) { System.out.println(greeting); System.out.println(divider); + String[] listOfThings = new String[100]; + int currentPosition = 0; String command; Scanner in = new Scanner(System.in); command = in.nextLine(); while (! command.equals("bye")){ - System.out.println(divider); - System.out.println(command); - System.out.println(divider); + int index = 1; + if (command.equals("list")){ + for (int i = 0; i < currentPosition; i++){ // while not null + System.out.println(index + ". " + listOfThings[index-1]); + index++; + } + } + + else { + listOfThings[currentPosition] = command; + System.out.println(divider); + System.out.println("added: " + command); + System.out.println(divider); + currentPosition++; + } command = in.nextLine(); + } System.out.println(divider); From c0efa6eabc1bd41364cdbdc158bc36575d46a7cc Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Wed, 1 Feb 2023 02:33:42 +0800 Subject: [PATCH 04/54] Added Increment - Level 3 --- src/main/java/Buddy.java | 33 ++++++++++++++++++++++++++++----- src/main/java/Task.java | 21 +++++++++++++++++++++ 2 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index d49aaa898..eee109cfb 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -12,8 +12,8 @@ public static void main(String[] args) { System.out.println(greeting); System.out.println(divider); - String[] listOfThings = new String[100]; - int currentPosition = 0; + Task[] listOfThings = new Task[100]; // why cannot private static? + int currentPosition = 0; // why cannot private static? String command; Scanner in = new Scanner(System.in); command = in.nextLine(); @@ -22,13 +22,36 @@ public static void main(String[] args) { int index = 1; if (command.equals("list")){ for (int i = 0; i < currentPosition; i++){ // while not null - System.out.println(index + ". " + listOfThings[index-1]); + System.out.println(index + ". [" + listOfThings[index - 1].getStatusIcon() + "] " + listOfThings[index-1].description); index++; } } - else { - listOfThings[currentPosition] = command; + else if (command.startsWith("mark")){ // .startsWith(" ") + int taskNumber = Integer.parseInt(command.substring(5)); + // have to parse + Task currentTask = listOfThings[taskNumber - 1]; + currentTask .setDone(true); + System.out.println(divider); + System.out.println("Great work on completing this task! Marked as done! :)"); + System.out.println("[" + currentTask.getStatusIcon() + "] " + currentTask.description); + System.out.println(divider); + } + + else if (command.startsWith("unmark")){ + int taskNumber = Integer.parseInt(command.substring(7)); + Task currentTask = listOfThings[taskNumber - 1]; + currentTask.setDone(false); + System.out.println(divider); + System.out.println("Remember to come back to this task! Marked as undone!"); + System.out.println("[" + currentTask.getStatusIcon() + "] " + currentTask.description); + System.out.println(divider); + + } + + else { // adding tasks + listOfThings[currentPosition] = new Task(command); // have to write in + //Task t = new Task(command); System.out.println(divider); System.out.println("added: " + command); System.out.println(divider); diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..b4923a243 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,21 @@ +public class Task { + protected String description; + protected boolean isDone; // protected => public + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + public boolean isDone() { // do we need this + return isDone; + } + + public void setDone(boolean isDone){ + this.isDone = isDone; + } +} From eae4525ad934354bf438448e5c3303d7032fe852 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Wed, 1 Feb 2023 02:46:07 +0800 Subject: [PATCH 05/54] Coding Standards --> Used camelCase throughout --- src/main/java/Buddy.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index eee109cfb..dd3eb4fc2 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -1,6 +1,8 @@ import java.util.Scanner; import java.util.Arrays; +// camelCase used as a coding standard + public class Buddy { public static void main(String[] args) { String greeting = "Hello there! I'm Buddy\n" From 7435c1add6309c40b60e155e092ca0290fe83685 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Wed, 1 Feb 2023 05:22:17 +0800 Subject: [PATCH 06/54] Added Increment - Level 4 --- src/main/java/Buddy.java | 62 ++++++++++++++++++++++++++++++++++--- src/main/java/Deadline.java | 14 +++++++++ src/main/java/Event.java | 16 ++++++++++ src/main/java/Task.java | 5 +++ src/main/java/Todo.java | 12 +++++++ 5 files changed, 104 insertions(+), 5 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/Buddy.java b/src/main/java/Buddy.java index dd3eb4fc2..96a5251fa 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -24,7 +24,7 @@ public static void main(String[] args) { int index = 1; if (command.equals("list")){ for (int i = 0; i < currentPosition; i++){ // while not null - System.out.println(index + ". [" + listOfThings[index - 1].getStatusIcon() + "] " + listOfThings[index-1].description); + System.out.println(index + "." + listOfThings[index - 1]); index++; } } @@ -33,10 +33,10 @@ else if (command.startsWith("mark")){ // .startsWith(" ") int taskNumber = Integer.parseInt(command.substring(5)); // have to parse Task currentTask = listOfThings[taskNumber - 1]; - currentTask .setDone(true); + currentTask.setDone(true); System.out.println(divider); System.out.println("Great work on completing this task! Marked as done! :)"); - System.out.println("[" + currentTask.getStatusIcon() + "] " + currentTask.description); + System.out.println(currentTask); System.out.println(divider); } @@ -46,23 +46,75 @@ else if (command.startsWith("unmark")){ currentTask.setDone(false); System.out.println(divider); System.out.println("Remember to come back to this task! Marked as undone!"); - System.out.println("[" + currentTask.getStatusIcon() + "] " + currentTask.description); + System.out.println(currentTask); System.out.println(divider); } - else { // adding tasks + /*else { // adding tasks listOfThings[currentPosition] = new Task(command); // have to write in //Task t = new Task(command); System.out.println(divider); System.out.println("added: " + command); System.out.println(divider); currentPosition++; + }*/ + + else{ //todo or deadline or event --> put together so don't have to repeat the same code thrice + System.out.println(divider); + System.out.println("Got it! I have added this task: "); + if (command.startsWith("todo")){ + Todo todoBeingAdded = new Todo(command.substring(5)); + listOfThings[currentPosition] = todoBeingAdded; + // Task is not a Todo but Todo is a task + System.out.println(todoBeingAdded); + } + + else if (command.startsWith("deadline")){ + Task taskBeingAdded = new Task(command.substring(9)); // task + date + slash (Description) + // filter the description and date + String taskWithDate = taskBeingAdded.description; + int indexOfSlash = taskWithDate.indexOf('/'); + String taskDescription = taskWithDate.substring(0, (indexOfSlash - 1)); // substring goes to the one before the second index!!!! + String date = taskWithDate.substring(indexOfSlash + 4); + Deadline deadlineBeingAdded = new Deadline(taskDescription, date); + listOfThings[currentPosition] = deadlineBeingAdded; + System.out.println(deadlineBeingAdded); + + } + + else if (command.startsWith("event")){ + Task taskBeingAdded = new Task(command.substring(6)); + // filter the description, from and to + String wholeLine = taskBeingAdded.description; + int indexOfFirstSlash = wholeLine.indexOf('/'); + String taskDescription = wholeLine.substring(0, (indexOfFirstSlash - 1)); + int indexOfSecondSlash = wholeLine.indexOf('/', (indexOfFirstSlash + 1)); //searches from index after first slash + String from = wholeLine.substring( (indexOfFirstSlash + 6), (indexOfSecondSlash)); + String to = wholeLine.substring(indexOfSecondSlash + 4); + Event eventBeingAdded = new Event(taskDescription, from, to); + listOfThings[currentPosition] = eventBeingAdded; + System.out.println(eventBeingAdded); + } + + currentPosition++; + System.out.print("You currently have " + currentPosition); + if (currentPosition == 1){ + System.out.println(" task remaining! Let's finish it quickly!"); + } + else{ + System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all three subtasks so put at the bottom + } + + } command = in.nextLine(); + } + + System.out.println(divider); System.out.println(exitMessage); System.out.println(divider); diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..0ff576079 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,14 @@ +public class Deadline extends Task { + + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + @Override + public String toString() { + return "[D]" + super.toString() + " (Please do by: " + by + "!)"; + } +} \ No newline at end of file diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..bb20f2825 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,16 @@ +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; + } + + @Override + public String toString() { + return "[E]" + super.toString() + " (from: " + from + "to: " + to + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/Task.java b/src/main/java/Task.java index b4923a243..619e37027 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -18,4 +18,9 @@ public boolean isDone() { // do we need this public void setDone(boolean isDone){ this.isDone = isDone; } + + @Override + public String toString() { // overrides --> print task prints this! + return "[" + this.getStatusIcon() + "] " + this.description; + } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..c8013d573 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,12 @@ +public class Todo extends Task { + protected boolean isDone; + public Todo(String description) { + super(description); // don't need isDone as isDone is already in Task class + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} + From 8c9d925a639ab0d6a3f8f6ba4ba96c1e1373d6d3 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Thu, 9 Feb 2023 23:23:30 +0800 Subject: [PATCH 07/54] Cleaned up code + Added increment - Code Quality --- src/main/java/Buddy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 96a5251fa..df25a5e18 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -102,7 +102,7 @@ else if (command.startsWith("event")){ if (currentPosition == 1){ System.out.println(" task remaining! Let's finish it quickly!"); } - else{ + else { System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all three subtasks so put at the bottom } From 4a3350e7c3781298b66d72e6aac93dfa0066dc92 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Thu, 9 Feb 2023 23:23:54 +0800 Subject: [PATCH 08/54] Cleaned up code + Added increment - Code Quality --- src/main/java/Buddy.java | 63 +++++++++++++--------------------------- src/main/java/Task.java | 6 ++-- 2 files changed, 23 insertions(+), 46 deletions(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index df25a5e18..a31efacd0 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -4,6 +4,9 @@ // camelCase used as a coding standard public class Buddy { + + static final int TOTAL_TASKS = 100; + public static void main(String[] args) { String greeting = "Hello there! I'm Buddy\n" + "How may I assist you?"; @@ -14,22 +17,20 @@ public static void main(String[] args) { System.out.println(greeting); System.out.println(divider); - Task[] listOfThings = new Task[100]; // why cannot private static? + Task[] listOfThings = new Task[TOTAL_TASKS]; // why cannot private static? int currentPosition = 0; // why cannot private static? String command; Scanner in = new Scanner(System.in); command = in.nextLine(); - while (! command.equals("bye")){ + while (!command.equals("bye")) { int index = 1; - if (command.equals("list")){ - for (int i = 0; i < currentPosition; i++){ // while not null + if (command.equals("list")) { + for (int i = 0; i < currentPosition; i++) { // while not null System.out.println(index + "." + listOfThings[index - 1]); index++; } - } - - else if (command.startsWith("mark")){ // .startsWith(" ") + } else if (command.startsWith("mark")) { // .startsWith(" ") int taskNumber = Integer.parseInt(command.substring(5)); // have to parse Task currentTask = listOfThings[taskNumber - 1]; @@ -38,9 +39,7 @@ else if (command.startsWith("mark")){ // .startsWith(" ") System.out.println("Great work on completing this task! Marked as done! :)"); System.out.println(currentTask); System.out.println(divider); - } - - else if (command.startsWith("unmark")){ + } else if (command.startsWith("unmark")) { int taskNumber = Integer.parseInt(command.substring(7)); Task currentTask = listOfThings[taskNumber - 1]; currentTask.setDone(false); @@ -48,30 +47,18 @@ else if (command.startsWith("unmark")){ System.out.println("Remember to come back to this task! Marked as undone!"); System.out.println(currentTask); System.out.println(divider); - - } - - /*else { // adding tasks - listOfThings[currentPosition] = new Task(command); // have to write in - //Task t = new Task(command); - System.out.println(divider); - System.out.println("added: " + command); - System.out.println(divider); - currentPosition++; - }*/ - - else{ //todo or deadline or event --> put together so don't have to repeat the same code thrice + } else { //todo or deadline or event --> put together so don't have to repeat the same code thrice System.out.println(divider); System.out.println("Got it! I have added this task: "); - if (command.startsWith("todo")){ - Todo todoBeingAdded = new Todo(command.substring(5)); + if (command.startsWith("todo")) { + int todo_starting_index = 5; + Todo todoBeingAdded = new Todo(command.substring(todo_starting_index)); listOfThings[currentPosition] = todoBeingAdded; // Task is not a Todo but Todo is a task System.out.println(todoBeingAdded); - } - - else if (command.startsWith("deadline")){ - Task taskBeingAdded = new Task(command.substring(9)); // task + date + slash (Description) + } else if (command.startsWith("deadline")) { + int deadline_starting_index = 9; + Task taskBeingAdded = new Task(command.substring(deadline_starting_index)); // task + date + slash (Description) // filter the description and date String taskWithDate = taskBeingAdded.description; int indexOfSlash = taskWithDate.indexOf('/'); @@ -81,16 +68,14 @@ else if (command.startsWith("deadline")){ listOfThings[currentPosition] = deadlineBeingAdded; System.out.println(deadlineBeingAdded); - } - - else if (command.startsWith("event")){ + } else if (command.startsWith("event")) { Task taskBeingAdded = new Task(command.substring(6)); // filter the description, from and to String wholeLine = taskBeingAdded.description; int indexOfFirstSlash = wholeLine.indexOf('/'); String taskDescription = wholeLine.substring(0, (indexOfFirstSlash - 1)); int indexOfSecondSlash = wholeLine.indexOf('/', (indexOfFirstSlash + 1)); //searches from index after first slash - String from = wholeLine.substring( (indexOfFirstSlash + 6), (indexOfSecondSlash)); + String from = wholeLine.substring((indexOfFirstSlash + 6), (indexOfSecondSlash)); String to = wholeLine.substring(indexOfSecondSlash + 4); Event eventBeingAdded = new Event(taskDescription, from, to); listOfThings[currentPosition] = eventBeingAdded; @@ -99,22 +84,14 @@ else if (command.startsWith("event")){ currentPosition++; System.out.print("You currently have " + currentPosition); - if (currentPosition == 1){ + if (currentPosition == 1) { System.out.println(" task remaining! Let's finish it quickly!"); - } - else { + } else { System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all three subtasks so put at the bottom } - - } command = in.nextLine(); - - } - - - System.out.println(divider); System.out.println(exitMessage); System.out.println(divider); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 619e37027..29248228d 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -15,12 +15,12 @@ public boolean isDone() { // do we need this return isDone; } - public void setDone(boolean isDone){ + public void setDone(boolean isDone) { this.isDone = isDone; } - @Override - public String toString() { // overrides --> print task prints this! + @Override // overrides --> print task prints this! + public String toString() { return "[" + this.getStatusIcon() + "] " + this.description; } } From 8bf96264908946223a92642e964690a9056600d9 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 10 Feb 2023 00:14:29 +0800 Subject: [PATCH 09/54] Improved code quality --- src/main/java/Buddy.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index a31efacd0..65db1c724 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -2,6 +2,7 @@ import java.util.Arrays; // camelCase used as a coding standard +// indented according to Java coding standards public class Buddy { @@ -31,7 +32,8 @@ public static void main(String[] args) { index++; } } else if (command.startsWith("mark")) { // .startsWith(" ") - int taskNumber = Integer.parseInt(command.substring(5)); + int taskNumberIndexMark = 5; + int taskNumber = Integer.parseInt(command.substring(taskNumberIndexMark)); // have to parse Task currentTask = listOfThings[taskNumber - 1]; currentTask.setDone(true); @@ -40,7 +42,8 @@ public static void main(String[] args) { System.out.println(currentTask); System.out.println(divider); } else if (command.startsWith("unmark")) { - int taskNumber = Integer.parseInt(command.substring(7)); + int taskNumberIndexUnmark = 7; + int taskNumber = Integer.parseInt(command.substring(taskNumberIndexUnmark)); Task currentTask = listOfThings[taskNumber - 1]; currentTask.setDone(false); System.out.println(divider); @@ -51,14 +54,14 @@ public static void main(String[] args) { System.out.println(divider); System.out.println("Got it! I have added this task: "); if (command.startsWith("todo")) { - int todo_starting_index = 5; - Todo todoBeingAdded = new Todo(command.substring(todo_starting_index)); + int todoStartingIndex = 5; + Todo todoBeingAdded = new Todo(command.substring(todoStartingIndex)); listOfThings[currentPosition] = todoBeingAdded; // Task is not a Todo but Todo is a task System.out.println(todoBeingAdded); } else if (command.startsWith("deadline")) { - int deadline_starting_index = 9; - Task taskBeingAdded = new Task(command.substring(deadline_starting_index)); // task + date + slash (Description) + int deadlineStartingIndex = 9; + Task taskBeingAdded = new Task(command.substring(deadlineStartingIndex)); // task + date + slash (Description) // filter the description and date String taskWithDate = taskBeingAdded.description; int indexOfSlash = taskWithDate.indexOf('/'); @@ -68,8 +71,9 @@ public static void main(String[] args) { listOfThings[currentPosition] = deadlineBeingAdded; System.out.println(deadlineBeingAdded); - } else if (command.startsWith("event")) { - Task taskBeingAdded = new Task(command.substring(6)); + } else if (command.startsWith("event")){ + int eventStartingIndex = 6; + Task taskBeingAdded = new Task(command.substring(eventStartingIndex)); // filter the description, from and to String wholeLine = taskBeingAdded.description; int indexOfFirstSlash = wholeLine.indexOf('/'); From 8e63c8d0ccf8db35be5c652700713df41be58dd1 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 10 Feb 2023 15:44:14 +0800 Subject: [PATCH 10/54] Added Level 5 for two exceptions + reformatted code --- src/main/java/BuddyException.java | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/main/java/BuddyException.java diff --git a/src/main/java/BuddyException.java b/src/main/java/BuddyException.java new file mode 100644 index 000000000..6c3b97f39 --- /dev/null +++ b/src/main/java/BuddyException.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class BuddyException { +} From 63a70ee93f44005122297383bf70e82005bf9900 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 10 Feb 2023 15:45:03 +0800 Subject: [PATCH 11/54] Added exceptions for Level 5 --- src/main/java/Buddy.java | 51 ++++++++++++++++++++++--------- src/main/java/BuddyException.java | 2 +- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 65db1c724..10ee56dd6 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -11,11 +11,13 @@ public class Buddy { public static void main(String[] args) { String greeting = "Hello there! I'm Buddy\n" + "How may I assist you?"; + String listOfCommands = "Here are the commands you can use: todo, deadline, event, list, mark, unmark, bye"; String exitMessage = "Hope I was of help to you! Have a great day and see you again, Buddy :)"; String divider = "________________________________________________________________________________"; System.out.println(divider); System.out.println(greeting); + System.out.println(listOfCommands); System.out.println(divider); Task[] listOfThings = new Task[TOTAL_TASKS]; // why cannot private static? @@ -24,7 +26,9 @@ public static void main(String[] args) { Scanner in = new Scanner(System.in); command = in.nextLine(); + while (!command.equals("bye")) { + int index = 1; if (command.equals("list")) { for (int i = 0; i < currentPosition; i++) { // while not null @@ -35,30 +39,46 @@ public static void main(String[] args) { int taskNumberIndexMark = 5; int taskNumber = Integer.parseInt(command.substring(taskNumberIndexMark)); // have to parse - Task currentTask = listOfThings[taskNumber - 1]; - currentTask.setDone(true); - System.out.println(divider); - System.out.println("Great work on completing this task! Marked as done! :)"); - System.out.println(currentTask); - System.out.println(divider); + + try { + Task currentTask = listOfThings[taskNumber - 1]; + currentTask.setDone(true); + System.out.println(divider); + System.out.println("Great work on completing this task! Marked as done! :)"); + System.out.println(currentTask); + System.out.println(divider); + } catch (IndexOutOfBoundsException a) { + System.out.println("That is not a valid task to mark! Please check your list again and input a valid task"); + + } } else if (command.startsWith("unmark")) { int taskNumberIndexUnmark = 7; int taskNumber = Integer.parseInt(command.substring(taskNumberIndexUnmark)); - Task currentTask = listOfThings[taskNumber - 1]; - currentTask.setDone(false); - System.out.println(divider); - System.out.println("Remember to come back to this task! Marked as undone!"); - System.out.println(currentTask); - System.out.println(divider); - } else { //todo or deadline or event --> put together so don't have to repeat the same code thrice + + try { + Task currentTask = listOfThings[taskNumber - 1]; + + currentTask.setDone(false); + System.out.println(divider); + System.out.println("Remember to come back to this task! Marked as undone!"); + System.out.println(currentTask); + System.out.println(divider); + } catch (IndexOutOfBoundsException a) { + System.out.println("That is not a valid task to unmark! Please check your list again and input a valid task"); + + } + } else if (command.startsWith("todo") || command.startsWith("deadline") || command.startsWith("event")) { //todo or deadline or event --> put together so don't have to repeat the same code thrice System.out.println(divider); System.out.println("Got it! I have added this task: "); if (command.startsWith("todo")) { int todoStartingIndex = 5; + Todo todoBeingAdded = new Todo(command.substring(todoStartingIndex)); listOfThings[currentPosition] = todoBeingAdded; + // Task is not a Todo but Todo is a task System.out.println(todoBeingAdded); + } else if (command.startsWith("deadline")) { int deadlineStartingIndex = 9; Task taskBeingAdded = new Task(command.substring(deadlineStartingIndex)); // task + date + slash (Description) @@ -71,7 +91,7 @@ public static void main(String[] args) { listOfThings[currentPosition] = deadlineBeingAdded; System.out.println(deadlineBeingAdded); - } else if (command.startsWith("event")){ + } else if (command.startsWith("event")) { int eventStartingIndex = 6; Task taskBeingAdded = new Task(command.substring(eventStartingIndex)); // filter the description, from and to @@ -93,8 +113,11 @@ public static void main(String[] args) { } else { System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all three subtasks so put at the bottom } + } else { + System.out.println("This command does not exist! Please type a valid command!"); } command = in.nextLine(); + } System.out.println(divider); System.out.println(exitMessage); diff --git a/src/main/java/BuddyException.java b/src/main/java/BuddyException.java index 6c3b97f39..2988fb133 100644 --- a/src/main/java/BuddyException.java +++ b/src/main/java/BuddyException.java @@ -1,2 +1,2 @@ -package PACKAGE_NAME;public class BuddyException { +public class BuddyException { } From cc2f69df01f4d674d6a3c3bb7a3593dba120cb93 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 17 Feb 2023 14:09:21 +0800 Subject: [PATCH 12/54] add delete command --- src/main/java/META-INF/MANIFEST.MF | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..df98b6161 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: main + From 1f72f15ae6819eae8ac627cd521051062b34c1f2 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 17 Feb 2023 14:15:02 +0800 Subject: [PATCH 13/54] add delete command --- src/main/java/Buddy.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 10ee56dd6..3f4e71820 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -104,7 +104,12 @@ public static void main(String[] args) { Event eventBeingAdded = new Event(taskDescription, from, to); listOfThings[currentPosition] = eventBeingAdded; System.out.println(eventBeingAdded); - } + } //else if (command.startsWith("delete")){ + // int indexOfTaskNumber = 7; + //int taskNumberToBeDeleted = listOfThings[indexOfTaskNumber]; + + + //} currentPosition++; System.out.print("You currently have " + currentPosition); From 6d07cfd1574486608a4565204621d61bd5cf0c36 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Sun, 19 Feb 2023 23:24:09 +0800 Subject: [PATCH 14/54] Changed to array list + Added Level 6 --- src/main/java/Buddy.java | 41 ++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 3f4e71820..d3fcd8a05 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -1,5 +1,6 @@ import java.util.Scanner; import java.util.Arrays; +import java.util.ArrayList; // camelCase used as a coding standard // indented according to Java coding standards @@ -20,8 +21,9 @@ public static void main(String[] args) { System.out.println(listOfCommands); System.out.println(divider); - Task[] listOfThings = new Task[TOTAL_TASKS]; // why cannot private static? - int currentPosition = 0; // why cannot private static? + ArrayList listOfThings = new ArrayList<>(); + //Task[] listOfThings = new Task[TOTAL_TASKS]; + int currentPosition = 0; String command; Scanner in = new Scanner(System.in); command = in.nextLine(); @@ -32,7 +34,7 @@ public static void main(String[] args) { int index = 1; if (command.equals("list")) { for (int i = 0; i < currentPosition; i++) { // while not null - System.out.println(index + "." + listOfThings[index - 1]); + System.out.println(index + "." + listOfThings.get(index - 1)); index++; } } else if (command.startsWith("mark")) { // .startsWith(" ") @@ -41,7 +43,7 @@ public static void main(String[] args) { // have to parse try { - Task currentTask = listOfThings[taskNumber - 1]; + Task currentTask = listOfThings.get(taskNumber - 1); currentTask.setDone(true); System.out.println(divider); System.out.println("Great work on completing this task! Marked as done! :)"); @@ -56,7 +58,7 @@ public static void main(String[] args) { int taskNumber = Integer.parseInt(command.substring(taskNumberIndexUnmark)); try { - Task currentTask = listOfThings[taskNumber - 1]; + Task currentTask = listOfThings.get(taskNumber - 1); currentTask.setDone(false); System.out.println(divider); @@ -67,17 +69,18 @@ public static void main(String[] args) { System.out.println("That is not a valid task to unmark! Please check your list again and input a valid task"); } - } else if (command.startsWith("todo") || command.startsWith("deadline") || command.startsWith("event")) { //todo or deadline or event --> put together so don't have to repeat the same code thrice + } else if (command.startsWith("todo") || command.startsWith("deadline") || command.startsWith("event") || command.startsWith("delete")) { //todo or deadline or event or delete--> put together so don't have to repeat the same code thrice System.out.println(divider); System.out.println("Got it! I have added this task: "); if (command.startsWith("todo")) { int todoStartingIndex = 5; Todo todoBeingAdded = new Todo(command.substring(todoStartingIndex)); - listOfThings[currentPosition] = todoBeingAdded; + listOfThings.add(todoBeingAdded); // Task is not a Todo but Todo is a task System.out.println(todoBeingAdded); + currentPosition++; } else if (command.startsWith("deadline")) { int deadlineStartingIndex = 9; @@ -88,8 +91,9 @@ public static void main(String[] args) { String taskDescription = taskWithDate.substring(0, (indexOfSlash - 1)); // substring goes to the one before the second index!!!! String date = taskWithDate.substring(indexOfSlash + 4); Deadline deadlineBeingAdded = new Deadline(taskDescription, date); - listOfThings[currentPosition] = deadlineBeingAdded; + listOfThings.add(deadlineBeingAdded); System.out.println(deadlineBeingAdded); + currentPosition++; } else if (command.startsWith("event")) { int eventStartingIndex = 6; @@ -102,21 +106,22 @@ public static void main(String[] args) { String from = wholeLine.substring((indexOfFirstSlash + 6), (indexOfSecondSlash)); String to = wholeLine.substring(indexOfSecondSlash + 4); Event eventBeingAdded = new Event(taskDescription, from, to); - listOfThings[currentPosition] = eventBeingAdded; + listOfThings.add(eventBeingAdded); System.out.println(eventBeingAdded); - } //else if (command.startsWith("delete")){ - // int indexOfTaskNumber = 7; - //int taskNumberToBeDeleted = listOfThings[indexOfTaskNumber]; - - - //} - - currentPosition++; + currentPosition++; + + } else if (command.startsWith("delete")) { + int indexOfTaskNumber = 7; + int taskNumberToBeDeleted = Integer.parseInt(command.substring(indexOfTaskNumber)); + listOfThings.remove(taskNumberToBeDeleted - 1); + currentPosition--; + System.out.print("OK! Task deleted :) "); + } System.out.print("You currently have " + currentPosition); if (currentPosition == 1) { System.out.println(" task remaining! Let's finish it quickly!"); } else { - System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all three subtasks so put at the bottom + System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all four subtasks so put at the bottom } } else { System.out.println("This command does not exist! Please type a valid command!"); From 8c7e7a725933a0454479a193fbca113b7fb99821 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Mon, 20 Feb 2023 10:53:55 +0800 Subject: [PATCH 15/54] refactored code --- src/main/java/Buddy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index d3fcd8a05..f90284f3c 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -115,7 +115,7 @@ public static void main(String[] args) { int taskNumberToBeDeleted = Integer.parseInt(command.substring(indexOfTaskNumber)); listOfThings.remove(taskNumberToBeDeleted - 1); currentPosition--; - System.out.print("OK! Task deleted :) "); + System.out.print("OK! Task deleted :) Type list to see remaining tasks!"); } System.out.print("You currently have " + currentPosition); if (currentPosition == 1) { From a96996140dad8a25a96e346f04e16e462387e80a Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Tue, 28 Feb 2023 22:13:45 +0800 Subject: [PATCH 16/54] added Storage --- src/main/java/Buddy.java | 9 ++++-- src/main/java/Storage/Storage.java | 46 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/main/java/Storage/Storage.java diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 10ee56dd6..b1e1381d5 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -11,7 +11,7 @@ public class Buddy { public static void main(String[] args) { String greeting = "Hello there! I'm Buddy\n" + "How may I assist you?"; - String listOfCommands = "Here are the commands you can use: todo, deadline, event, list, mark, unmark, bye"; + String listOfCommands = "Here are the commands you can use: todo, deadline, event, list, mark, unmark, delete, bye"; String exitMessage = "Hope I was of help to you! Have a great day and see you again, Buddy :)"; String divider = "________________________________________________________________________________"; @@ -60,7 +60,7 @@ public static void main(String[] args) { currentTask.setDone(false); System.out.println(divider); - System.out.println("Remember to come back to this task! Marked as undone!"); + System.out.println("Come on, remember to come back to this task! Marked as undone!"); System.out.println(currentTask); System.out.println(divider); } catch (IndexOutOfBoundsException a) { @@ -69,12 +69,13 @@ public static void main(String[] args) { } } else if (command.startsWith("todo") || command.startsWith("deadline") || command.startsWith("event")) { //todo or deadline or event --> put together so don't have to repeat the same code thrice System.out.println(divider); - System.out.println("Got it! I have added this task: "); + if (command.startsWith("todo")) { int todoStartingIndex = 5; Todo todoBeingAdded = new Todo(command.substring(todoStartingIndex)); listOfThings[currentPosition] = todoBeingAdded; + System.out.println("Got it! I have added this task: "); // Task is not a Todo but Todo is a task System.out.println(todoBeingAdded); @@ -89,6 +90,7 @@ public static void main(String[] args) { String date = taskWithDate.substring(indexOfSlash + 4); Deadline deadlineBeingAdded = new Deadline(taskDescription, date); listOfThings[currentPosition] = deadlineBeingAdded; + System.out.println("Got it! I have added this task: "); System.out.println(deadlineBeingAdded); } else if (command.startsWith("event")) { @@ -103,6 +105,7 @@ public static void main(String[] args) { String to = wholeLine.substring(indexOfSecondSlash + 4); Event eventBeingAdded = new Event(taskDescription, from, to); listOfThings[currentPosition] = eventBeingAdded; + System.out.println("Got it! I have added this task: "); System.out.println(eventBeingAdded); } diff --git a/src/main/java/Storage/Storage.java b/src/main/java/Storage/Storage.java new file mode 100644 index 000000000..0512da399 --- /dev/null +++ b/src/main/java/Storage/Storage.java @@ -0,0 +1,46 @@ +package Storage; + +import java.io.File; +import java.io.IOException; +import java.io.FileNotFoundException; +import java.util.Scanner; +import java.util.ArrayList; + + + +public class Storage { + private final String filePath; + + + public Storage(String filePath){ + this.filePath = filePath; + } + + public void createFile() { + File newFolder = new File(filePath); + File newFile = new File(filePath + "/Buddy.txt"); + + try { + if(!newFolder.exists()){ // if folder does not exist + newFolder.mkdirs(); // creates new directory + + } + + if(!newFile.exists()){ // if file does not exist + newFile.createNewFile(); // creates new file + } + } catch (IOException e){ + System.out.println("An error occurred when creating the file :("); + e.printStackTrace(); + } + } + + public void loadData(){ + + } + + + + + +} From f8c92892ade2450a853b3cd33b29e0996456f59d Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Tue, 28 Feb 2023 22:29:40 +0800 Subject: [PATCH 17/54] resolve merge conflicts --- src/main/java/Buddy.java | 43 +++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index b1e1381d5..f90284f3c 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -1,5 +1,6 @@ import java.util.Scanner; import java.util.Arrays; +import java.util.ArrayList; // camelCase used as a coding standard // indented according to Java coding standards @@ -11,7 +12,7 @@ public class Buddy { public static void main(String[] args) { String greeting = "Hello there! I'm Buddy\n" + "How may I assist you?"; - String listOfCommands = "Here are the commands you can use: todo, deadline, event, list, mark, unmark, delete, bye"; + String listOfCommands = "Here are the commands you can use: todo, deadline, event, list, mark, unmark, bye"; String exitMessage = "Hope I was of help to you! Have a great day and see you again, Buddy :)"; String divider = "________________________________________________________________________________"; @@ -20,8 +21,9 @@ public static void main(String[] args) { System.out.println(listOfCommands); System.out.println(divider); - Task[] listOfThings = new Task[TOTAL_TASKS]; // why cannot private static? - int currentPosition = 0; // why cannot private static? + ArrayList listOfThings = new ArrayList<>(); + //Task[] listOfThings = new Task[TOTAL_TASKS]; + int currentPosition = 0; String command; Scanner in = new Scanner(System.in); command = in.nextLine(); @@ -32,7 +34,7 @@ public static void main(String[] args) { int index = 1; if (command.equals("list")) { for (int i = 0; i < currentPosition; i++) { // while not null - System.out.println(index + "." + listOfThings[index - 1]); + System.out.println(index + "." + listOfThings.get(index - 1)); index++; } } else if (command.startsWith("mark")) { // .startsWith(" ") @@ -41,7 +43,7 @@ public static void main(String[] args) { // have to parse try { - Task currentTask = listOfThings[taskNumber - 1]; + Task currentTask = listOfThings.get(taskNumber - 1); currentTask.setDone(true); System.out.println(divider); System.out.println("Great work on completing this task! Marked as done! :)"); @@ -56,29 +58,29 @@ public static void main(String[] args) { int taskNumber = Integer.parseInt(command.substring(taskNumberIndexUnmark)); try { - Task currentTask = listOfThings[taskNumber - 1]; + Task currentTask = listOfThings.get(taskNumber - 1); currentTask.setDone(false); System.out.println(divider); - System.out.println("Come on, remember to come back to this task! Marked as undone!"); + System.out.println("Remember to come back to this task! Marked as undone!"); System.out.println(currentTask); System.out.println(divider); } catch (IndexOutOfBoundsException a) { System.out.println("That is not a valid task to unmark! Please check your list again and input a valid task"); } - } else if (command.startsWith("todo") || command.startsWith("deadline") || command.startsWith("event")) { //todo or deadline or event --> put together so don't have to repeat the same code thrice + } else if (command.startsWith("todo") || command.startsWith("deadline") || command.startsWith("event") || command.startsWith("delete")) { //todo or deadline or event or delete--> put together so don't have to repeat the same code thrice System.out.println(divider); - + System.out.println("Got it! I have added this task: "); if (command.startsWith("todo")) { int todoStartingIndex = 5; Todo todoBeingAdded = new Todo(command.substring(todoStartingIndex)); - listOfThings[currentPosition] = todoBeingAdded; - System.out.println("Got it! I have added this task: "); + listOfThings.add(todoBeingAdded); // Task is not a Todo but Todo is a task System.out.println(todoBeingAdded); + currentPosition++; } else if (command.startsWith("deadline")) { int deadlineStartingIndex = 9; @@ -89,9 +91,9 @@ public static void main(String[] args) { String taskDescription = taskWithDate.substring(0, (indexOfSlash - 1)); // substring goes to the one before the second index!!!! String date = taskWithDate.substring(indexOfSlash + 4); Deadline deadlineBeingAdded = new Deadline(taskDescription, date); - listOfThings[currentPosition] = deadlineBeingAdded; - System.out.println("Got it! I have added this task: "); + listOfThings.add(deadlineBeingAdded); System.out.println(deadlineBeingAdded); + currentPosition++; } else if (command.startsWith("event")) { int eventStartingIndex = 6; @@ -104,17 +106,22 @@ public static void main(String[] args) { String from = wholeLine.substring((indexOfFirstSlash + 6), (indexOfSecondSlash)); String to = wholeLine.substring(indexOfSecondSlash + 4); Event eventBeingAdded = new Event(taskDescription, from, to); - listOfThings[currentPosition] = eventBeingAdded; - System.out.println("Got it! I have added this task: "); + listOfThings.add(eventBeingAdded); System.out.println(eventBeingAdded); + currentPosition++; + + } else if (command.startsWith("delete")) { + int indexOfTaskNumber = 7; + int taskNumberToBeDeleted = Integer.parseInt(command.substring(indexOfTaskNumber)); + listOfThings.remove(taskNumberToBeDeleted - 1); + currentPosition--; + System.out.print("OK! Task deleted :) Type list to see remaining tasks!"); } - - currentPosition++; System.out.print("You currently have " + currentPosition); if (currentPosition == 1) { System.out.println(" task remaining! Let's finish it quickly!"); } else { - System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all three subtasks so put at the bottom + System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all four subtasks so put at the bottom } } else { System.out.println("This command does not exist! Please type a valid command!"); From 5fe1586c72b048c9204e9ba84c642587cb8b75e3 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 17 Feb 2023 14:09:21 +0800 Subject: [PATCH 18/54] add delete command --- src/main/java/META-INF/MANIFEST.MF | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..df98b6161 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: main + From 9c94db05640673defa1f6065e517031e71be92d0 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 17 Feb 2023 14:15:02 +0800 Subject: [PATCH 19/54] add delete command --- src/main/java/Buddy.java | 41 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index f90284f3c..3f4e71820 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -1,6 +1,5 @@ import java.util.Scanner; import java.util.Arrays; -import java.util.ArrayList; // camelCase used as a coding standard // indented according to Java coding standards @@ -21,9 +20,8 @@ public static void main(String[] args) { System.out.println(listOfCommands); System.out.println(divider); - ArrayList listOfThings = new ArrayList<>(); - //Task[] listOfThings = new Task[TOTAL_TASKS]; - int currentPosition = 0; + Task[] listOfThings = new Task[TOTAL_TASKS]; // why cannot private static? + int currentPosition = 0; // why cannot private static? String command; Scanner in = new Scanner(System.in); command = in.nextLine(); @@ -34,7 +32,7 @@ public static void main(String[] args) { int index = 1; if (command.equals("list")) { for (int i = 0; i < currentPosition; i++) { // while not null - System.out.println(index + "." + listOfThings.get(index - 1)); + System.out.println(index + "." + listOfThings[index - 1]); index++; } } else if (command.startsWith("mark")) { // .startsWith(" ") @@ -43,7 +41,7 @@ public static void main(String[] args) { // have to parse try { - Task currentTask = listOfThings.get(taskNumber - 1); + Task currentTask = listOfThings[taskNumber - 1]; currentTask.setDone(true); System.out.println(divider); System.out.println("Great work on completing this task! Marked as done! :)"); @@ -58,7 +56,7 @@ public static void main(String[] args) { int taskNumber = Integer.parseInt(command.substring(taskNumberIndexUnmark)); try { - Task currentTask = listOfThings.get(taskNumber - 1); + Task currentTask = listOfThings[taskNumber - 1]; currentTask.setDone(false); System.out.println(divider); @@ -69,18 +67,17 @@ public static void main(String[] args) { System.out.println("That is not a valid task to unmark! Please check your list again and input a valid task"); } - } else if (command.startsWith("todo") || command.startsWith("deadline") || command.startsWith("event") || command.startsWith("delete")) { //todo or deadline or event or delete--> put together so don't have to repeat the same code thrice + } else if (command.startsWith("todo") || command.startsWith("deadline") || command.startsWith("event")) { //todo or deadline or event --> put together so don't have to repeat the same code thrice System.out.println(divider); System.out.println("Got it! I have added this task: "); if (command.startsWith("todo")) { int todoStartingIndex = 5; Todo todoBeingAdded = new Todo(command.substring(todoStartingIndex)); - listOfThings.add(todoBeingAdded); + listOfThings[currentPosition] = todoBeingAdded; // Task is not a Todo but Todo is a task System.out.println(todoBeingAdded); - currentPosition++; } else if (command.startsWith("deadline")) { int deadlineStartingIndex = 9; @@ -91,9 +88,8 @@ public static void main(String[] args) { String taskDescription = taskWithDate.substring(0, (indexOfSlash - 1)); // substring goes to the one before the second index!!!! String date = taskWithDate.substring(indexOfSlash + 4); Deadline deadlineBeingAdded = new Deadline(taskDescription, date); - listOfThings.add(deadlineBeingAdded); + listOfThings[currentPosition] = deadlineBeingAdded; System.out.println(deadlineBeingAdded); - currentPosition++; } else if (command.startsWith("event")) { int eventStartingIndex = 6; @@ -106,22 +102,21 @@ public static void main(String[] args) { String from = wholeLine.substring((indexOfFirstSlash + 6), (indexOfSecondSlash)); String to = wholeLine.substring(indexOfSecondSlash + 4); Event eventBeingAdded = new Event(taskDescription, from, to); - listOfThings.add(eventBeingAdded); + listOfThings[currentPosition] = eventBeingAdded; System.out.println(eventBeingAdded); - currentPosition++; - - } else if (command.startsWith("delete")) { - int indexOfTaskNumber = 7; - int taskNumberToBeDeleted = Integer.parseInt(command.substring(indexOfTaskNumber)); - listOfThings.remove(taskNumberToBeDeleted - 1); - currentPosition--; - System.out.print("OK! Task deleted :) Type list to see remaining tasks!"); - } + } //else if (command.startsWith("delete")){ + // int indexOfTaskNumber = 7; + //int taskNumberToBeDeleted = listOfThings[indexOfTaskNumber]; + + + //} + + currentPosition++; System.out.print("You currently have " + currentPosition); if (currentPosition == 1) { System.out.println(" task remaining! Let's finish it quickly!"); } else { - System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all four subtasks so put at the bottom + System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all three subtasks so put at the bottom } } else { System.out.println("This command does not exist! Please type a valid command!"); From cca85127c5a20e12a4aba62761ce25a0c04247a5 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Sun, 19 Feb 2023 23:24:09 +0800 Subject: [PATCH 20/54] Changed to array list + Added Level 6 --- src/main/java/Buddy.java | 41 ++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 3f4e71820..d3fcd8a05 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -1,5 +1,6 @@ import java.util.Scanner; import java.util.Arrays; +import java.util.ArrayList; // camelCase used as a coding standard // indented according to Java coding standards @@ -20,8 +21,9 @@ public static void main(String[] args) { System.out.println(listOfCommands); System.out.println(divider); - Task[] listOfThings = new Task[TOTAL_TASKS]; // why cannot private static? - int currentPosition = 0; // why cannot private static? + ArrayList listOfThings = new ArrayList<>(); + //Task[] listOfThings = new Task[TOTAL_TASKS]; + int currentPosition = 0; String command; Scanner in = new Scanner(System.in); command = in.nextLine(); @@ -32,7 +34,7 @@ public static void main(String[] args) { int index = 1; if (command.equals("list")) { for (int i = 0; i < currentPosition; i++) { // while not null - System.out.println(index + "." + listOfThings[index - 1]); + System.out.println(index + "." + listOfThings.get(index - 1)); index++; } } else if (command.startsWith("mark")) { // .startsWith(" ") @@ -41,7 +43,7 @@ public static void main(String[] args) { // have to parse try { - Task currentTask = listOfThings[taskNumber - 1]; + Task currentTask = listOfThings.get(taskNumber - 1); currentTask.setDone(true); System.out.println(divider); System.out.println("Great work on completing this task! Marked as done! :)"); @@ -56,7 +58,7 @@ public static void main(String[] args) { int taskNumber = Integer.parseInt(command.substring(taskNumberIndexUnmark)); try { - Task currentTask = listOfThings[taskNumber - 1]; + Task currentTask = listOfThings.get(taskNumber - 1); currentTask.setDone(false); System.out.println(divider); @@ -67,17 +69,18 @@ public static void main(String[] args) { System.out.println("That is not a valid task to unmark! Please check your list again and input a valid task"); } - } else if (command.startsWith("todo") || command.startsWith("deadline") || command.startsWith("event")) { //todo or deadline or event --> put together so don't have to repeat the same code thrice + } else if (command.startsWith("todo") || command.startsWith("deadline") || command.startsWith("event") || command.startsWith("delete")) { //todo or deadline or event or delete--> put together so don't have to repeat the same code thrice System.out.println(divider); System.out.println("Got it! I have added this task: "); if (command.startsWith("todo")) { int todoStartingIndex = 5; Todo todoBeingAdded = new Todo(command.substring(todoStartingIndex)); - listOfThings[currentPosition] = todoBeingAdded; + listOfThings.add(todoBeingAdded); // Task is not a Todo but Todo is a task System.out.println(todoBeingAdded); + currentPosition++; } else if (command.startsWith("deadline")) { int deadlineStartingIndex = 9; @@ -88,8 +91,9 @@ public static void main(String[] args) { String taskDescription = taskWithDate.substring(0, (indexOfSlash - 1)); // substring goes to the one before the second index!!!! String date = taskWithDate.substring(indexOfSlash + 4); Deadline deadlineBeingAdded = new Deadline(taskDescription, date); - listOfThings[currentPosition] = deadlineBeingAdded; + listOfThings.add(deadlineBeingAdded); System.out.println(deadlineBeingAdded); + currentPosition++; } else if (command.startsWith("event")) { int eventStartingIndex = 6; @@ -102,21 +106,22 @@ public static void main(String[] args) { String from = wholeLine.substring((indexOfFirstSlash + 6), (indexOfSecondSlash)); String to = wholeLine.substring(indexOfSecondSlash + 4); Event eventBeingAdded = new Event(taskDescription, from, to); - listOfThings[currentPosition] = eventBeingAdded; + listOfThings.add(eventBeingAdded); System.out.println(eventBeingAdded); - } //else if (command.startsWith("delete")){ - // int indexOfTaskNumber = 7; - //int taskNumberToBeDeleted = listOfThings[indexOfTaskNumber]; - - - //} - - currentPosition++; + currentPosition++; + + } else if (command.startsWith("delete")) { + int indexOfTaskNumber = 7; + int taskNumberToBeDeleted = Integer.parseInt(command.substring(indexOfTaskNumber)); + listOfThings.remove(taskNumberToBeDeleted - 1); + currentPosition--; + System.out.print("OK! Task deleted :) "); + } System.out.print("You currently have " + currentPosition); if (currentPosition == 1) { System.out.println(" task remaining! Let's finish it quickly!"); } else { - System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all three subtasks so put at the bottom + System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all four subtasks so put at the bottom } } else { System.out.println("This command does not exist! Please type a valid command!"); From 8d246b722f6a255241e36783cf250ec5e9657df2 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Mon, 20 Feb 2023 10:53:55 +0800 Subject: [PATCH 21/54] refactored code --- src/main/java/Buddy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index d3fcd8a05..f90284f3c 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -115,7 +115,7 @@ public static void main(String[] args) { int taskNumberToBeDeleted = Integer.parseInt(command.substring(indexOfTaskNumber)); listOfThings.remove(taskNumberToBeDeleted - 1); currentPosition--; - System.out.print("OK! Task deleted :) "); + System.out.print("OK! Task deleted :) Type list to see remaining tasks!"); } System.out.print("You currently have " + currentPosition); if (currentPosition == 1) { From 678f733196565ec158e3b2c9727be4d9a195ff89 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Tue, 28 Feb 2023 23:20:16 +0800 Subject: [PATCH 22/54] delete branch 7 to make it easier --- src/main/java/Buddy.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index f90284f3c..a23e4f067 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -22,7 +22,6 @@ public static void main(String[] args) { System.out.println(divider); ArrayList listOfThings = new ArrayList<>(); - //Task[] listOfThings = new Task[TOTAL_TASKS]; int currentPosition = 0; String command; Scanner in = new Scanner(System.in); @@ -37,10 +36,10 @@ public static void main(String[] args) { System.out.println(index + "." + listOfThings.get(index - 1)); index++; } - } else if (command.startsWith("mark")) { // .startsWith(" ") + } else if (command.startsWith("mark")) { int taskNumberIndexMark = 5; int taskNumber = Integer.parseInt(command.substring(taskNumberIndexMark)); - // have to parse + try { Task currentTask = listOfThings.get(taskNumber - 1); From 154b006c7691b28af320f0fe51613d218ae1dda7 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Wed, 1 Mar 2023 00:36:35 +0800 Subject: [PATCH 23/54] Done till Level 6 --- src/main/java/Buddy.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index f90284f3c..0e11ca38a 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -1,5 +1,4 @@ import java.util.Scanner; -import java.util.Arrays; import java.util.ArrayList; // camelCase used as a coding standard From a6e5092fe2606a4c3891236e81fa669a07dc3946 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Wed, 1 Mar 2023 16:22:26 +0800 Subject: [PATCH 24/54] Testing --- src/main/.idea/.gitignore | 8 ++++++++ src/main/.idea/misc.xml | 6 ++++++ src/main/.idea/modules.xml | 8 ++++++++ src/main/.idea/vcs.xml | 6 ++++++ src/main/java/Buddy.java | 5 +---- src/main/java/{Storage => }/Storage.java | 5 ++--- 6 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 src/main/.idea/.gitignore create mode 100644 src/main/.idea/misc.xml create mode 100644 src/main/.idea/modules.xml create mode 100644 src/main/.idea/vcs.xml rename src/main/java/{Storage => }/Storage.java (98%) diff --git a/src/main/.idea/.gitignore b/src/main/.idea/.gitignore new file mode 100644 index 000000000..13566b81b --- /dev/null +++ b/src/main/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/src/main/.idea/misc.xml b/src/main/.idea/misc.xml new file mode 100644 index 000000000..639900d13 --- /dev/null +++ b/src/main/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/.idea/modules.xml b/src/main/.idea/modules.xml new file mode 100644 index 000000000..122a9054e --- /dev/null +++ b/src/main/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/.idea/vcs.xml b/src/main/.idea/vcs.xml new file mode 100644 index 000000000..b2bdec2d7 --- /dev/null +++ b/src/main/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 0e11ca38a..38deb8853 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -1,12 +1,10 @@ import java.util.Scanner; import java.util.ArrayList; -// camelCase used as a coding standard -// indented according to Java coding standards + public class Buddy { - static final int TOTAL_TASKS = 100; public static void main(String[] args) { String greeting = "Hello there! I'm Buddy\n" @@ -21,7 +19,6 @@ public static void main(String[] args) { System.out.println(divider); ArrayList listOfThings = new ArrayList<>(); - //Task[] listOfThings = new Task[TOTAL_TASKS]; int currentPosition = 0; String command; Scanner in = new Scanner(System.in); diff --git a/src/main/java/Storage/Storage.java b/src/main/java/Storage.java similarity index 98% rename from src/main/java/Storage/Storage.java rename to src/main/java/Storage.java index 0512da399..336583f6d 100644 --- a/src/main/java/Storage/Storage.java +++ b/src/main/java/Storage.java @@ -1,5 +1,3 @@ -package Storage; - import java.io.File; import java.io.IOException; import java.io.FileNotFoundException; @@ -7,7 +5,6 @@ import java.util.ArrayList; - public class Storage { private final String filePath; @@ -37,6 +34,8 @@ public void createFile() { public void loadData(){ + + } From 34f8b0d6b5b0751a0ed54b6d90450d5823d2c524 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Thu, 2 Mar 2023 18:09:23 +0800 Subject: [PATCH 25/54] SAVE FINALLY WORKS WOHOO --- src/main/java/Buddy.java | 46 +++++++++++---- src/main/java/Deadline.java | 11 ++++ src/main/java/Event.java | 11 ++++ src/main/java/Storage.java | 113 +++++++++++++++++++++++++++++------- src/main/java/Task.java | 25 ++++++-- src/main/java/Todo.java | 5 ++ 6 files changed, 173 insertions(+), 38 deletions(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index ff295253e..bd360878f 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -1,12 +1,29 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; import java.util.Scanner; import java.util.ArrayList; - +import java.io.FileWriter; +import java.text.ParseException; +import java.util.zip.DataFormatException; public class Buddy { + public static int taskCount = 0; + public static void main(String[] args) { + ArrayList listOfThings = new ArrayList<>(); + try{ + Storage.loadFile(listOfThings); + + } catch (FileNotFoundException e){ + System.out.println("File not found"); + Storage.createFile(); + + } + String greeting = "Hello there! I'm Buddy\n" + "How may I assist you?"; String listOfCommands = "Here are the commands you can use: todo, deadline, event, list, mark, unmark, bye"; @@ -18,18 +35,19 @@ public static void main(String[] args) { System.out.println(listOfCommands); System.out.println(divider); - ArrayList listOfThings = new ArrayList<>(); - int currentPosition = 0; + + String command; Scanner in = new Scanner(System.in); command = in.nextLine(); + while (!command.equals("bye")) { int index = 1; if (command.equals("list")) { - for (int i = 0; i < currentPosition; i++) { // while not null + for (int i = 0; i < taskCount; i++) { // while not null System.out.println(index + "." + listOfThings.get(index - 1)); index++; } @@ -74,9 +92,8 @@ public static void main(String[] args) { Todo todoBeingAdded = new Todo(command.substring(todoStartingIndex)); listOfThings.add(todoBeingAdded); - // Task is not a Todo but Todo is a task System.out.println(todoBeingAdded); - currentPosition++; + taskCount++; } else if (command.startsWith("deadline")) { int deadlineStartingIndex = 9; @@ -89,7 +106,7 @@ public static void main(String[] args) { Deadline deadlineBeingAdded = new Deadline(taskDescription, date); listOfThings.add(deadlineBeingAdded); System.out.println(deadlineBeingAdded); - currentPosition++; + taskCount++; } else if (command.startsWith("event")) { int eventStartingIndex = 6; @@ -104,17 +121,17 @@ public static void main(String[] args) { Event eventBeingAdded = new Event(taskDescription, from, to); listOfThings.add(eventBeingAdded); System.out.println(eventBeingAdded); - currentPosition++; + taskCount++; } else if (command.startsWith("delete")) { int indexOfTaskNumber = 7; int taskNumberToBeDeleted = Integer.parseInt(command.substring(indexOfTaskNumber)); listOfThings.remove(taskNumberToBeDeleted - 1); - currentPosition--; + taskCount--; System.out.print("OK! Task deleted :) Type list to see remaining tasks!"); } - System.out.print("You currently have " + currentPosition); - if (currentPosition == 1) { + System.out.print("You currently have " + taskCount); + if (taskCount == 1) { System.out.println(" task remaining! Let's finish it quickly!"); } else { System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all four subtasks so put at the bottom @@ -125,6 +142,13 @@ public static void main(String[] args) { command = in.nextLine(); } + try{ + Storage.updateFile(listOfThings); + + } catch(IOException e){ + System.out.println("Error occurred"); + } + System.out.println(divider); System.out.println(exitMessage); System.out.println(divider); diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 0ff576079..181b95d6c 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -7,6 +7,17 @@ public Deadline(String description, String by) { this.by = by; } + public String getDeadline(){ + return by; + } + + @Override + public String getType(){ + return "D"; + } + + + @Override public String toString() { return "[D]" + super.toString() + " (Please do by: " + by + "!)"; diff --git a/src/main/java/Event.java b/src/main/java/Event.java index bb20f2825..17e647b50 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -9,6 +9,17 @@ public Event(String description, String from, String to) { this.to = to; } + public String getStart(){ + return this.from; + } + public String getEnd(){ + return this.to; + } + + @Override + public String getType(){ + return "E"; + } @Override public String toString() { return "[E]" + super.toString() + " (from: " + from + "to: " + to + ")"; diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 336583f6d..46ff9007c 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -1,45 +1,116 @@ import java.io.File; -import java.io.IOException; import java.io.FileNotFoundException; -import java.util.Scanner; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; +import java.util.Scanner; public class Storage { - private final String filePath; - - public Storage(String filePath){ - this.filePath = filePath; - } - - public void createFile() { - File newFolder = new File(filePath); - File newFile = new File(filePath + "/Buddy.txt"); + public static void createFile() { + //File directory = new File("Buddy.txt"); + File newFile = new File("Buddy.txt"); try { - if(!newFolder.exists()){ // if folder does not exist - newFolder.mkdirs(); // creates new directory - + //if(directory.mkdirs()){ + // System.out.println("Directory has been created :)"); + // } + //else { + // System.out.println("Directory exists already!"); + // } + + if (newFile.createNewFile()) { + System.out.println("File has been created :)"); + } else { + System.out.println("File already exists"); } - - if(!newFile.exists()){ // if file does not exist - newFile.createNewFile(); // creates new file - } - } catch (IOException e){ + } catch (IOException e) { System.out.println("An error occurred when creating the file :("); e.printStackTrace(); } } - public void loadData(){ - + public static void updateFile(ArrayList taskList) throws IOException { + /*try { + createFile(); + } catch (IOException e) { + System.out.println("Error occurred as the file probably exists"); + }*/ + FileWriter overwriteFile = new FileWriter("Buddy.txt"); + for (Task task : taskList) { + String taskType = task.getType(); + String taskName = task.getTaskName(); + String taskStatus = task.getStatusIcon(); + + switch (taskType) { + case "T": + overwriteFile.write(taskType + "$" + taskStatus + "$" + taskName + "\n"); + break; + case "D": + Deadline deadlineTask = (Deadline) task; + overwriteFile.write(taskType + "$" + taskStatus + "$" + taskName + "$" + deadlineTask.getDeadline() + "\n"); + break; + case "E": + Event eventTask = (Event) task; + overwriteFile.write(taskType + "$" + taskStatus + "$" + taskName + "$" + eventTask.getStart() + "$" + eventTask.getEnd() + "\n"); + break; + default: + } + } + overwriteFile.close(); } + public static void loadFile(ArrayList taskList) throws FileNotFoundException { + File file = new File("Buddy.txt"); + Scanner s = new Scanner(file); + while (s.hasNext()) { + String line = s.nextLine(); + String[] taskElements = line.split("\\$"); + String taskType = taskElements[0].trim(); + String taskStatus = taskElements[1].trim(); + String taskName = taskElements[2].trim(); + + switch (taskType) { + case "T": + Todo newTodo = new Todo(taskName); + if (taskStatus.equals("X")) { + newTodo.setDone(true); + } + taskList.add(newTodo); + Buddy.taskCount++; + break; + + case "D": + String deadline = taskElements[3].trim(); + Deadline newDeadline = new Deadline(taskName, deadline); + if (taskStatus.equals("X")) { + newDeadline.setDone(true); + } + taskList.add(newDeadline); + Buddy.taskCount++; + break; + + case "E": + String start = taskElements[3].trim(); + String end = taskElements[4].trim(); + Event newEvent = new Event(taskName, start, end); + + if (taskStatus.equals("X")) { + newEvent.setDone(true); + } + taskList.add(newEvent); + Buddy.taskCount++; + break; + default: + } + } + } + } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 29248228d..9efb5c481 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,25 +1,38 @@ public class Task { protected String description; - protected boolean isDone; // protected => public + protected boolean isDone; + protected String type; public Task(String description) { this.description = description; this.isDone = false; } - public String getStatusIcon() { - return (isDone ? "X" : " "); // mark done task with X + public String getTaskName(){ + return this.description; + } + + public String getType(){ + return ""; } - public boolean isDone() { // do we need this - return isDone; + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X } public void setDone(boolean isDone) { this.isDone = isDone; } - @Override // overrides --> print task prints this! + public void markAsDone(){ + this.isDone = true; + } + + public void markAsUndone(){ + this.isDone = false; + } + + @Override public String toString() { return "[" + this.getStatusIcon() + "] " + this.description; } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index c8013d573..6fd392806 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -4,6 +4,11 @@ public Todo(String description) { super(description); // don't need isDone as isDone is already in Task class } + @Override + public String getType(){ + return "T"; + } + @Override public String toString() { return "[T]" + super.toString(); From 91858cb154e2fe8bab4ba337f02e59888dfd177d Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Thu, 2 Mar 2023 18:37:53 +0800 Subject: [PATCH 26/54] Working JAR File --- src/main/java/META-INF/MANIFEST.MF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF index df98b6161..90913dd96 100644 --- a/src/main/java/META-INF/MANIFEST.MF +++ b/src/main/java/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ Manifest-Version: 1.0 -Main-Class: main +Main-Class: Buddy From b7593c63be4324f9b5c90bfee09ef080f9f767bd Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Thu, 2 Mar 2023 18:38:21 +0800 Subject: [PATCH 27/54] Working JAR File --- Buddy.txt | 1 + src/main/java/Buddy.java | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) create mode 100644 Buddy.txt diff --git a/Buddy.txt b/Buddy.txt new file mode 100644 index 000000000..0610bc886 --- /dev/null +++ b/Buddy.txt @@ -0,0 +1 @@ +T$X$hi diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index bd360878f..b24c5af66 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -11,14 +11,12 @@ public class Buddy { public static int taskCount = 0; - - public static void main(String[] args) { ArrayList listOfThings = new ArrayList<>(); - try{ + try { Storage.loadFile(listOfThings); - } catch (FileNotFoundException e){ + } catch (FileNotFoundException e) { System.out.println("File not found"); Storage.createFile(); @@ -36,13 +34,11 @@ public static void main(String[] args) { System.out.println(divider); - String command; Scanner in = new Scanner(System.in); command = in.nextLine(); - while (!command.equals("bye")) { int index = 1; @@ -142,10 +138,10 @@ public static void main(String[] args) { command = in.nextLine(); } - try{ + try { Storage.updateFile(listOfThings); - } catch(IOException e){ + } catch (IOException e) { System.out.println("Error occurred"); } From 5c84e0b2a4c18bbaaca7847e1e13f2594b403c6d Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Thu, 2 Mar 2023 20:06:32 +0800 Subject: [PATCH 28/54] FIND function implemented --- Buddy.txt | 1 - src/main/java/Buddy.java | 27 ++++++++++++++++++++++++--- src/main/java/Storage.java | 2 ++ 3 files changed, 26 insertions(+), 4 deletions(-) delete mode 100644 Buddy.txt diff --git a/Buddy.txt b/Buddy.txt deleted file mode 100644 index 0610bc886..000000000 --- a/Buddy.txt +++ /dev/null @@ -1 +0,0 @@ -T$X$hi diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index b24c5af66..8fc2db569 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -4,8 +4,8 @@ import java.util.Scanner; import java.util.ArrayList; import java.io.FileWriter; -import java.text.ParseException; -import java.util.zip.DataFormatException; +import java.util.stream.Collectors; +import static java.util.stream.Collectors.toList; public class Buddy { @@ -79,7 +79,7 @@ public static void main(String[] args) { System.out.println("That is not a valid task to unmark! Please check your list again and input a valid task"); } - } else if (command.startsWith("todo") || command.startsWith("deadline") || command.startsWith("event") || command.startsWith("delete")) { //todo or deadline or event or delete--> put together so don't have to repeat the same code thrice + } else if (command.startsWith("todo") || command.startsWith("deadline") || command.startsWith("event") || command.startsWith("delete") || command.startsWith("find")) { //todo or deadline or event or delete--> put together so don't have to repeat the same code thrice System.out.println(divider); System.out.println("Got it! I have added this task: "); if (command.startsWith("todo")) { @@ -125,6 +125,27 @@ public static void main(String[] args) { listOfThings.remove(taskNumberToBeDeleted - 1); taskCount--; System.out.print("OK! Task deleted :) Type list to see remaining tasks!"); + } else if (command.startsWith("find")){ + String keyword = command.split(" ")[1].trim().toLowerCase(); + ArrayList matchedTasks = new ArrayList<>(); + matchedTasks = (ArrayList) listOfThings.stream() // casts list to ArrayList + .filter(t -> t.getTaskName().trim().toLowerCase().contains(keyword)).collect(toList()); + if (!matchedTasks.isEmpty()){ + System.out.println("Well, I found these matching tasks in your list!"); + } + for (Task task : matchedTasks){ + + System.out.println(task); + + } + if (matchedTasks.isEmpty()){ + System.out.println("Oops, there are no tasks matching the keyword! Try again with another keyword"); + } + + + + + } System.out.print("You currently have " + taskCount); if (taskCount == 1) { diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 46ff9007c..087ba3a67 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -4,6 +4,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; +import java.text.ParseException; +import java.util.zip.DataFormatException; public class Storage { From 999cf72ff3826cf8395fd070f1da1a620f28c099 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 00:44:53 +0800 Subject: [PATCH 29/54] Added Task List Class which works!! --- src/main/java/Buddy.java | 93 ++++++++++++++-------------------- src/main/java/Command.java | 11 ++++ src/main/java/Task.java | 23 +++++++++ src/main/java/TaskList.java | 21 ++++++++ src/main/java/TodoCommand.java | 9 ++++ 5 files changed, 103 insertions(+), 54 deletions(-) create mode 100644 src/main/java/Command.java create mode 100644 src/main/java/TaskList.java create mode 100644 src/main/java/TodoCommand.java diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 8fc2db569..20aa08fc5 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -10,11 +10,12 @@ public class Buddy { public static int taskCount = 0; + public static String divider = "________________________________________________________________________________"; public static void main(String[] args) { - ArrayList listOfThings = new ArrayList<>(); + TaskList taskList = new TaskList(); try { - Storage.loadFile(listOfThings); + Storage.loadFile(taskList); } catch (FileNotFoundException e) { System.out.println("File not found"); @@ -26,7 +27,7 @@ public static void main(String[] args) { + "How may I assist you?"; String listOfCommands = "Here are the commands you can use: todo, deadline, event, list, mark, unmark, bye"; String exitMessage = "Hope I was of help to you! Have a great day and see you again, Buddy :)"; - String divider = "________________________________________________________________________________"; + System.out.println(divider); System.out.println(greeting); @@ -34,26 +35,26 @@ public static void main(String[] args) { System.out.println(divider); - String command; + String input; Scanner in = new Scanner(System.in); - command = in.nextLine(); + input = in.nextLine(); - while (!command.equals("bye")) { + while (!input.equals("bye")) { int index = 1; - if (command.equals("list")) { + if (input.equals("list")) { for (int i = 0; i < taskCount; i++) { // while not null - System.out.println(index + "." + listOfThings.get(index - 1)); + System.out.println(index + "." + taskList.get(index - 1)); index++; } - } else if (command.startsWith("mark")) { + } else if (input.startsWith("mark")) { int taskNumberIndexMark = 5; - int taskNumber = Integer.parseInt(command.substring(taskNumberIndexMark)); + int taskNumber = Integer.parseInt(input.substring(taskNumberIndexMark)); try { - Task currentTask = listOfThings.get(taskNumber - 1); + Task currentTask = taskList.get(taskNumber - 1); currentTask.setDone(true); System.out.println(divider); System.out.println("Great work on completing this task! Marked as done! :)"); @@ -63,12 +64,12 @@ public static void main(String[] args) { System.out.println("That is not a valid task to mark! Please check your list again and input a valid task"); } - } else if (command.startsWith("unmark")) { + } else if (input.startsWith("unmark")) { int taskNumberIndexUnmark = 7; - int taskNumber = Integer.parseInt(command.substring(taskNumberIndexUnmark)); + int taskNumber = Integer.parseInt(input.substring(taskNumberIndexUnmark)); try { - Task currentTask = listOfThings.get(taskNumber - 1); + Task currentTask = taskList.get(taskNumber - 1); currentTask.setDone(false); System.out.println(divider); @@ -79,34 +80,29 @@ public static void main(String[] args) { System.out.println("That is not a valid task to unmark! Please check your list again and input a valid task"); } - } else if (command.startsWith("todo") || command.startsWith("deadline") || command.startsWith("event") || command.startsWith("delete") || command.startsWith("find")) { //todo or deadline or event or delete--> put together so don't have to repeat the same code thrice - System.out.println(divider); - System.out.println("Got it! I have added this task: "); - if (command.startsWith("todo")) { - int todoStartingIndex = 5; + } else if (input.startsWith("todo") || input.startsWith("deadline") || input.startsWith("event") || input.startsWith("delete") || input.startsWith("find")) { - Todo todoBeingAdded = new Todo(command.substring(todoStartingIndex)); - listOfThings.add(todoBeingAdded); + if (input.startsWith("todo")) { + int todoStartingIndex = 5; - System.out.println(todoBeingAdded); - taskCount++; + Todo todoBeingAdded = new Todo(input.substring(todoStartingIndex)); + taskList.addTask(todoBeingAdded); - } else if (command.startsWith("deadline")) { + } else if (input.startsWith("deadline")) { int deadlineStartingIndex = 9; - Task taskBeingAdded = new Task(command.substring(deadlineStartingIndex)); // task + date + slash (Description) + Task taskBeingAdded = new Task(input.substring(deadlineStartingIndex)); // task + date + slash (Description) // filter the description and date String taskWithDate = taskBeingAdded.description; int indexOfSlash = taskWithDate.indexOf('/'); String taskDescription = taskWithDate.substring(0, (indexOfSlash - 1)); // substring goes to the one before the second index!!!! String date = taskWithDate.substring(indexOfSlash + 4); Deadline deadlineBeingAdded = new Deadline(taskDescription, date); - listOfThings.add(deadlineBeingAdded); - System.out.println(deadlineBeingAdded); - taskCount++; + taskList.addTask(deadlineBeingAdded); - } else if (command.startsWith("event")) { + + } else if (input.startsWith("event")) { int eventStartingIndex = 6; - Task taskBeingAdded = new Task(command.substring(eventStartingIndex)); + Task taskBeingAdded = new Task(input.substring(eventStartingIndex)); // filter the description, from and to String wholeLine = taskBeingAdded.description; int indexOfFirstSlash = wholeLine.indexOf('/'); @@ -115,20 +111,18 @@ public static void main(String[] args) { String from = wholeLine.substring((indexOfFirstSlash + 6), (indexOfSecondSlash)); String to = wholeLine.substring(indexOfSecondSlash + 4); Event eventBeingAdded = new Event(taskDescription, from, to); - listOfThings.add(eventBeingAdded); - System.out.println(eventBeingAdded); - taskCount++; + taskList.addTask(eventBeingAdded); + - } else if (command.startsWith("delete")) { + } else if (input.startsWith("delete")) { int indexOfTaskNumber = 7; - int taskNumberToBeDeleted = Integer.parseInt(command.substring(indexOfTaskNumber)); - listOfThings.remove(taskNumberToBeDeleted - 1); - taskCount--; - System.out.print("OK! Task deleted :) Type list to see remaining tasks!"); - } else if (command.startsWith("find")){ - String keyword = command.split(" ")[1].trim().toLowerCase(); + int taskNumberToBeDeleted = Integer.parseInt(input.substring(indexOfTaskNumber)); + taskList.deleteTask(taskNumberToBeDeleted - 1); + + } else if (input.startsWith("find")){ + String keyword = input.split(" ")[1].trim().toLowerCase(); ArrayList matchedTasks = new ArrayList<>(); - matchedTasks = (ArrayList) listOfThings.stream() // casts list to ArrayList + matchedTasks = (ArrayList) taskList.stream() // casts list to ArrayList .filter(t -> t.getTaskName().trim().toLowerCase().contains(keyword)).collect(toList()); if (!matchedTasks.isEmpty()){ System.out.println("Well, I found these matching tasks in your list!"); @@ -142,25 +136,16 @@ public static void main(String[] args) { System.out.println("Oops, there are no tasks matching the keyword! Try again with another keyword"); } - - - - - } - System.out.print("You currently have " + taskCount); - if (taskCount == 1) { - System.out.println(" task remaining! Let's finish it quickly!"); - } else { - System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all four subtasks so put at the bottom } + } else { - System.out.println("This command does not exist! Please type a valid command!"); + System.out.println("This input does not exist! Please type a valid input!"); } - command = in.nextLine(); + input = in.nextLine(); } try { - Storage.updateFile(listOfThings); + Storage.updateFile(taskList); } catch (IOException e) { System.out.println("Error occurred"); diff --git a/src/main/java/Command.java b/src/main/java/Command.java new file mode 100644 index 000000000..9fc4956a6 --- /dev/null +++ b/src/main/java/Command.java @@ -0,0 +1,11 @@ +import java.util.ArrayList; +import java.text.ParseException; +import java.util.zip.DataFormatException; + + +public abstract class Command { + public void executeCommand(ArrayList taskList, String input){ + + } + +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 9efb5c481..388a2e167 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -36,4 +36,27 @@ public void markAsUndone(){ public String toString() { return "[" + this.getStatusIcon() + "] " + this.description; } + + public void printAfterAddingTask(){ + if (Buddy.taskCount == 1){ + System.out.println("Got it! I have added this task!: \n" + this + "\n" + "Now you have " + Buddy.taskCount + " task remaining! Almost there, buddy!"); + } + else{ + System.out.println("Got it! I have added this task! \n" + this + "\n" + "Now you have " + Buddy.taskCount + " tasks remaining! Let's finish them faster and relax!"); + + } + + } + + public void printAfterDeletingTask() { + if (Buddy.taskCount == 0) { + System.out.println( "OK I have deleted this task!: \n" + this + "\n" + "CONGRATS BUDDY ON FINISHING ALL YOUR TASKS! TIME TO RELAX WITH YOUR FRIENDS AND FAMILY! :)"); + } else if (Buddy.taskCount == 1) { + System.out.println("YAY ONE LESS TO GO! I have deleted this task!: \n" + this + "\n" + "Now you have JUST " + Buddy.taskCount + " task remaining! CHOP CHOP FINISH IT"); + } else{ + System.out.println("YAY ONE LESS TO GO! I have deleted this task!: \n" + this + "\n" + "Now you have " + Buddy.taskCount + " tasks remaining! Type list to see remaining tasks"); + + } + } + } diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 000000000..8ae0ca6d5 --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,21 @@ +import java.util.ArrayList; + +public class TaskList extends ArrayList { + public void addTask (Task newTask){ + System.out.println(Buddy.divider); + this.add(newTask); // new task is added to taskList + Buddy.taskCount++; // increments number of tasks + newTask.printAfterAddingTask(); // print message once new task is added (From Task class) + System.out.println(Buddy.divider); + } + + public void deleteTask (int indexOfTaskToDelete){ + System.out.println(Buddy.divider); + Task taskToBeDeleted = this.get(indexOfTaskToDelete); + Buddy.taskCount--; // decrements number of tasks + taskToBeDeleted.printAfterDeletingTask(); + this.remove(indexOfTaskToDelete); // delete task from taskList + System.out.println(Buddy.divider); + + } +} diff --git a/src/main/java/TodoCommand.java b/src/main/java/TodoCommand.java new file mode 100644 index 000000000..fbcbc9b38 --- /dev/null +++ b/src/main/java/TodoCommand.java @@ -0,0 +1,9 @@ +import java.util.ArrayList; + +/* +public class TodoCommand extends Command{ + @Override + public void executeCommand(ArrayList taskList, String input) { + taskList.addTask + } +}*/ From 8a086b7fa45b56b1d05572ebc030a4bb547f94e5 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 01:24:47 +0800 Subject: [PATCH 30/54] Added the different Task Command Classes --- src/main/java/Command.java | 5 +---- src/main/java/TodoCommand.java | 9 --------- src/main/java/addDeadlineCommand.java | 13 +++++++++++++ src/main/java/addEventCommand.java | 14 ++++++++++++++ src/main/java/addTodoCommand.java | 10 ++++++++++ 5 files changed, 38 insertions(+), 13 deletions(-) delete mode 100644 src/main/java/TodoCommand.java create mode 100644 src/main/java/addDeadlineCommand.java create mode 100644 src/main/java/addEventCommand.java create mode 100644 src/main/java/addTodoCommand.java diff --git a/src/main/java/Command.java b/src/main/java/Command.java index 9fc4956a6..9f6dd7389 100644 --- a/src/main/java/Command.java +++ b/src/main/java/Command.java @@ -4,8 +4,5 @@ public abstract class Command { - public void executeCommand(ArrayList taskList, String input){ - - } - + public abstract void executeCommand(TaskList taskList, String input); // executes the commands differently based on the various types of commands } diff --git a/src/main/java/TodoCommand.java b/src/main/java/TodoCommand.java deleted file mode 100644 index fbcbc9b38..000000000 --- a/src/main/java/TodoCommand.java +++ /dev/null @@ -1,9 +0,0 @@ -import java.util.ArrayList; - -/* -public class TodoCommand extends Command{ - @Override - public void executeCommand(ArrayList taskList, String input) { - taskList.addTask - } -}*/ diff --git a/src/main/java/addDeadlineCommand.java b/src/main/java/addDeadlineCommand.java new file mode 100644 index 000000000..77ea78bf7 --- /dev/null +++ b/src/main/java/addDeadlineCommand.java @@ -0,0 +1,13 @@ + + +public class addDeadlineCommand extends Command{ + @Override + public void executeCommand(TaskList taskList, String input) { + String[] deadlineSplit = input.split("/by", 2); + String deadlineBy = deadlineSplit[1]; + String[] deadlineAndName = deadlineSplit[0].split(" ", 2); + String deadlineName = deadlineAndName[1]; + Deadline deadlineBeingAdded = new Deadline(deadlineName, deadlineBy); + taskList.addTask(deadlineBeingAdded); + } +} \ No newline at end of file diff --git a/src/main/java/addEventCommand.java b/src/main/java/addEventCommand.java new file mode 100644 index 000000000..25beacb10 --- /dev/null +++ b/src/main/java/addEventCommand.java @@ -0,0 +1,14 @@ +public class addEventCommand extends Command { + @Override + public void executeCommand(TaskList taskList, String input) { + String[] eventSplit = input.split("/", 3); + String[] eventAndName= eventSplit[0].split(" ", '2'); + String eventName = eventAndName[1]; + String[] fromAndStart = eventSplit[1].split(" ", '2'); + String start = fromAndStart[1]; + String[] toAndEnd = eventSplit[2].split(" ", '2'); + String end = toAndEnd[1]; + Event eventBeingAdded = new Event(eventName, start, end); + taskList.addTask(eventBeingAdded); + } +} diff --git a/src/main/java/addTodoCommand.java b/src/main/java/addTodoCommand.java new file mode 100644 index 000000000..d22739a11 --- /dev/null +++ b/src/main/java/addTodoCommand.java @@ -0,0 +1,10 @@ + + +public class addTodoCommand extends Command{ + @Override + public void executeCommand(TaskList taskList, String input) { + String[] todoSplit = input.split(" ", 2); + Todo todoBeingAdded = new Todo(todoSplit[1]); + taskList.addTask(todoBeingAdded); + } +} From df06eddd922a5a7b79a52ed7621cd50534a873f0 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 02:28:05 +0800 Subject: [PATCH 31/54] Added ALL Command classes - Task and Action --- ...neCommand.java => AddDeadlineCommand.java} | 6 +- ...EventCommand.java => AddEventCommand.java} | 6 +- ...ddTodoCommand.java => AddTodoCommand.java} | 2 +- src/main/java/Buddy.java | 80 +++++-------------- src/main/java/DeleteTaskCommand.java | 12 +++ src/main/java/Event.java | 2 +- src/main/java/FindTaskCommand.java | 25 ++++++ src/main/java/ListCommand.java | 15 ++++ src/main/java/MarkTaskCommand.java | 10 +++ src/main/java/Task.java | 8 ++ src/main/java/UnmarkTaskCommand.java | 10 +++ 11 files changed, 110 insertions(+), 66 deletions(-) rename src/main/java/{addDeadlineCommand.java => AddDeadlineCommand.java} (67%) rename src/main/java/{addEventCommand.java => AddEventCommand.java} (77%) rename src/main/java/{addTodoCommand.java => AddTodoCommand.java} (83%) create mode 100644 src/main/java/DeleteTaskCommand.java create mode 100644 src/main/java/FindTaskCommand.java create mode 100644 src/main/java/ListCommand.java create mode 100644 src/main/java/MarkTaskCommand.java create mode 100644 src/main/java/UnmarkTaskCommand.java diff --git a/src/main/java/addDeadlineCommand.java b/src/main/java/AddDeadlineCommand.java similarity index 67% rename from src/main/java/addDeadlineCommand.java rename to src/main/java/AddDeadlineCommand.java index 77ea78bf7..61ddabbf8 100644 --- a/src/main/java/addDeadlineCommand.java +++ b/src/main/java/AddDeadlineCommand.java @@ -1,12 +1,12 @@ -public class addDeadlineCommand extends Command{ +public class AddDeadlineCommand extends Command{ @Override public void executeCommand(TaskList taskList, String input) { String[] deadlineSplit = input.split("/by", 2); - String deadlineBy = deadlineSplit[1]; + String deadlineBy = deadlineSplit[1].trim(); String[] deadlineAndName = deadlineSplit[0].split(" ", 2); - String deadlineName = deadlineAndName[1]; + String deadlineName = deadlineAndName[1].trim(); Deadline deadlineBeingAdded = new Deadline(deadlineName, deadlineBy); taskList.addTask(deadlineBeingAdded); } diff --git a/src/main/java/addEventCommand.java b/src/main/java/AddEventCommand.java similarity index 77% rename from src/main/java/addEventCommand.java rename to src/main/java/AddEventCommand.java index 25beacb10..41772c0eb 100644 --- a/src/main/java/addEventCommand.java +++ b/src/main/java/AddEventCommand.java @@ -1,13 +1,13 @@ -public class addEventCommand extends Command { +public class AddEventCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { String[] eventSplit = input.split("/", 3); String[] eventAndName= eventSplit[0].split(" ", '2'); String eventName = eventAndName[1]; String[] fromAndStart = eventSplit[1].split(" ", '2'); - String start = fromAndStart[1]; + String start = fromAndStart[1].trim(); String[] toAndEnd = eventSplit[2].split(" ", '2'); - String end = toAndEnd[1]; + String end = toAndEnd[1].trim(); Event eventBeingAdded = new Event(eventName, start, end); taskList.addTask(eventBeingAdded); } diff --git a/src/main/java/addTodoCommand.java b/src/main/java/AddTodoCommand.java similarity index 83% rename from src/main/java/addTodoCommand.java rename to src/main/java/AddTodoCommand.java index d22739a11..d3395ffc2 100644 --- a/src/main/java/addTodoCommand.java +++ b/src/main/java/AddTodoCommand.java @@ -1,6 +1,6 @@ -public class addTodoCommand extends Command{ +public class AddTodoCommand extends Command{ @Override public void executeCommand(TaskList taskList, String input) { String[] todoSplit = input.split(" ", 2); diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 20aa08fc5..207f8697d 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -44,16 +44,13 @@ public static void main(String[] args) { int index = 1; if (input.equals("list")) { - for (int i = 0; i < taskCount; i++) { // while not null - System.out.println(index + "." + taskList.get(index - 1)); - index++; - } - } else if (input.startsWith("mark")) { - int taskNumberIndexMark = 5; - int taskNumber = Integer.parseInt(input.substring(taskNumberIndexMark)); - + Command list = new ListCommand(); + list.executeCommand(taskList, input); - try { + } else if (input.startsWith("mark")) { + Command mark = new MarkTaskCommand(); + mark.executeCommand(taskList, input); + /*try { Task currentTask = taskList.get(taskNumber - 1); currentTask.setDone(true); System.out.println(divider); @@ -63,11 +60,12 @@ public static void main(String[] args) { } catch (IndexOutOfBoundsException a) { System.out.println("That is not a valid task to mark! Please check your list again and input a valid task"); - } - } else if (input.startsWith("unmark")) { - int taskNumberIndexUnmark = 7; - int taskNumber = Integer.parseInt(input.substring(taskNumberIndexUnmark)); + }*/ + } else if (input.startsWith("unmark")) { + Command unmark = new UnmarkTaskCommand(); + unmark.executeCommand(taskList, input); + /* try { Task currentTask = taskList.get(taskNumber - 1); @@ -79,62 +77,28 @@ public static void main(String[] args) { } catch (IndexOutOfBoundsException a) { System.out.println("That is not a valid task to unmark! Please check your list again and input a valid task"); - } + }*/ } else if (input.startsWith("todo") || input.startsWith("deadline") || input.startsWith("event") || input.startsWith("delete") || input.startsWith("find")) { if (input.startsWith("todo")) { - int todoStartingIndex = 5; - - Todo todoBeingAdded = new Todo(input.substring(todoStartingIndex)); - taskList.addTask(todoBeingAdded); + Command addTodo = new AddTodoCommand(); + addTodo.executeCommand(taskList, input); } else if (input.startsWith("deadline")) { - int deadlineStartingIndex = 9; - Task taskBeingAdded = new Task(input.substring(deadlineStartingIndex)); // task + date + slash (Description) - // filter the description and date - String taskWithDate = taskBeingAdded.description; - int indexOfSlash = taskWithDate.indexOf('/'); - String taskDescription = taskWithDate.substring(0, (indexOfSlash - 1)); // substring goes to the one before the second index!!!! - String date = taskWithDate.substring(indexOfSlash + 4); - Deadline deadlineBeingAdded = new Deadline(taskDescription, date); - taskList.addTask(deadlineBeingAdded); - + Command addDeadline = new AddDeadlineCommand(); + addDeadline.executeCommand(taskList, input); } else if (input.startsWith("event")) { - int eventStartingIndex = 6; - Task taskBeingAdded = new Task(input.substring(eventStartingIndex)); - // filter the description, from and to - String wholeLine = taskBeingAdded.description; - int indexOfFirstSlash = wholeLine.indexOf('/'); - String taskDescription = wholeLine.substring(0, (indexOfFirstSlash - 1)); - int indexOfSecondSlash = wholeLine.indexOf('/', (indexOfFirstSlash + 1)); //searches from index after first slash - String from = wholeLine.substring((indexOfFirstSlash + 6), (indexOfSecondSlash)); - String to = wholeLine.substring(indexOfSecondSlash + 4); - Event eventBeingAdded = new Event(taskDescription, from, to); - taskList.addTask(eventBeingAdded); - + Command addEvent = new AddEventCommand(); + addEvent.executeCommand(taskList, input); } else if (input.startsWith("delete")) { - int indexOfTaskNumber = 7; - int taskNumberToBeDeleted = Integer.parseInt(input.substring(indexOfTaskNumber)); - taskList.deleteTask(taskNumberToBeDeleted - 1); + Command delete = new DeleteTaskCommand(); + delete.executeCommand(taskList, input); } else if (input.startsWith("find")){ - String keyword = input.split(" ")[1].trim().toLowerCase(); - ArrayList matchedTasks = new ArrayList<>(); - matchedTasks = (ArrayList) taskList.stream() // casts list to ArrayList - .filter(t -> t.getTaskName().trim().toLowerCase().contains(keyword)).collect(toList()); - if (!matchedTasks.isEmpty()){ - System.out.println("Well, I found these matching tasks in your list!"); - } - for (Task task : matchedTasks){ - - System.out.println(task); - - } - if (matchedTasks.isEmpty()){ - System.out.println("Oops, there are no tasks matching the keyword! Try again with another keyword"); - } + Command find = new FindTaskCommand(); + find.executeCommand(taskList, input); } diff --git a/src/main/java/DeleteTaskCommand.java b/src/main/java/DeleteTaskCommand.java new file mode 100644 index 000000000..742a8ea7a --- /dev/null +++ b/src/main/java/DeleteTaskCommand.java @@ -0,0 +1,12 @@ +public class DeleteTaskCommand extends Command{ + + @Override + public void executeCommand(TaskList taskList, String input) { + String[] deleteSplit = input.split(" ", 2); + int taskNumberToBeDeleted = Integer.parseInt(deleteSplit[1]); + int indexOfTaskInTaskList = taskNumberToBeDeleted - 1; + taskList.deleteTask(indexOfTaskInTaskList); + + + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 17e647b50..789ac0230 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -22,6 +22,6 @@ public String getType(){ } @Override public String toString() { - return "[E]" + super.toString() + " (from: " + from + "to: " + to + ")"; + return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")"; } } \ No newline at end of file diff --git a/src/main/java/FindTaskCommand.java b/src/main/java/FindTaskCommand.java new file mode 100644 index 000000000..d1d0bd5f3 --- /dev/null +++ b/src/main/java/FindTaskCommand.java @@ -0,0 +1,25 @@ +import java.util.ArrayList; + +import static java.util.stream.Collectors.toList; + +public class FindTaskCommand extends Command{ + @Override + public void executeCommand(TaskList taskList, String input) { + String keyword = input.split(" ")[1].trim().toLowerCase(); + ArrayList matchedTasks; + matchedTasks = (ArrayList) taskList.stream() // casts list to ArrayList + .filter(t -> t.getTaskName().trim().toLowerCase().contains(keyword)).collect(toList()); + System.out.println(Buddy.divider); + if (!matchedTasks.isEmpty()){ + System.out.println("Well, here is the list of tasks matching your keyword!"); + } + for (Task task : matchedTasks){ + System.out.println(task); + } + if (matchedTasks.isEmpty()){ + System.out.println("Oops, there are no tasks matching the keyword! Try again with another keyword"); + } + System.out.println(Buddy.divider); + + } +} diff --git a/src/main/java/ListCommand.java b/src/main/java/ListCommand.java new file mode 100644 index 000000000..5ba3fefeb --- /dev/null +++ b/src/main/java/ListCommand.java @@ -0,0 +1,15 @@ +public class ListCommand extends Command { + @Override + public void executeCommand(TaskList taskList, String input) { + System.out.println(Buddy.divider); + System.out.println("Here is the list of tasks you have remaining! Come on Buddy!"); + int index = 1; // index which shows numbers the task + for (int i = 0; i < Buddy.taskCount; i++) { + System.out.println(index + "." + taskList.get(i)); + index++; // increment the number on the task + } + System.out.println(Buddy.divider); + + + } +} diff --git a/src/main/java/MarkTaskCommand.java b/src/main/java/MarkTaskCommand.java new file mode 100644 index 000000000..9744e2b18 --- /dev/null +++ b/src/main/java/MarkTaskCommand.java @@ -0,0 +1,10 @@ +public class MarkTaskCommand extends Command { + @Override + public void executeCommand(TaskList taskList, String input) { + String[] markSplit = input.split(" ", 2); + int taskNumberToBeMarked = Integer.parseInt(markSplit[1]); + int indexOfTaskToBeMarked = taskNumberToBeMarked - 1; + Task taskToBeMarked = taskList.get(indexOfTaskToBeMarked); + taskToBeMarked.markAsDone(); + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 388a2e167..49a583949 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -26,10 +26,18 @@ public void setDone(boolean isDone) { public void markAsDone(){ this.isDone = true; + System.out.println(Buddy.divider); + System.out.println("Great work on completing this task! Marked as done! :)"); + System.out.println(this); + System.out.println(Buddy.divider); } public void markAsUndone(){ this.isDone = false; + System.out.println(Buddy.divider); + System.out.println("Come on, don't procrastinate! Marked as undone!"); + System.out.println(this); + System.out.println(Buddy.divider); } @Override diff --git a/src/main/java/UnmarkTaskCommand.java b/src/main/java/UnmarkTaskCommand.java new file mode 100644 index 000000000..5d603d95c --- /dev/null +++ b/src/main/java/UnmarkTaskCommand.java @@ -0,0 +1,10 @@ +public class UnmarkTaskCommand extends Command { + @Override + public void executeCommand(TaskList taskList, String input) { + String[] unmarkSplit = input.split(" ", 2); + int taskNumberToBeUnmarked = Integer.parseInt(unmarkSplit[1]); + int indexOfTaskToBeUnmarked = taskNumberToBeUnmarked - 1; + Task taskToBeUnmarked = taskList.get(indexOfTaskToBeUnmarked); + taskToBeUnmarked.markAsUndone(); + } +} \ No newline at end of file From 511e48ce72d827a43b119b15c3bb471408ba923b Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 03:05:57 +0800 Subject: [PATCH 32/54] Added Parser Class and works --- src/main/java/Buddy.java | 17 +++++------ src/main/java/Parser.java | 64 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 src/main/java/Parser.java diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 207f8697d..39db592d6 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -12,7 +12,7 @@ public class Buddy { public static int taskCount = 0; public static String divider = "________________________________________________________________________________"; - public static void main(String[] args) { + public static void main(String[] args) throws IOException { TaskList taskList = new TaskList(); try { Storage.loadFile(taskList); @@ -38,11 +38,13 @@ public static void main(String[] args) { String input; Scanner in = new Scanner(System.in); input = in.nextLine(); + Parser processAllCommands = new Parser(); + while (! processAllCommands.isExit(input)) { + processAllCommands.executeLine(taskList, input); - while (!input.equals("bye")) { - int index = 1; + /*int index = 1; if (input.equals("list")) { Command list = new ListCommand(); list.executeCommand(taskList, input); @@ -60,7 +62,7 @@ public static void main(String[] args) { } catch (IndexOutOfBoundsException a) { System.out.println("That is not a valid task to mark! Please check your list again and input a valid task"); - }*/ + } } else if (input.startsWith("unmark")) { Command unmark = new UnmarkTaskCommand(); @@ -77,7 +79,7 @@ public static void main(String[] args) { } catch (IndexOutOfBoundsException a) { System.out.println("That is not a valid task to unmark! Please check your list again and input a valid task"); - }*/ + } } else if (input.startsWith("todo") || input.startsWith("deadline") || input.startsWith("event") || input.startsWith("delete") || input.startsWith("find")) { if (input.startsWith("todo")) { @@ -100,11 +102,8 @@ public static void main(String[] args) { Command find = new FindTaskCommand(); find.executeCommand(taskList, input); - } + }*/ - } else { - System.out.println("This input does not exist! Please type a valid input!"); - } input = in.nextLine(); } diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 000000000..16a4eceae --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,64 @@ +import java.io.IOException; + +public class Parser{ + + public boolean isExit(String input){ + return input.equals("bye"); + } + + public void executeLine(TaskList taskList, String input) throws IOException { + String[] inputSplit = input.split(" ", 2); + String commandName = inputSplit[0].trim(); + + switch (commandName){ + case "todo": + Command addTodo = new AddTodoCommand(); + addTodo.executeCommand(taskList, input); + Storage.updateFile(taskList); + break; + + case "deadline": + Command addDeadline = new AddDeadlineCommand(); + addDeadline.executeCommand(taskList, input); + Storage.updateFile(taskList); + break; + + case "event": + Command addEvent = new AddEventCommand(); + addEvent.executeCommand(taskList, input); + Storage.updateFile(taskList); + break; + + case "list": + Command list = new ListCommand(); + list.executeCommand(taskList, input); + break; + + case "mark": + Command mark = new MarkTaskCommand(); + mark.executeCommand(taskList, input); + Storage.updateFile(taskList); + break; + + case "unmark": + Command unmark = new UnmarkTaskCommand(); + unmark.executeCommand(taskList, input); + Storage.updateFile(taskList); + break; + + case "delete": + Command delete = new DeleteTaskCommand(); + delete.executeCommand(taskList, input); + Storage.updateFile(taskList); + break; + + case "find": + Command find = new FindTaskCommand(); + find.executeCommand(taskList, input); + break; + + default: + } + } + +} From 4c43b1e871d6c868cee8adff144b33a5bd494b86 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 03:26:40 +0800 Subject: [PATCH 33/54] Added Messages Class --- src/main/java/Buddy.java | 20 ++++++++------------ src/main/java/FindTaskCommand.java | 4 ++-- src/main/java/ListCommand.java | 4 ++-- src/main/java/Messages.java | 7 +++++++ src/main/java/Task.java | 8 ++++---- src/main/java/TaskList.java | 8 ++++---- src/main/java/Ui.java | 2 ++ 7 files changed, 29 insertions(+), 24 deletions(-) create mode 100644 src/main/java/Messages.java create mode 100644 src/main/java/Ui.java diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 39db592d6..671bc3599 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -10,7 +10,7 @@ public class Buddy { public static int taskCount = 0; - public static String divider = "________________________________________________________________________________"; + public static void main(String[] args) throws IOException { TaskList taskList = new TaskList(); @@ -23,16 +23,12 @@ public static void main(String[] args) throws IOException { } - String greeting = "Hello there! I'm Buddy\n" - + "How may I assist you?"; - String listOfCommands = "Here are the commands you can use: todo, deadline, event, list, mark, unmark, bye"; - String exitMessage = "Hope I was of help to you! Have a great day and see you again, Buddy :)"; - System.out.println(divider); - System.out.println(greeting); - System.out.println(listOfCommands); - System.out.println(divider); + System.out.println(Messages.DIVIDER); + System.out.println(Messages.GREETING); + System.out.println(Messages.INTRODUCTION); + System.out.println(Messages.DIVIDER); String input; @@ -114,9 +110,9 @@ public static void main(String[] args) throws IOException { System.out.println("Error occurred"); } - System.out.println(divider); - System.out.println(exitMessage); - System.out.println(divider); + System.out.println(Messages.DIVIDER); + System.out.println(Messages.EXITMESSAGE); + System.out.println(Messages.DIVIDER); } } diff --git a/src/main/java/FindTaskCommand.java b/src/main/java/FindTaskCommand.java index d1d0bd5f3..9cbf8c479 100644 --- a/src/main/java/FindTaskCommand.java +++ b/src/main/java/FindTaskCommand.java @@ -9,7 +9,7 @@ public void executeCommand(TaskList taskList, String input) { ArrayList matchedTasks; matchedTasks = (ArrayList) taskList.stream() // casts list to ArrayList .filter(t -> t.getTaskName().trim().toLowerCase().contains(keyword)).collect(toList()); - System.out.println(Buddy.divider); + System.out.println(Messages.DIVIDER); if (!matchedTasks.isEmpty()){ System.out.println("Well, here is the list of tasks matching your keyword!"); } @@ -19,7 +19,7 @@ public void executeCommand(TaskList taskList, String input) { if (matchedTasks.isEmpty()){ System.out.println("Oops, there are no tasks matching the keyword! Try again with another keyword"); } - System.out.println(Buddy.divider); + System.out.println(Messages.DIVIDER); } } diff --git a/src/main/java/ListCommand.java b/src/main/java/ListCommand.java index 5ba3fefeb..9c7cc2892 100644 --- a/src/main/java/ListCommand.java +++ b/src/main/java/ListCommand.java @@ -1,14 +1,14 @@ public class ListCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { - System.out.println(Buddy.divider); + System.out.println(Messages.DIVIDER); System.out.println("Here is the list of tasks you have remaining! Come on Buddy!"); int index = 1; // index which shows numbers the task for (int i = 0; i < Buddy.taskCount; i++) { System.out.println(index + "." + taskList.get(i)); index++; // increment the number on the task } - System.out.println(Buddy.divider); + System.out.println(Messages.DIVIDER); } diff --git a/src/main/java/Messages.java b/src/main/java/Messages.java new file mode 100644 index 000000000..aaabf2030 --- /dev/null +++ b/src/main/java/Messages.java @@ -0,0 +1,7 @@ +public class Messages { + public static final String DIVIDER = "________________________________________________________________________________"; + public static final String GREETING = "Hello there! I'm Buddy\n" + + "How may I assist you?"; + public static final String INTRODUCTION = "Here are the possible commands: todo, deadline, event, list, mark, unmark, bye \n" + "Type if you are unsure of what these commands do!"; + public static final String EXITMESSAGE = "Hope I was of help to you! Have a great day and see you again, Buddy :)"; +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 49a583949..c45b4e24e 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -26,18 +26,18 @@ public void setDone(boolean isDone) { public void markAsDone(){ this.isDone = true; - System.out.println(Buddy.divider); + System.out.println(Messages.DIVIDER); System.out.println("Great work on completing this task! Marked as done! :)"); System.out.println(this); - System.out.println(Buddy.divider); + System.out.println(Messages.DIVIDER); } public void markAsUndone(){ this.isDone = false; - System.out.println(Buddy.divider); + System.out.println(Messages.DIVIDER); System.out.println("Come on, don't procrastinate! Marked as undone!"); System.out.println(this); - System.out.println(Buddy.divider); + System.out.println(Messages.DIVIDER); } @Override diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 8ae0ca6d5..af99bfe7c 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -2,20 +2,20 @@ public class TaskList extends ArrayList { public void addTask (Task newTask){ - System.out.println(Buddy.divider); + System.out.println(Messages.DIVIDER); this.add(newTask); // new task is added to taskList Buddy.taskCount++; // increments number of tasks newTask.printAfterAddingTask(); // print message once new task is added (From Task class) - System.out.println(Buddy.divider); + System.out.println(Messages.DIVIDER); } public void deleteTask (int indexOfTaskToDelete){ - System.out.println(Buddy.divider); + System.out.println(Messages.DIVIDER); Task taskToBeDeleted = this.get(indexOfTaskToDelete); Buddy.taskCount--; // decrements number of tasks taskToBeDeleted.printAfterDeletingTask(); this.remove(indexOfTaskToDelete); // delete task from taskList - System.out.println(Buddy.divider); + System.out.println(Messages.DIVIDER); } } diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 000000000..30d98a701 --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,2 @@ +public class Ui { +} From 8f0a3e89131629390b5c47b25695ca2e62ea5732 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 03:59:36 +0800 Subject: [PATCH 34/54] Added Help Command and Help Message --- src/main/java/Buddy.java | 2 +- src/main/java/HelpCommand.java | 8 ++++++++ src/main/java/Messages.java | 26 +++++++++++++++++++++++++- src/main/java/Parser.java | 3 +++ src/main/java/Ui.java | 13 +++++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/main/java/HelpCommand.java diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 671bc3599..9f5761f9f 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -26,7 +26,7 @@ public static void main(String[] args) throws IOException { System.out.println(Messages.DIVIDER); - System.out.println(Messages.GREETING); + System.out.println(Messages.INTRODUCTION); System.out.println(Messages.DIVIDER); diff --git a/src/main/java/HelpCommand.java b/src/main/java/HelpCommand.java new file mode 100644 index 000000000..5f23a4c95 --- /dev/null +++ b/src/main/java/HelpCommand.java @@ -0,0 +1,8 @@ +public class HelpCommand extends Command{ + @Override + public void executeCommand(TaskList taskList, String input) { + System.out.println(Messages.DIVIDER); + System.out.println(Messages.HELPMESSAGE); + System.out.println(Messages.DIVIDER); + } +} diff --git a/src/main/java/Messages.java b/src/main/java/Messages.java index aaabf2030..f904a738b 100644 --- a/src/main/java/Messages.java +++ b/src/main/java/Messages.java @@ -2,6 +2,30 @@ public class Messages { public static final String DIVIDER = "________________________________________________________________________________"; public static final String GREETING = "Hello there! I'm Buddy\n" + "How may I assist you?"; - public static final String INTRODUCTION = "Here are the possible commands: todo, deadline, event, list, mark, unmark, bye \n" + "Type if you are unsure of what these commands do!"; + public static final String INTRODUCTION = "Here are the possible commands: todo, deadline, event, list, mark, unmark, find, bye\n" + "Type if you are unsure of what these commands do!"; public static final String EXITMESSAGE = "Hope I was of help to you! Have a great day and see you again, Buddy :)"; + public static final String HELPMESSAGE = + "These are the various commands and their functions. Please type in the FORMAT that is stated below\n" + + "There are 3 add task commands which add 3 kinds of tasks: todo, deadline and event\n" + + "todo: Adds a todo to your task list\n" + + "FORMAT: todo \n" + + "deadline: Adds a deadline to your task list\n" + + "FORMAT: deadline /by \n" + + "event: Adds an event to your task list\n" + + "FORMAT: event /from /to \n" + + "There are 5 other action commands: list, mark, unmark, find and bye\n" + + "list: lists all the tasks that you have remaining\n" + + "FORMAT: list\n" + + "mark: marks a task as done with an X\n" + + "FORMAT: mark \n" + + "unmark: marks a task as not done\n" + + "FORMAT: unmark \n" + + "find: finds a task which contains the keyword that you typed\n" + + "FORMAT: find \n" + + "bye: exits the application\n" + + "FORMAT: bye\n" + + "Hope that this was useful!"; + + + ; } diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 16a4eceae..59da57663 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -56,6 +56,9 @@ public void executeLine(TaskList taskList, String input) throws IOException { Command find = new FindTaskCommand(); find.executeCommand(taskList, input); break; + case "help": + Command help = new HelpCommand(); + help.executeCommand(taskList, input); default: } diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 30d98a701..7ca8c8417 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,2 +1,15 @@ public class Ui { + + public void greetUser(){ + System.out.println(Messages.GREETING); + } + public void giveIntroToUser(){ + System.out.println(Messages.INTRODUCTION); + } + public void displayHelpMessage(){ + System.out.println(Messages.HELPMESSAGE); + } + public void sayByeToUser(){ + System.out.println(Messages.EXITMESSAGE); + } } From 5c3cb49208b3ab39902b61c2e190f968c8887c2a Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 04:02:04 +0800 Subject: [PATCH 35/54] Added Greeting --- src/main/java/Buddy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 9f5761f9f..671bc3599 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -26,7 +26,7 @@ public static void main(String[] args) throws IOException { System.out.println(Messages.DIVIDER); - + System.out.println(Messages.GREETING); System.out.println(Messages.INTRODUCTION); System.out.println(Messages.DIVIDER); From 5bebd1978fad3b95495df8d3c203899f2dbf35e8 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 04:49:30 +0800 Subject: [PATCH 36/54] Add Date Time Formatter for Deadline --- src/main/java/AddDeadlineCommand.java | 10 ++++++++-- src/main/java/Messages.java | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/AddDeadlineCommand.java b/src/main/java/AddDeadlineCommand.java index 61ddabbf8..fe1c8f14c 100644 --- a/src/main/java/AddDeadlineCommand.java +++ b/src/main/java/AddDeadlineCommand.java @@ -1,13 +1,19 @@ - +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.Date; public class AddDeadlineCommand extends Command{ + @Override public void executeCommand(TaskList taskList, String input) { String[] deadlineSplit = input.split("/by", 2); String deadlineBy = deadlineSplit[1].trim(); + LocalDate toFormat = LocalDate.parse(deadlineBy); + String deadlineByFormatted = toFormat.format(DateTimeFormatter.ofPattern("MMM d yyyy")); String[] deadlineAndName = deadlineSplit[0].split(" ", 2); String deadlineName = deadlineAndName[1].trim(); - Deadline deadlineBeingAdded = new Deadline(deadlineName, deadlineBy); + + Deadline deadlineBeingAdded = new Deadline(deadlineName, deadlineByFormatted); taskList.addTask(deadlineBeingAdded); } } \ No newline at end of file diff --git a/src/main/java/Messages.java b/src/main/java/Messages.java index f904a738b..d92e253bc 100644 --- a/src/main/java/Messages.java +++ b/src/main/java/Messages.java @@ -10,7 +10,7 @@ public class Messages { "todo: Adds a todo to your task list\n" + "FORMAT: todo \n" + "deadline: Adds a deadline to your task list\n" + - "FORMAT: deadline /by \n" + + "FORMAT: deadline /by \n" + "event: Adds an event to your task list\n" + "FORMAT: event /from /to \n" + "There are 5 other action commands: list, mark, unmark, find and bye\n" + From de0616cdb4dab047c554bc52034ec9e57a116144 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 04:51:37 +0800 Subject: [PATCH 37/54] changing just to merge --- src/main/java/Buddy.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index b24c5af66..4b37b3252 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -9,6 +9,7 @@ public class Buddy { + public static int taskCount = 0; public static void main(String[] args) { From bb101ad59a49c560a2b340bace1d8f4690322328 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 05:27:39 +0800 Subject: [PATCH 38/54] Added exceptions to code --- src/main/java/AddDeadlineCommand.java | 31 ++++++++--- src/main/java/AddEventCommand.java | 27 ++++++--- src/main/java/AddTodoCommand.java | 15 ++++- src/main/java/Buddy.java | 64 ---------------------- src/main/java/BuddyException.java | 2 - src/main/java/DeleteTaskCommand.java | 14 +++-- src/main/java/FindTaskCommand.java | 1 - src/main/java/InvalidCommandException.java | 6 ++ src/main/java/ListCommand.java | 3 + src/main/java/MarkTaskCommand.java | 16 ++++-- src/main/java/Messages.java | 2 +- src/main/java/UnmarkTaskCommand.java | 16 ++++-- 12 files changed, 96 insertions(+), 101 deletions(-) delete mode 100644 src/main/java/BuddyException.java create mode 100644 src/main/java/InvalidCommandException.java diff --git a/src/main/java/AddDeadlineCommand.java b/src/main/java/AddDeadlineCommand.java index 61ddabbf8..8dd62380c 100644 --- a/src/main/java/AddDeadlineCommand.java +++ b/src/main/java/AddDeadlineCommand.java @@ -1,13 +1,30 @@ - +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; public class AddDeadlineCommand extends Command{ @Override public void executeCommand(TaskList taskList, String input) { - String[] deadlineSplit = input.split("/by", 2); - String deadlineBy = deadlineSplit[1].trim(); - String[] deadlineAndName = deadlineSplit[0].split(" ", 2); - String deadlineName = deadlineAndName[1].trim(); - Deadline deadlineBeingAdded = new Deadline(deadlineName, deadlineBy); - taskList.addTask(deadlineBeingAdded); + try{ + String[] deadlineSplit = input.split("/by", 2); + String deadlineBy = deadlineSplit[1].trim(); + LocalDate toFormat = LocalDate.parse(deadlineBy); + if (toFormat.isBefore(LocalDate.now())){ + throw new InvalidCommandException(); + } + String deadlineByFormatted = toFormat.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + String[] deadlineAndName = deadlineSplit[0].split(" ", 2); + String deadlineName = deadlineAndName[1].trim(); + if (deadlineName.equals("")){ + throw new InvalidCommandException(); + } + + Deadline deadlineBeingAdded = new Deadline(deadlineName, deadlineByFormatted); + taskList.addTask(deadlineBeingAdded); + + }catch(InvalidCommandException e){ + InvalidCommandException.printMessage(); + } + + } } \ No newline at end of file diff --git a/src/main/java/AddEventCommand.java b/src/main/java/AddEventCommand.java index 41772c0eb..4471c0615 100644 --- a/src/main/java/AddEventCommand.java +++ b/src/main/java/AddEventCommand.java @@ -1,14 +1,23 @@ public class AddEventCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { - String[] eventSplit = input.split("/", 3); - String[] eventAndName= eventSplit[0].split(" ", '2'); - String eventName = eventAndName[1]; - String[] fromAndStart = eventSplit[1].split(" ", '2'); - String start = fromAndStart[1].trim(); - String[] toAndEnd = eventSplit[2].split(" ", '2'); - String end = toAndEnd[1].trim(); - Event eventBeingAdded = new Event(eventName, start, end); - taskList.addTask(eventBeingAdded); + try{ + String[] eventSplit = input.split("/", 3); + String[] eventAndName= eventSplit[0].split(" ", '2'); + String eventName = eventAndName[1]; + String[] fromAndStart = eventSplit[1].split(" ", '2'); + String start = fromAndStart[1].trim(); + String[] toAndEnd = eventSplit[2].split(" ", '2'); + String end = toAndEnd[1].trim(); + if (eventName.equals("") || start.equals("") || end.equals("")){ + throw new InvalidCommandException(); + } + Event eventBeingAdded = new Event(eventName, start, end); + taskList.addTask(eventBeingAdded); + + }catch(InvalidCommandException e){ + InvalidCommandException.printMessage(); + } + } } diff --git a/src/main/java/AddTodoCommand.java b/src/main/java/AddTodoCommand.java index d3395ffc2..f0a828152 100644 --- a/src/main/java/AddTodoCommand.java +++ b/src/main/java/AddTodoCommand.java @@ -3,8 +3,17 @@ public class AddTodoCommand extends Command{ @Override public void executeCommand(TaskList taskList, String input) { - String[] todoSplit = input.split(" ", 2); - Todo todoBeingAdded = new Todo(todoSplit[1]); - taskList.addTask(todoBeingAdded); + try{ + String[] todoSplit = input.split(" ", 2); + if (todoSplit[1].equals("")){ + throw new InvalidCommandException(); + } + Todo todoBeingAdded = new Todo(todoSplit[1]); + taskList.addTask(todoBeingAdded); + + }catch (InvalidCommandException e){ + InvalidCommandException.printMessage(); + } + } } diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 4b560804b..951471eec 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -24,8 +24,6 @@ public static void main(String[] args) throws IOException { } - - System.out.println(Messages.DIVIDER); System.out.println(Messages.GREETING); System.out.println(Messages.INTRODUCTION); @@ -39,68 +37,6 @@ public static void main(String[] args) throws IOException { while (! processAllCommands.isExit(input)) { processAllCommands.executeLine(taskList, input); - - - /*int index = 1; - if (input.equals("list")) { - Command list = new ListCommand(); - list.executeCommand(taskList, input); - - } else if (input.startsWith("mark")) { - Command mark = new MarkTaskCommand(); - mark.executeCommand(taskList, input); - /*try { - Task currentTask = taskList.get(taskNumber - 1); - currentTask.setDone(true); - System.out.println(divider); - System.out.println("Great work on completing this task! Marked as done! :)"); - System.out.println(currentTask); - System.out.println(divider); - } catch (IndexOutOfBoundsException a) { - System.out.println("That is not a valid task to mark! Please check your list again and input a valid task"); - - } - - } else if (input.startsWith("unmark")) { - Command unmark = new UnmarkTaskCommand(); - unmark.executeCommand(taskList, input); - /* - try { - Task currentTask = taskList.get(taskNumber - 1); - - currentTask.setDone(false); - System.out.println(divider); - System.out.println("Remember to come back to this task! Marked as undone!"); - System.out.println(currentTask); - System.out.println(divider); - } catch (IndexOutOfBoundsException a) { - System.out.println("That is not a valid task to unmark! Please check your list again and input a valid task"); - - } - } else if (input.startsWith("todo") || input.startsWith("deadline") || input.startsWith("event") || input.startsWith("delete") || input.startsWith("find")) { - - if (input.startsWith("todo")) { - Command addTodo = new AddTodoCommand(); - addTodo.executeCommand(taskList, input); - - } else if (input.startsWith("deadline")) { - Command addDeadline = new AddDeadlineCommand(); - addDeadline.executeCommand(taskList, input); - - } else if (input.startsWith("event")) { - Command addEvent = new AddEventCommand(); - addEvent.executeCommand(taskList, input); - - } else if (input.startsWith("delete")) { - Command delete = new DeleteTaskCommand(); - delete.executeCommand(taskList, input); - - } else if (input.startsWith("find")){ - Command find = new FindTaskCommand(); - find.executeCommand(taskList, input); - - }*/ - input = in.nextLine(); } diff --git a/src/main/java/BuddyException.java b/src/main/java/BuddyException.java deleted file mode 100644 index 2988fb133..000000000 --- a/src/main/java/BuddyException.java +++ /dev/null @@ -1,2 +0,0 @@ -public class BuddyException { -} diff --git a/src/main/java/DeleteTaskCommand.java b/src/main/java/DeleteTaskCommand.java index 742a8ea7a..8c925e203 100644 --- a/src/main/java/DeleteTaskCommand.java +++ b/src/main/java/DeleteTaskCommand.java @@ -2,10 +2,16 @@ public class DeleteTaskCommand extends Command{ @Override public void executeCommand(TaskList taskList, String input) { - String[] deleteSplit = input.split(" ", 2); - int taskNumberToBeDeleted = Integer.parseInt(deleteSplit[1]); - int indexOfTaskInTaskList = taskNumberToBeDeleted - 1; - taskList.deleteTask(indexOfTaskInTaskList); + try{ + String[] deleteSplit = input.split(" ", 2); + int taskNumberToBeDeleted = Integer.parseInt(deleteSplit[1]); + int indexOfTaskInTaskList = taskNumberToBeDeleted - 1; + taskList.deleteTask(indexOfTaskInTaskList); + + } catch(IndexOutOfBoundsException e){ + System.out.println("That is not a valid task to delete! Please check your list again and input a valid task"); + } + } diff --git a/src/main/java/FindTaskCommand.java b/src/main/java/FindTaskCommand.java index 9cbf8c479..682df7055 100644 --- a/src/main/java/FindTaskCommand.java +++ b/src/main/java/FindTaskCommand.java @@ -1,5 +1,4 @@ import java.util.ArrayList; - import static java.util.stream.Collectors.toList; public class FindTaskCommand extends Command{ diff --git a/src/main/java/InvalidCommandException.java b/src/main/java/InvalidCommandException.java new file mode 100644 index 000000000..784eaa559 --- /dev/null +++ b/src/main/java/InvalidCommandException.java @@ -0,0 +1,6 @@ +public class InvalidCommandException extends Exception{ + public static void printMessage(){ + System.out.println("This is an invalid command! Please check and type in again"); + } + +} diff --git a/src/main/java/ListCommand.java b/src/main/java/ListCommand.java index 9c7cc2892..c6383a625 100644 --- a/src/main/java/ListCommand.java +++ b/src/main/java/ListCommand.java @@ -8,6 +8,9 @@ public void executeCommand(TaskList taskList, String input) { System.out.println(index + "." + taskList.get(i)); index++; // increment the number on the task } + if (taskList.isEmpty()){ + System.out.println("There is nothing in the list! Please enter a new command"); + } System.out.println(Messages.DIVIDER); diff --git a/src/main/java/MarkTaskCommand.java b/src/main/java/MarkTaskCommand.java index 9744e2b18..08c2b7f06 100644 --- a/src/main/java/MarkTaskCommand.java +++ b/src/main/java/MarkTaskCommand.java @@ -1,10 +1,16 @@ public class MarkTaskCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { - String[] markSplit = input.split(" ", 2); - int taskNumberToBeMarked = Integer.parseInt(markSplit[1]); - int indexOfTaskToBeMarked = taskNumberToBeMarked - 1; - Task taskToBeMarked = taskList.get(indexOfTaskToBeMarked); - taskToBeMarked.markAsDone(); + try{ + String[] markSplit = input.split(" ", 2); + int taskNumberToBeMarked = Integer.parseInt(markSplit[1]); + int indexOfTaskToBeMarked = taskNumberToBeMarked - 1; + Task taskToBeMarked = taskList.get(indexOfTaskToBeMarked); + taskToBeMarked.markAsDone(); + + }catch(IndexOutOfBoundsException e){ + System.out.println("That is not a valid task to mark! Please check your list again and input a valid task"); + } + } } diff --git a/src/main/java/Messages.java b/src/main/java/Messages.java index f904a738b..ab201453e 100644 --- a/src/main/java/Messages.java +++ b/src/main/java/Messages.java @@ -10,7 +10,7 @@ public class Messages { "todo: Adds a todo to your task list\n" + "FORMAT: todo \n" + "deadline: Adds a deadline to your task list\n" + - "FORMAT: deadline /by \n" + + "FORMAT: deadline /by (where YYYY is year, MM is month and DD is day)\n" + "event: Adds an event to your task list\n" + "FORMAT: event /from /to \n" + "There are 5 other action commands: list, mark, unmark, find and bye\n" + diff --git a/src/main/java/UnmarkTaskCommand.java b/src/main/java/UnmarkTaskCommand.java index 5d603d95c..959a879af 100644 --- a/src/main/java/UnmarkTaskCommand.java +++ b/src/main/java/UnmarkTaskCommand.java @@ -1,10 +1,16 @@ public class UnmarkTaskCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { - String[] unmarkSplit = input.split(" ", 2); - int taskNumberToBeUnmarked = Integer.parseInt(unmarkSplit[1]); - int indexOfTaskToBeUnmarked = taskNumberToBeUnmarked - 1; - Task taskToBeUnmarked = taskList.get(indexOfTaskToBeUnmarked); - taskToBeUnmarked.markAsUndone(); + try{ + String[] unmarkSplit = input.split(" ", 2); + int taskNumberToBeUnmarked = Integer.parseInt(unmarkSplit[1]); + int indexOfTaskToBeUnmarked = taskNumberToBeUnmarked - 1; + Task taskToBeUnmarked = taskList.get(indexOfTaskToBeUnmarked); + taskToBeUnmarked.markAsUndone(); + + }catch(IndexOutOfBoundsException e){ + System.out.println("That is not a valid task to unmark! Please check your list again and input a valid task"); + } + } } \ No newline at end of file From e45aba27470c8bbe6cc7f5b2fed43e5b706b8d29 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 05:44:52 +0800 Subject: [PATCH 39/54] Added Testing --- src/main/java/Buddy.java | 7 ++---- src/main/java/Messages.java | 2 +- text-ui-test/EXPECTED.TXT | 49 +++++++++++++++++++++++++++++++------ text-ui-test/input.txt | 8 ++++++ 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 951471eec..a6f7793cf 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -1,11 +1,8 @@ -import java.io.File; + import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; -import java.util.ArrayList; -import java.io.FileWriter; -import java.util.stream.Collectors; -import static java.util.stream.Collectors.toList; + public class Buddy { diff --git a/src/main/java/Messages.java b/src/main/java/Messages.java index 504c93cb4..5a31ed1e7 100644 --- a/src/main/java/Messages.java +++ b/src/main/java/Messages.java @@ -28,5 +28,5 @@ public class Messages { "Hope that this was useful!"; - ; + } diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..d536451ca 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,42 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - +________________________________________________________________________________ +Hello there! I'm Buddy +How may I assist you? +Here are the possible commands: todo, deadline, event, list, mark, unmark, find, bye +Type if you are unsure of what these commands do! +________________________________________________________________________________ +________________________________________________________________________________ +Got it! I have added this task!: +[T][ ] cs2113 +Now you have 1 task remaining! Almost there, buddy! +________________________________________________________________________________ +________________________________________________________________________________ +Got it! I have added this task! +[D][ ] cg mod (Please do by: Dec 1 2023!) +Now you have 2 tasks remaining! Let's finish them faster and relax! +________________________________________________________________________________ +________________________________________________________________________________ +Got it! I have added this task! +[E][ ] exam (from: 2pm to: 5pm) +Now you have 3 tasks remaining! Let's finish them faster and relax! +________________________________________________________________________________ +________________________________________________________________________________ +Great work on completing this task! Marked as done! :) +[T][X] cs2113 +________________________________________________________________________________ +________________________________________________________________________________ +Great work on completing this task! Marked as done! :) +[D][X] cg mod (Please do by: Dec 1 2023!) +________________________________________________________________________________ +________________________________________________________________________________ +Come on, don't procrastinate! Marked as undone! +[T][ ] cs2113 +________________________________________________________________________________ +________________________________________________________________________________ +Here is the list of tasks you have remaining! Come on Buddy! +1.[T][ ] cs2113 +2.[D][X] cg mod (Please do by: Dec 1 2023!) +3.[E][ ] exam (from: 2pm to: 5pm) +________________________________________________________________________________ +________________________________________________________________________________ +Hope I was of help to you! Have a great day and see you again, Buddy :) +________________________________________________________________________________ \ No newline at end of file diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..3dfa1bb39 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,8 @@ +todo cs2113 +deadline cg mod /by 2023-12-01 +event exam /from 2pm /to 5pm +mark 1 +mark 2 +unmark 1 +list +bye From 8ca8fd879a734835059a3ea3fd0d26a023580172 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 12:12:34 +0800 Subject: [PATCH 40/54] All works, adding UI --- src/main/java/AddDeadlineCommand.java | 2 + src/main/java/AddEventCommand.java | 3 + src/main/java/AddTodoCommand.java | 2 +- src/main/java/Buddy.java | 8 -- src/main/java/DeleteTaskCommand.java | 3 +- src/main/java/ListCommand.java | 5 +- src/main/java/MarkTaskCommand.java | 3 + src/main/java/Parser.java | 118 ++++++++++++++------------ src/main/java/Storage.java | 5 +- src/main/java/UnmarkTaskCommand.java | 3 + 10 files changed, 85 insertions(+), 67 deletions(-) diff --git a/src/main/java/AddDeadlineCommand.java b/src/main/java/AddDeadlineCommand.java index 2b7caa5ab..42c9ea281 100644 --- a/src/main/java/AddDeadlineCommand.java +++ b/src/main/java/AddDeadlineCommand.java @@ -1,3 +1,4 @@ +import java.io.IOException; import java.time.LocalDate; import java.time.format.DateTimeFormatter; @@ -22,6 +23,7 @@ public void executeCommand(TaskList taskList, String input) { Deadline deadlineBeingAdded = new Deadline(deadlineName, deadlineByFormatted); taskList.addTask(deadlineBeingAdded); + }catch(InvalidCommandException e){ InvalidCommandException.printMessage(); } diff --git a/src/main/java/AddEventCommand.java b/src/main/java/AddEventCommand.java index 4471c0615..f3f0246e6 100644 --- a/src/main/java/AddEventCommand.java +++ b/src/main/java/AddEventCommand.java @@ -1,3 +1,5 @@ +import java.io.IOException; + public class AddEventCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { @@ -15,6 +17,7 @@ public void executeCommand(TaskList taskList, String input) { Event eventBeingAdded = new Event(eventName, start, end); taskList.addTask(eventBeingAdded); + }catch(InvalidCommandException e){ InvalidCommandException.printMessage(); } diff --git a/src/main/java/AddTodoCommand.java b/src/main/java/AddTodoCommand.java index f0a828152..6c1c28707 100644 --- a/src/main/java/AddTodoCommand.java +++ b/src/main/java/AddTodoCommand.java @@ -1,4 +1,4 @@ - +import java.io.IOException; public class AddTodoCommand extends Command{ @Override diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index a6f7793cf..3389421b6 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -35,15 +35,7 @@ public static void main(String[] args) throws IOException { while (! processAllCommands.isExit(input)) { processAllCommands.executeLine(taskList, input); input = in.nextLine(); - } - try { - Storage.updateFile(taskList); - - } catch (IOException e) { - System.out.println("Error occurred"); - } - System.out.println(Messages.DIVIDER); System.out.println(Messages.EXITMESSAGE); System.out.println(Messages.DIVIDER); diff --git a/src/main/java/DeleteTaskCommand.java b/src/main/java/DeleteTaskCommand.java index 8c925e203..ab361bd84 100644 --- a/src/main/java/DeleteTaskCommand.java +++ b/src/main/java/DeleteTaskCommand.java @@ -1,3 +1,5 @@ +import java.io.IOException; + public class DeleteTaskCommand extends Command{ @Override @@ -13,6 +15,5 @@ public void executeCommand(TaskList taskList, String input) { } - } } diff --git a/src/main/java/ListCommand.java b/src/main/java/ListCommand.java index c6383a625..f0f96321f 100644 --- a/src/main/java/ListCommand.java +++ b/src/main/java/ListCommand.java @@ -2,7 +2,10 @@ public class ListCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { System.out.println(Messages.DIVIDER); - System.out.println("Here is the list of tasks you have remaining! Come on Buddy!"); + if (!taskList.isEmpty()){ + System.out.println("Here is the list of tasks you have remaining! Come on Buddy!"); + + } int index = 1; // index which shows numbers the task for (int i = 0; i < Buddy.taskCount; i++) { System.out.println(index + "." + taskList.get(i)); diff --git a/src/main/java/MarkTaskCommand.java b/src/main/java/MarkTaskCommand.java index 08c2b7f06..aff29a468 100644 --- a/src/main/java/MarkTaskCommand.java +++ b/src/main/java/MarkTaskCommand.java @@ -1,3 +1,5 @@ +import java.io.IOException; + public class MarkTaskCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { @@ -8,6 +10,7 @@ public void executeCommand(TaskList taskList, String input) { Task taskToBeMarked = taskList.get(indexOfTaskToBeMarked); taskToBeMarked.markAsDone(); + }catch(IndexOutOfBoundsException e){ System.out.println("That is not a valid task to mark! Please check your list again and input a valid task"); } diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 59da57663..b10c85e1b 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,67 +1,79 @@ import java.io.IOException; -public class Parser{ +public class Parser { - public boolean isExit(String input){ + public boolean isExit(String input) { return input.equals("bye"); } public void executeLine(TaskList taskList, String input) throws IOException { String[] inputSplit = input.split(" ", 2); String commandName = inputSplit[0].trim(); + try { + switch (commandName) { + case "todo": + Command addTodo = new AddTodoCommand(); + addTodo.executeCommand(taskList, input); + break; - switch (commandName){ - case "todo": - Command addTodo = new AddTodoCommand(); - addTodo.executeCommand(taskList, input); - Storage.updateFile(taskList); - break; - - case "deadline": - Command addDeadline = new AddDeadlineCommand(); - addDeadline.executeCommand(taskList, input); - Storage.updateFile(taskList); - break; - - case "event": - Command addEvent = new AddEventCommand(); - addEvent.executeCommand(taskList, input); - Storage.updateFile(taskList); - break; - - case "list": - Command list = new ListCommand(); - list.executeCommand(taskList, input); - break; - - case "mark": - Command mark = new MarkTaskCommand(); - mark.executeCommand(taskList, input); - Storage.updateFile(taskList); - break; - - case "unmark": - Command unmark = new UnmarkTaskCommand(); - unmark.executeCommand(taskList, input); - Storage.updateFile(taskList); - break; - - case "delete": - Command delete = new DeleteTaskCommand(); - delete.executeCommand(taskList, input); - Storage.updateFile(taskList); - break; - - case "find": - Command find = new FindTaskCommand(); - find.executeCommand(taskList, input); - break; - case "help": - Command help = new HelpCommand(); - help.executeCommand(taskList, input); - - default: + case "deadline": + Command addDeadline = new AddDeadlineCommand(); + addDeadline.executeCommand(taskList, input); + break; + + case "event": + Command addEvent = new AddEventCommand(); + addEvent.executeCommand(taskList, input); + break; + + case "list": + Command list = new ListCommand(); + list.executeCommand(taskList, input); + break; + + case "mark": + Command mark = new MarkTaskCommand(); + mark.executeCommand(taskList, input); + break; + + case "unmark": + Command unmark = new UnmarkTaskCommand(); + unmark.executeCommand(taskList, input); + break; + + case "delete": + Command delete = new DeleteTaskCommand(); + delete.executeCommand(taskList, input); + + break; + + case "find": + Command find = new FindTaskCommand(); + find.executeCommand(taskList, input); + break; + + case "help": + Command help = new HelpCommand(); + help.executeCommand(taskList, input); + + default: + throw new InvalidCommandException(); + } + + } catch (InvalidCommandException e) { + InvalidCommandException.printMessage(); + } + + try{ + Storage.updateFile(taskList); + }catch (IOException e){ + System.out.println("IO Error"); } + + + + + } } diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 087ba3a67..77f172328 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -33,7 +33,7 @@ public static void createFile() { } } - public static void updateFile(ArrayList taskList) throws IOException { + public static void updateFile(TaskList taskList) throws IOException { /*try { createFile(); } catch (IOException e) { @@ -59,14 +59,13 @@ public static void updateFile(ArrayList taskList) throws IOException { break; default: } - } overwriteFile.close(); } - public static void loadFile(ArrayList taskList) throws FileNotFoundException { + public static void loadFile(TaskList taskList) throws FileNotFoundException { File file = new File("Buddy.txt"); Scanner s = new Scanner(file); while (s.hasNext()) { diff --git a/src/main/java/UnmarkTaskCommand.java b/src/main/java/UnmarkTaskCommand.java index 959a879af..b0388805f 100644 --- a/src/main/java/UnmarkTaskCommand.java +++ b/src/main/java/UnmarkTaskCommand.java @@ -1,3 +1,5 @@ +import java.io.IOException; + public class UnmarkTaskCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { @@ -8,6 +10,7 @@ public void executeCommand(TaskList taskList, String input) { Task taskToBeUnmarked = taskList.get(indexOfTaskToBeUnmarked); taskToBeUnmarked.markAsUndone(); + }catch(IndexOutOfBoundsException e){ System.out.println("That is not a valid task to unmark! Please check your list again and input a valid task"); } From 3ffea719d2a22843c7938c6de2d0d5d199631fd4 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 12:35:33 +0800 Subject: [PATCH 41/54] Added MoreOOP everything works --- src/main/java/Buddy.java | 22 ++++++++-------------- src/main/java/HelpCommand.java | 2 +- src/main/java/Messages.java | 3 --- src/main/java/Parser.java | 2 +- src/main/java/Ui.java | 12 +++++++----- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java index 3389421b6..dbca98e84 100644 --- a/src/main/java/Buddy.java +++ b/src/main/java/Buddy.java @@ -6,11 +6,14 @@ public class Buddy { - + private Storage storage; + private TaskList taskList; + private Ui ui; public static int taskCount = 0; - public static void main(String[] args) throws IOException { + + public static void main(String[] args){ TaskList taskList = new TaskList(); try { Storage.loadFile(taskList); @@ -18,27 +21,18 @@ public static void main(String[] args) throws IOException { } catch (FileNotFoundException e) { System.out.println("File not found"); Storage.createFile(); - } - System.out.println(Messages.DIVIDER); - System.out.println(Messages.GREETING); - System.out.println(Messages.INTRODUCTION); - System.out.println(Messages.DIVIDER); - - + Ui.greetUser(); String input; Scanner in = new Scanner(System.in); input = in.nextLine(); Parser processAllCommands = new Parser(); while (! processAllCommands.isExit(input)) { - processAllCommands.executeLine(taskList, input); + processAllCommands.executeInput(taskList, input); input = in.nextLine(); } - System.out.println(Messages.DIVIDER); - System.out.println(Messages.EXITMESSAGE); - System.out.println(Messages.DIVIDER); - + Ui.sayByeToUser(); } } diff --git a/src/main/java/HelpCommand.java b/src/main/java/HelpCommand.java index 5f23a4c95..77c623908 100644 --- a/src/main/java/HelpCommand.java +++ b/src/main/java/HelpCommand.java @@ -2,7 +2,7 @@ public class HelpCommand extends Command{ @Override public void executeCommand(TaskList taskList, String input) { System.out.println(Messages.DIVIDER); - System.out.println(Messages.HELPMESSAGE); + Ui.displayHelpMessage(); System.out.println(Messages.DIVIDER); } } diff --git a/src/main/java/Messages.java b/src/main/java/Messages.java index 5a31ed1e7..ef086e5a2 100644 --- a/src/main/java/Messages.java +++ b/src/main/java/Messages.java @@ -26,7 +26,4 @@ public class Messages { "bye: exits the application\n" + "FORMAT: bye\n" + "Hope that this was useful!"; - - - } diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index b10c85e1b..d3c2cdb93 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -6,7 +6,7 @@ public boolean isExit(String input) { return input.equals("bye"); } - public void executeLine(TaskList taskList, String input) throws IOException { + public void executeInput(TaskList taskList, String input) { String[] inputSplit = input.split(" ", 2); String commandName = inputSplit[0].trim(); try { diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 7ca8c8417..f072a3bf4 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,15 +1,17 @@ public class Ui { - public void greetUser(){ + public static void greetUser(){ + System.out.println(Messages.DIVIDER); System.out.println(Messages.GREETING); - } - public void giveIntroToUser(){ System.out.println(Messages.INTRODUCTION); + System.out.println(Messages.DIVIDER); } - public void displayHelpMessage(){ + public static void displayHelpMessage(){ System.out.println(Messages.HELPMESSAGE); } - public void sayByeToUser(){ + public static void sayByeToUser(){ + System.out.println(Messages.DIVIDER); System.out.println(Messages.EXITMESSAGE); + System.out.println(Messages.DIVIDER); } } From 2675b55e98197ed47def81ea3679bac7e5042501 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 15:22:59 +0800 Subject: [PATCH 42/54] added to main, debugging issues --- README.md | 2 +- src/main/java/Buddy.java | 38 ----------------- src/main/java/buddy/Buddy.java | 42 +++++++++++++++++++ .../java/{ => buddy/commands}/Command.java | 6 +-- .../actionCommands}/DeleteTaskCommand.java | 7 +++- .../actionCommands}/FindTaskCommand.java | 13 ++++-- .../commands/actionCommands}/HelpCommand.java | 9 +++- .../commands/actionCommands}/ListCommand.java | 9 +++- .../actionCommands}/MarkTaskCommand.java | 5 ++- .../actionCommands}/UnmarkTaskCommand.java | 5 ++- .../addTaskCommands}/AddDeadlineCommand.java | 10 ++++- .../addTaskCommands}/AddEventCommand.java | 6 ++- .../addTaskCommands}/AddTodoCommand.java | 8 +++- .../exception}/InvalidCommandException.java | 4 +- .../java/{ => buddy/messages}/Messages.java | 6 ++- src/main/java/{ => buddy/parser}/Parser.java | 12 +++++- .../java/{ => buddy/storage}/Storage.java | 42 +++++++++---------- src/main/java/{ => buddy/tasks}/Deadline.java | 2 + src/main/java/{ => buddy/tasks}/Event.java | 2 + src/main/java/{ => buddy/tasks}/Task.java | 9 +++- src/main/java/{ => buddy/tasks}/TaskList.java | 9 +++- src/main/java/{ => buddy/tasks}/Todo.java | 2 + src/main/java/{ => buddy/ui}/Ui.java | 17 ++++++++ text-ui-test/EXPECTED.TXT | 10 ++--- text-ui-test/runtest.bat | 2 +- 25 files changed, 183 insertions(+), 94 deletions(-) delete mode 100644 src/main/java/Buddy.java create mode 100644 src/main/java/buddy/Buddy.java rename src/main/java/{ => buddy/commands}/Command.java (64%) rename src/main/java/{ => buddy/commands/actionCommands}/DeleteTaskCommand.java (79%) rename src/main/java/{ => buddy/commands/actionCommands}/FindTaskCommand.java (66%) rename src/main/java/{ => buddy/commands/actionCommands}/HelpCommand.java (52%) rename src/main/java/{ => buddy/commands/actionCommands}/ListCommand.java (74%) rename src/main/java/{ => buddy/commands/actionCommands}/MarkTaskCommand.java (87%) rename src/main/java/{ => buddy/commands/actionCommands}/UnmarkTaskCommand.java (87%) rename src/main/java/{ => buddy/commands/addTaskCommands}/AddDeadlineCommand.java (82%) rename src/main/java/{ => buddy/commands/addTaskCommands}/AddEventCommand.java (86%) rename src/main/java/{ => buddy/commands/addTaskCommands}/AddTodoCommand.java (71%) rename src/main/java/{ => buddy/exception}/InvalidCommandException.java (87%) rename src/main/java/{ => buddy/messages}/Messages.java (92%) rename src/main/java/{ => buddy/parser}/Parser.java (86%) rename src/main/java/{ => buddy/storage}/Storage.java (77%) rename src/main/java/{ => buddy/tasks}/Deadline.java (95%) rename src/main/java/{ => buddy/tasks}/Event.java (96%) rename src/main/java/{ => buddy/tasks}/Task.java (89%) rename src/main/java/{ => buddy/tasks}/TaskList.java (88%) rename src/main/java/{ => buddy/tasks}/Todo.java (94%) rename src/main/java/{ => buddy/ui}/Ui.java (56%) diff --git a/README.md b/README.md index 8715d4d91..014a6b49a 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version. 1. If there are any further prompts, accept the defaults. 1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: +3. After that, locate the `src/buddy.main/java/Duke.java` file, right-click it, and choose `Run Duke.buddy.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 ____ _ diff --git a/src/main/java/Buddy.java b/src/main/java/Buddy.java deleted file mode 100644 index dbca98e84..000000000 --- a/src/main/java/Buddy.java +++ /dev/null @@ -1,38 +0,0 @@ - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Scanner; - - - -public class Buddy { - private Storage storage; - private TaskList taskList; - private Ui ui; - public static int taskCount = 0; - - - - public static void main(String[] args){ - TaskList taskList = new TaskList(); - try { - Storage.loadFile(taskList); - - } catch (FileNotFoundException e) { - System.out.println("File not found"); - Storage.createFile(); - } - - Ui.greetUser(); - String input; - Scanner in = new Scanner(System.in); - input = in.nextLine(); - Parser processAllCommands = new Parser(); - - while (! processAllCommands.isExit(input)) { - processAllCommands.executeInput(taskList, input); - input = in.nextLine(); - } - Ui.sayByeToUser(); - } -} diff --git a/src/main/java/buddy/Buddy.java b/src/main/java/buddy/Buddy.java new file mode 100644 index 000000000..745e0182e --- /dev/null +++ b/src/main/java/buddy/Buddy.java @@ -0,0 +1,42 @@ +package buddy; + +import java.util.Scanner; + +import buddy.parser.Parser; +import buddy.storage.Storage; +import buddy.tasks.*; +import buddy.ui.Ui; + + +public class Buddy { + private final Storage storage; + private static TaskList taskList; + private final Ui ui; + public static int taskCount = 0; + + + public Buddy(String filePath){ + taskList = new TaskList(); + storage = new Storage(filePath); + ui = new Ui(); + + } + public void run(){ + ui.loadFileOrCreateFile(taskList, storage); + ui.greetUser(); + String input; + Scanner in = new Scanner(System.in); + input = in.nextLine(); + Parser processAllCommands = new Parser(); + + while (! processAllCommands.isExit(input)) { + processAllCommands.executeInput(taskList, input, storage); + input = in.nextLine(); + } + Ui.sayByeToUser(); + } + public static void main(String[] args){ + new Buddy("./buddy.txt").run(); + + } +} diff --git a/src/main/java/Command.java b/src/main/java/buddy/commands/Command.java similarity index 64% rename from src/main/java/Command.java rename to src/main/java/buddy/commands/Command.java index 9f6dd7389..e44ad825a 100644 --- a/src/main/java/Command.java +++ b/src/main/java/buddy/commands/Command.java @@ -1,7 +1,5 @@ -import java.util.ArrayList; -import java.text.ParseException; -import java.util.zip.DataFormatException; - +package buddy.commands; +import buddy.tasks.*; public abstract class Command { public abstract void executeCommand(TaskList taskList, String input); // executes the commands differently based on the various types of commands diff --git a/src/main/java/DeleteTaskCommand.java b/src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java similarity index 79% rename from src/main/java/DeleteTaskCommand.java rename to src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java index ab361bd84..97f3c1f2f 100644 --- a/src/main/java/DeleteTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java @@ -1,6 +1,9 @@ -import java.io.IOException; +package buddy.commands.actionCommands; -public class DeleteTaskCommand extends Command{ +import buddy.commands.Command; +import buddy.tasks.*; + +public class DeleteTaskCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { diff --git a/src/main/java/FindTaskCommand.java b/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java similarity index 66% rename from src/main/java/FindTaskCommand.java rename to src/main/java/buddy/commands/actionCommands/FindTaskCommand.java index 682df7055..1a4b7f134 100644 --- a/src/main/java/FindTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java @@ -1,7 +1,14 @@ +package buddy.commands.actionCommands; + +import buddy.messages.Messages; +import buddy.commands.Command; +import buddy.tasks.*; + import java.util.ArrayList; + import static java.util.stream.Collectors.toList; -public class FindTaskCommand extends Command{ +public class FindTaskCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { String keyword = input.split(" ")[1].trim().toLowerCase(); @@ -10,13 +17,13 @@ public void executeCommand(TaskList taskList, String input) { .filter(t -> t.getTaskName().trim().toLowerCase().contains(keyword)).collect(toList()); System.out.println(Messages.DIVIDER); if (!matchedTasks.isEmpty()){ - System.out.println("Well, here is the list of tasks matching your keyword!"); + System.out.println("Well, here is the list of buddy.tasks matching your keyword!"); } for (Task task : matchedTasks){ System.out.println(task); } if (matchedTasks.isEmpty()){ - System.out.println("Oops, there are no tasks matching the keyword! Try again with another keyword"); + System.out.println("Oops, there are no buddy.tasks matching the keyword! Try again with another keyword"); } System.out.println(Messages.DIVIDER); diff --git a/src/main/java/HelpCommand.java b/src/main/java/buddy/commands/actionCommands/HelpCommand.java similarity index 52% rename from src/main/java/HelpCommand.java rename to src/main/java/buddy/commands/actionCommands/HelpCommand.java index 77c623908..0415b349e 100644 --- a/src/main/java/HelpCommand.java +++ b/src/main/java/buddy/commands/actionCommands/HelpCommand.java @@ -1,4 +1,11 @@ -public class HelpCommand extends Command{ +package buddy.commands.actionCommands; + +import buddy.messages.Messages; +import buddy.ui.Ui; +import buddy.commands.Command; +import buddy.tasks.*; + +public class HelpCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { System.out.println(Messages.DIVIDER); diff --git a/src/main/java/ListCommand.java b/src/main/java/buddy/commands/actionCommands/ListCommand.java similarity index 74% rename from src/main/java/ListCommand.java rename to src/main/java/buddy/commands/actionCommands/ListCommand.java index f0f96321f..0976f8558 100644 --- a/src/main/java/ListCommand.java +++ b/src/main/java/buddy/commands/actionCommands/ListCommand.java @@ -1,9 +1,16 @@ +package buddy.commands.actionCommands; + +import buddy.Buddy; +import buddy.messages.Messages; +import buddy.commands.Command; +import buddy.tasks.*; + public class ListCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { System.out.println(Messages.DIVIDER); if (!taskList.isEmpty()){ - System.out.println("Here is the list of tasks you have remaining! Come on Buddy!"); + System.out.println("Here is the list of buddy.tasks you have remaining! Come on Buddy!"); } int index = 1; // index which shows numbers the task diff --git a/src/main/java/MarkTaskCommand.java b/src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java similarity index 87% rename from src/main/java/MarkTaskCommand.java rename to src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java index aff29a468..cf61614da 100644 --- a/src/main/java/MarkTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java @@ -1,4 +1,7 @@ -import java.io.IOException; +package buddy.commands.actionCommands; + +import buddy.commands.Command; +import buddy.tasks.*; public class MarkTaskCommand extends Command { @Override diff --git a/src/main/java/UnmarkTaskCommand.java b/src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java similarity index 87% rename from src/main/java/UnmarkTaskCommand.java rename to src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java index b0388805f..c852fea26 100644 --- a/src/main/java/UnmarkTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java @@ -1,4 +1,7 @@ -import java.io.IOException; +package buddy.commands.actionCommands; + +import buddy.commands.Command; +import buddy.tasks.*; public class UnmarkTaskCommand extends Command { @Override diff --git a/src/main/java/AddDeadlineCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java similarity index 82% rename from src/main/java/AddDeadlineCommand.java rename to src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java index 42c9ea281..b9569b99e 100644 --- a/src/main/java/AddDeadlineCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java @@ -1,9 +1,15 @@ -import java.io.IOException; +package buddy.commands.addTaskCommands; + +import buddy.exception.InvalidCommandException; +import buddy.commands.Command; + import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import buddy.tasks.TaskList; +import buddy.tasks.*; -public class AddDeadlineCommand extends Command{ +public class AddDeadlineCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { diff --git a/src/main/java/AddEventCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java similarity index 86% rename from src/main/java/AddEventCommand.java rename to src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java index f3f0246e6..5115b3830 100644 --- a/src/main/java/AddEventCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java @@ -1,4 +1,8 @@ -import java.io.IOException; +package buddy.commands.addTaskCommands; + +import buddy.exception.InvalidCommandException; +import buddy.commands.Command; +import buddy.tasks.*; public class AddEventCommand extends Command { @Override diff --git a/src/main/java/AddTodoCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java similarity index 71% rename from src/main/java/AddTodoCommand.java rename to src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java index 6c1c28707..5024e22a6 100644 --- a/src/main/java/AddTodoCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java @@ -1,6 +1,10 @@ -import java.io.IOException; +package buddy.commands.addTaskCommands; -public class AddTodoCommand extends Command{ +import buddy.exception.InvalidCommandException; +import buddy.commands.Command; +import buddy.tasks.*; + +public class AddTodoCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { try{ diff --git a/src/main/java/InvalidCommandException.java b/src/main/java/buddy/exception/InvalidCommandException.java similarity index 87% rename from src/main/java/InvalidCommandException.java rename to src/main/java/buddy/exception/InvalidCommandException.java index 784eaa559..58a12b513 100644 --- a/src/main/java/InvalidCommandException.java +++ b/src/main/java/buddy/exception/InvalidCommandException.java @@ -1,6 +1,8 @@ +package buddy.exception; + public class InvalidCommandException extends Exception{ public static void printMessage(){ System.out.println("This is an invalid command! Please check and type in again"); } -} +} \ No newline at end of file diff --git a/src/main/java/Messages.java b/src/main/java/buddy/messages/Messages.java similarity index 92% rename from src/main/java/Messages.java rename to src/main/java/buddy/messages/Messages.java index ef086e5a2..5153ac459 100644 --- a/src/main/java/Messages.java +++ b/src/main/java/buddy/messages/Messages.java @@ -1,3 +1,5 @@ +package buddy.messages; + public class Messages { public static final String DIVIDER = "________________________________________________________________________________"; public static final String GREETING = "Hello there! I'm Buddy\n" @@ -6,7 +8,7 @@ public class Messages { public static final String EXITMESSAGE = "Hope I was of help to you! Have a great day and see you again, Buddy :)"; public static final String HELPMESSAGE = "These are the various commands and their functions. Please type in the FORMAT that is stated below\n" + - "There are 3 add task commands which add 3 kinds of tasks: todo, deadline and event\n" + + "There are 3 add task commands which add 3 kinds of buddy.tasks: todo, deadline and event\n" + "todo: Adds a todo to your task list\n" + "FORMAT: todo \n" + "deadline: Adds a deadline to your task list\n" + @@ -15,7 +17,7 @@ public class Messages { "event: Adds an event to your task list\n" + "FORMAT: event /from /to \n" + "There are 5 other action commands: list, mark, unmark, find and bye\n" + - "list: lists all the tasks that you have remaining\n" + + "list: lists all the buddy.tasks that you have remaining\n" + "FORMAT: list\n" + "mark: marks a task as done with an X\n" + "FORMAT: mark \n" + diff --git a/src/main/java/Parser.java b/src/main/java/buddy/parser/Parser.java similarity index 86% rename from src/main/java/Parser.java rename to src/main/java/buddy/parser/Parser.java index d3c2cdb93..e6d989364 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/buddy/parser/Parser.java @@ -1,4 +1,12 @@ +package buddy.parser; + import java.io.IOException; +import buddy.commands.*; +import buddy.commands.actionCommands.*; +import buddy.commands.addTaskCommands.*; +import buddy.exception.InvalidCommandException; +import buddy.storage.Storage; +import buddy.tasks.*; public class Parser { @@ -6,7 +14,7 @@ public boolean isExit(String input) { return input.equals("bye"); } - public void executeInput(TaskList taskList, String input) { + public void executeInput(TaskList taskList, String input, Storage storage) { String[] inputSplit = input.split(" ", 2); String commandName = inputSplit[0].trim(); try { @@ -65,7 +73,7 @@ public void executeInput(TaskList taskList, String input) { } try{ - Storage.updateFile(taskList); + storage.updateFile(taskList); }catch (IOException e){ System.out.println("IO Error"); } diff --git a/src/main/java/Storage.java b/src/main/java/buddy/storage/Storage.java similarity index 77% rename from src/main/java/Storage.java rename to src/main/java/buddy/storage/Storage.java index 77f172328..4c24caf5d 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/buddy/storage/Storage.java @@ -1,26 +1,29 @@ +package buddy.storage; + +import buddy.Buddy; +import buddy.tasks.TaskList; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; -import java.util.ArrayList; import java.util.Scanner; -import java.text.ParseException; -import java.util.zip.DataFormatException; - +import buddy.tasks.*; public class Storage { - public static void createFile() { - //File directory = new File("Buddy.txt"); - File newFile = new File("Buddy.txt"); + private final String filePath; + public Storage(String filePath){ + this.filePath = filePath; + } + public void createFile(){ + //File directory = new File(filePath); + File newFile = new File(filePath); try { - //if(directory.mkdirs()){ - // System.out.println("Directory has been created :)"); - // } - //else { - // System.out.println("Directory exists already!"); - // } + /* if (!directory.exists()){ + System.out.println("Directory has been created :)"); + }*/ if (newFile.createNewFile()) { System.out.println("File has been created :)"); @@ -33,13 +36,8 @@ public static void createFile() { } } - public static void updateFile(TaskList taskList) throws IOException { - /*try { - createFile(); - } catch (IOException e) { - System.out.println("Error occurred as the file probably exists"); - }*/ - FileWriter overwriteFile = new FileWriter("Buddy.txt"); + public void updateFile(TaskList taskList) throws IOException { + FileWriter overwriteFile = new FileWriter(filePath); for (Task task : taskList) { String taskType = task.getType(); String taskName = task.getTaskName(); @@ -65,8 +63,8 @@ public static void updateFile(TaskList taskList) throws IOException { } - public static void loadFile(TaskList taskList) throws FileNotFoundException { - File file = new File("Buddy.txt"); + public void loadFile(TaskList taskList) throws FileNotFoundException { + File file = new File(filePath); Scanner s = new Scanner(file); while (s.hasNext()) { String line = s.nextLine(); diff --git a/src/main/java/Deadline.java b/src/main/java/buddy/tasks/Deadline.java similarity index 95% rename from src/main/java/Deadline.java rename to src/main/java/buddy/tasks/Deadline.java index 181b95d6c..3485aa010 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/buddy/tasks/Deadline.java @@ -1,3 +1,5 @@ +package buddy.tasks; + public class Deadline extends Task { protected String by; diff --git a/src/main/java/Event.java b/src/main/java/buddy/tasks/Event.java similarity index 96% rename from src/main/java/Event.java rename to src/main/java/buddy/tasks/Event.java index 789ac0230..bcc977b33 100644 --- a/src/main/java/Event.java +++ b/src/main/java/buddy/tasks/Event.java @@ -1,3 +1,5 @@ +package buddy.tasks; + public class Event extends Task { protected String from; diff --git a/src/main/java/Task.java b/src/main/java/buddy/tasks/Task.java similarity index 89% rename from src/main/java/Task.java rename to src/main/java/buddy/tasks/Task.java index c45b4e24e..de08f0b34 100644 --- a/src/main/java/Task.java +++ b/src/main/java/buddy/tasks/Task.java @@ -1,3 +1,8 @@ +package buddy.tasks; + +import buddy.Buddy; +import buddy.messages.Messages; + public class Task { protected String description; protected boolean isDone; @@ -50,7 +55,7 @@ public void printAfterAddingTask(){ System.out.println("Got it! I have added this task!: \n" + this + "\n" + "Now you have " + Buddy.taskCount + " task remaining! Almost there, buddy!"); } else{ - System.out.println("Got it! I have added this task! \n" + this + "\n" + "Now you have " + Buddy.taskCount + " tasks remaining! Let's finish them faster and relax!"); + System.out.println("Got it! I have added this task! \n" + this + "\n" + "Now you have " + Buddy.taskCount + " buddy.tasks remaining! Let's finish them faster and relax!"); } @@ -62,7 +67,7 @@ public void printAfterDeletingTask() { } else if (Buddy.taskCount == 1) { System.out.println("YAY ONE LESS TO GO! I have deleted this task!: \n" + this + "\n" + "Now you have JUST " + Buddy.taskCount + " task remaining! CHOP CHOP FINISH IT"); } else{ - System.out.println("YAY ONE LESS TO GO! I have deleted this task!: \n" + this + "\n" + "Now you have " + Buddy.taskCount + " tasks remaining! Type list to see remaining tasks"); + System.out.println("YAY ONE LESS TO GO! I have deleted this task!: \n" + this + "\n" + "Now you have " + Buddy.taskCount + " buddy.tasks remaining! Type list to see remaining buddy.tasks"); } } diff --git a/src/main/java/TaskList.java b/src/main/java/buddy/tasks/TaskList.java similarity index 88% rename from src/main/java/TaskList.java rename to src/main/java/buddy/tasks/TaskList.java index af99bfe7c..7256e2e76 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/buddy/tasks/TaskList.java @@ -1,10 +1,15 @@ +package buddy.tasks; + +import buddy.Buddy; +import buddy.messages.Messages; + import java.util.ArrayList; public class TaskList extends ArrayList { public void addTask (Task newTask){ System.out.println(Messages.DIVIDER); this.add(newTask); // new task is added to taskList - Buddy.taskCount++; // increments number of tasks + Buddy.taskCount++; // increments number of buddy.tasks newTask.printAfterAddingTask(); // print message once new task is added (From Task class) System.out.println(Messages.DIVIDER); } @@ -12,7 +17,7 @@ public void addTask (Task newTask){ public void deleteTask (int indexOfTaskToDelete){ System.out.println(Messages.DIVIDER); Task taskToBeDeleted = this.get(indexOfTaskToDelete); - Buddy.taskCount--; // decrements number of tasks + Buddy.taskCount--; // decrements number of buddy.tasks taskToBeDeleted.printAfterDeletingTask(); this.remove(indexOfTaskToDelete); // delete task from taskList System.out.println(Messages.DIVIDER); diff --git a/src/main/java/Todo.java b/src/main/java/buddy/tasks/Todo.java similarity index 94% rename from src/main/java/Todo.java rename to src/main/java/buddy/tasks/Todo.java index 6fd392806..0aa250f09 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/buddy/tasks/Todo.java @@ -1,3 +1,5 @@ +package buddy.tasks; + public class Todo extends Task { protected boolean isDone; public Todo(String description) { diff --git a/src/main/java/Ui.java b/src/main/java/buddy/ui/Ui.java similarity index 56% rename from src/main/java/Ui.java rename to src/main/java/buddy/ui/Ui.java index f072a3bf4..c65a3ae03 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/buddy/ui/Ui.java @@ -1,3 +1,11 @@ +package buddy.ui; + +import buddy.messages.Messages; +import buddy.storage.Storage; +import buddy.tasks.*; + +import java.io.FileNotFoundException; + public class Ui { public static void greetUser(){ @@ -14,4 +22,13 @@ public static void sayByeToUser(){ System.out.println(Messages.EXITMESSAGE); System.out.println(Messages.DIVIDER); } + public static void loadFileOrCreateFile(TaskList taskList, Storage storage){ + try { + storage.loadFile(taskList); + + } catch (FileNotFoundException e) { + System.out.println("File not found"); + storage.createFile(); + } + } } diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index d536451ca..6ca1ea139 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,5 +1,5 @@ ________________________________________________________________________________ -Hello there! I'm Buddy +Hello there! I'm buddy How may I assist you? Here are the possible commands: todo, deadline, event, list, mark, unmark, find, bye Type if you are unsure of what these commands do! @@ -12,12 +12,12 @@ ________________________________________________________________________________ ________________________________________________________________________________ Got it! I have added this task! [D][ ] cg mod (Please do by: Dec 1 2023!) -Now you have 2 tasks remaining! Let's finish them faster and relax! +Now you have 2 buddy.tasks remaining! Let's finish them faster and relax! ________________________________________________________________________________ ________________________________________________________________________________ Got it! I have added this task! [E][ ] exam (from: 2pm to: 5pm) -Now you have 3 tasks remaining! Let's finish them faster and relax! +Now you have 3 buddy.tasks remaining! Let's finish them faster and relax! ________________________________________________________________________________ ________________________________________________________________________________ Great work on completing this task! Marked as done! :) @@ -32,11 +32,11 @@ Come on, don't procrastinate! Marked as undone! [T][ ] cs2113 ________________________________________________________________________________ ________________________________________________________________________________ -Here is the list of tasks you have remaining! Come on Buddy! +Here is the list of buddy.tasks you have remaining! Come on buddy! 1.[T][ ] cs2113 2.[D][X] cg mod (Please do by: Dec 1 2023!) 3.[E][ ] exam (from: 2pm to: 5pm) ________________________________________________________________________________ ________________________________________________________________________________ -Hope I was of help to you! Have a great day and see you again, Buddy :) +Hope I was of help to you! Have a great day and see you again, buddy :) ________________________________________________________________________________ \ No newline at end of file diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 087374464..54ff33dec 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -7,7 +7,7 @@ REM delete output from previous run if exist ACTUAL.TXT del ACTUAL.TXT REM compile the code into the bin folder -javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java +javac -cp ..\src\buddy.main\java -Xlint:none -d ..\bin ..\src\buddy.main\java\*.java IF ERRORLEVEL 1 ( echo ********** BUILD FAILURE ********** exit /b 1 From 39a3bfbd992c25759f52ef017986ab5459f1a7aa Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 15:39:10 +0800 Subject: [PATCH 43/54] file works WITHOUT directory --- src/main/java/buddy/Buddy.java | 2 +- .../java/buddy/commands/actionCommands/FindTaskCommand.java | 4 ++-- src/main/java/buddy/commands/actionCommands/ListCommand.java | 2 +- src/main/java/buddy/tasks/Task.java | 5 ++--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/buddy/Buddy.java b/src/main/java/buddy/Buddy.java index 745e0182e..5703d0b81 100644 --- a/src/main/java/buddy/Buddy.java +++ b/src/main/java/buddy/Buddy.java @@ -33,7 +33,7 @@ public void run(){ processAllCommands.executeInput(taskList, input, storage); input = in.nextLine(); } - Ui.sayByeToUser(); + ui.sayByeToUser(); } public static void main(String[] args){ new Buddy("./buddy.txt").run(); diff --git a/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java b/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java index 1a4b7f134..89fa4feec 100644 --- a/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java @@ -17,13 +17,13 @@ public void executeCommand(TaskList taskList, String input) { .filter(t -> t.getTaskName().trim().toLowerCase().contains(keyword)).collect(toList()); System.out.println(Messages.DIVIDER); if (!matchedTasks.isEmpty()){ - System.out.println("Well, here is the list of buddy.tasks matching your keyword!"); + System.out.println("Well, here is the list of tasks matching your keyword!"); } for (Task task : matchedTasks){ System.out.println(task); } if (matchedTasks.isEmpty()){ - System.out.println("Oops, there are no buddy.tasks matching the keyword! Try again with another keyword"); + System.out.println("Oops, there are no tasks matching the keyword! Try again with another keyword"); } System.out.println(Messages.DIVIDER); diff --git a/src/main/java/buddy/commands/actionCommands/ListCommand.java b/src/main/java/buddy/commands/actionCommands/ListCommand.java index 0976f8558..141d42341 100644 --- a/src/main/java/buddy/commands/actionCommands/ListCommand.java +++ b/src/main/java/buddy/commands/actionCommands/ListCommand.java @@ -10,7 +10,7 @@ public class ListCommand extends Command { public void executeCommand(TaskList taskList, String input) { System.out.println(Messages.DIVIDER); if (!taskList.isEmpty()){ - System.out.println("Here is the list of buddy.tasks you have remaining! Come on Buddy!"); + System.out.println("Here is the list of tasks you have remaining! Come on Buddy!"); } int index = 1; // index which shows numbers the task diff --git a/src/main/java/buddy/tasks/Task.java b/src/main/java/buddy/tasks/Task.java index de08f0b34..89f99c147 100644 --- a/src/main/java/buddy/tasks/Task.java +++ b/src/main/java/buddy/tasks/Task.java @@ -6,7 +6,6 @@ public class Task { protected String description; protected boolean isDone; - protected String type; public Task(String description) { this.description = description; @@ -55,7 +54,7 @@ public void printAfterAddingTask(){ System.out.println("Got it! I have added this task!: \n" + this + "\n" + "Now you have " + Buddy.taskCount + " task remaining! Almost there, buddy!"); } else{ - System.out.println("Got it! I have added this task! \n" + this + "\n" + "Now you have " + Buddy.taskCount + " buddy.tasks remaining! Let's finish them faster and relax!"); + System.out.println("Got it! I have added this task! \n" + this + "\n" + "Now you have " + Buddy.taskCount + " tasks remaining! Let's finish them faster and relax!"); } @@ -67,7 +66,7 @@ public void printAfterDeletingTask() { } else if (Buddy.taskCount == 1) { System.out.println("YAY ONE LESS TO GO! I have deleted this task!: \n" + this + "\n" + "Now you have JUST " + Buddy.taskCount + " task remaining! CHOP CHOP FINISH IT"); } else{ - System.out.println("YAY ONE LESS TO GO! I have deleted this task!: \n" + this + "\n" + "Now you have " + Buddy.taskCount + " buddy.tasks remaining! Type list to see remaining buddy.tasks"); + System.out.println("YAY ONE LESS TO GO! I have deleted this task!: \n" + this + "\n" + "Now you have " + Buddy.taskCount + " tasks remaining! Type list to see remaining tasks"); } } From 856052cc6d0b126d0ace7afcbe3b5935ecc94285 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 16:23:02 +0800 Subject: [PATCH 44/54] imported packages without * so better coding standard --- src/main/java/buddy/Buddy.java | 3 +-- src/main/java/buddy/commands/Command.java | 2 +- .../actionCommands/DeleteTaskCommand.java | 2 +- .../commands/actionCommands/FindTaskCommand.java | 5 ++--- .../commands/actionCommands/HelpCommand.java | 2 +- .../commands/actionCommands/ListCommand.java | 2 +- .../commands/actionCommands/MarkTaskCommand.java | 3 ++- .../actionCommands/UnmarkTaskCommand.java | 3 ++- .../addTaskCommands/AddDeadlineCommand.java | 3 +-- .../addTaskCommands/AddEventCommand.java | 4 +++- .../commands/addTaskCommands/AddTodoCommand.java | 3 ++- src/main/java/buddy/parser/Parser.java | 16 ++++++++++++---- src/main/java/buddy/storage/Storage.java | 8 +++++--- src/main/java/buddy/tasks/TaskList.java | 1 - src/main/java/buddy/ui/Ui.java | 2 +- 15 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/main/java/buddy/Buddy.java b/src/main/java/buddy/Buddy.java index 5703d0b81..00dc5d8f2 100644 --- a/src/main/java/buddy/Buddy.java +++ b/src/main/java/buddy/Buddy.java @@ -1,10 +1,9 @@ package buddy; import java.util.Scanner; - import buddy.parser.Parser; import buddy.storage.Storage; -import buddy.tasks.*; +import buddy.tasks.TaskList; import buddy.ui.Ui; diff --git a/src/main/java/buddy/commands/Command.java b/src/main/java/buddy/commands/Command.java index e44ad825a..108e115a9 100644 --- a/src/main/java/buddy/commands/Command.java +++ b/src/main/java/buddy/commands/Command.java @@ -1,5 +1,5 @@ package buddy.commands; -import buddy.tasks.*; +import buddy.tasks.TaskList; public abstract class Command { public abstract void executeCommand(TaskList taskList, String input); // executes the commands differently based on the various types of commands diff --git a/src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java b/src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java index 97f3c1f2f..7e967f9ec 100644 --- a/src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java @@ -1,7 +1,7 @@ package buddy.commands.actionCommands; import buddy.commands.Command; -import buddy.tasks.*; +import buddy.tasks.TaskList; public class DeleteTaskCommand extends Command { diff --git a/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java b/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java index 89fa4feec..9add06a0f 100644 --- a/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java @@ -2,10 +2,9 @@ import buddy.messages.Messages; import buddy.commands.Command; -import buddy.tasks.*; - +import buddy.tasks.TaskList; +import buddy.tasks.Task; import java.util.ArrayList; - import static java.util.stream.Collectors.toList; public class FindTaskCommand extends Command { diff --git a/src/main/java/buddy/commands/actionCommands/HelpCommand.java b/src/main/java/buddy/commands/actionCommands/HelpCommand.java index 0415b349e..72a995126 100644 --- a/src/main/java/buddy/commands/actionCommands/HelpCommand.java +++ b/src/main/java/buddy/commands/actionCommands/HelpCommand.java @@ -3,7 +3,7 @@ import buddy.messages.Messages; import buddy.ui.Ui; import buddy.commands.Command; -import buddy.tasks.*; +import buddy.tasks.TaskList; public class HelpCommand extends Command { @Override diff --git a/src/main/java/buddy/commands/actionCommands/ListCommand.java b/src/main/java/buddy/commands/actionCommands/ListCommand.java index 141d42341..bc749363f 100644 --- a/src/main/java/buddy/commands/actionCommands/ListCommand.java +++ b/src/main/java/buddy/commands/actionCommands/ListCommand.java @@ -3,7 +3,7 @@ import buddy.Buddy; import buddy.messages.Messages; import buddy.commands.Command; -import buddy.tasks.*; +import buddy.tasks.TaskList; public class ListCommand extends Command { @Override diff --git a/src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java b/src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java index cf61614da..efe620d70 100644 --- a/src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java @@ -1,7 +1,8 @@ package buddy.commands.actionCommands; import buddy.commands.Command; -import buddy.tasks.*; +import buddy.tasks.TaskList; +import buddy.tasks.Task; public class MarkTaskCommand extends Command { @Override diff --git a/src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java b/src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java index c852fea26..4ad70373e 100644 --- a/src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java @@ -1,7 +1,8 @@ package buddy.commands.actionCommands; import buddy.commands.Command; -import buddy.tasks.*; +import buddy.tasks.TaskList; +import buddy.tasks.Task; public class UnmarkTaskCommand extends Command { @Override diff --git a/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java index b9569b99e..120b07140 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java @@ -2,11 +2,10 @@ import buddy.exception.InvalidCommandException; import buddy.commands.Command; - import java.time.LocalDate; import java.time.format.DateTimeFormatter; import buddy.tasks.TaskList; -import buddy.tasks.*; +import buddy.tasks.Deadline; public class AddDeadlineCommand extends Command { diff --git a/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java index 5115b3830..46d5a14f4 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java @@ -2,7 +2,9 @@ import buddy.exception.InvalidCommandException; import buddy.commands.Command; -import buddy.tasks.*; +import buddy.tasks.TaskList; +import buddy.tasks.Event; + public class AddEventCommand extends Command { @Override diff --git a/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java index 5024e22a6..abe1fdddf 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java @@ -2,7 +2,8 @@ import buddy.exception.InvalidCommandException; import buddy.commands.Command; -import buddy.tasks.*; +import buddy.tasks.TaskList; +import buddy.tasks.Todo; public class AddTodoCommand extends Command { @Override diff --git a/src/main/java/buddy/parser/Parser.java b/src/main/java/buddy/parser/Parser.java index e6d989364..257c2ee8b 100644 --- a/src/main/java/buddy/parser/Parser.java +++ b/src/main/java/buddy/parser/Parser.java @@ -1,12 +1,19 @@ package buddy.parser; import java.io.IOException; -import buddy.commands.*; -import buddy.commands.actionCommands.*; -import buddy.commands.addTaskCommands.*; +import buddy.commands.Command; +import buddy.commands.actionCommands.DeleteTaskCommand; +import buddy.commands.actionCommands.HelpCommand; +import buddy.commands.actionCommands.ListCommand; +import buddy.commands.actionCommands.MarkTaskCommand; +import buddy.commands.actionCommands.UnmarkTaskCommand; +import buddy.commands.actionCommands.FindTaskCommand; +import buddy.commands.addTaskCommands.AddTodoCommand; +import buddy.commands.addTaskCommands.AddDeadlineCommand; +import buddy.commands.addTaskCommands.AddEventCommand; import buddy.exception.InvalidCommandException; import buddy.storage.Storage; -import buddy.tasks.*; +import buddy.tasks.TaskList; public class Parser { @@ -63,6 +70,7 @@ public void executeInput(TaskList taskList, String input, Storage storage) { case "help": Command help = new HelpCommand(); help.executeCommand(taskList, input); + break; default: throw new InvalidCommandException(); diff --git a/src/main/java/buddy/storage/Storage.java b/src/main/java/buddy/storage/Storage.java index 4c24caf5d..f05579b62 100644 --- a/src/main/java/buddy/storage/Storage.java +++ b/src/main/java/buddy/storage/Storage.java @@ -2,13 +2,15 @@ import buddy.Buddy; import buddy.tasks.TaskList; - import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; -import buddy.tasks.*; +import buddy.tasks.Task; +import buddy.tasks.Todo; +import buddy.tasks.Deadline; +import buddy.tasks.Event; public class Storage { @@ -21,7 +23,7 @@ public void createFile(){ File newFile = new File(filePath); try { - /* if (!directory.exists()){ + /* if (directory.mkdirs()){ System.out.println("Directory has been created :)"); }*/ diff --git a/src/main/java/buddy/tasks/TaskList.java b/src/main/java/buddy/tasks/TaskList.java index 7256e2e76..e4fb5db05 100644 --- a/src/main/java/buddy/tasks/TaskList.java +++ b/src/main/java/buddy/tasks/TaskList.java @@ -2,7 +2,6 @@ import buddy.Buddy; import buddy.messages.Messages; - import java.util.ArrayList; public class TaskList extends ArrayList { diff --git a/src/main/java/buddy/ui/Ui.java b/src/main/java/buddy/ui/Ui.java index c65a3ae03..658d48372 100644 --- a/src/main/java/buddy/ui/Ui.java +++ b/src/main/java/buddy/ui/Ui.java @@ -2,7 +2,7 @@ import buddy.messages.Messages; import buddy.storage.Storage; -import buddy.tasks.*; +import buddy.tasks.TaskList; import java.io.FileNotFoundException; From e444e1b37754e6fa168087a5effebc6d9a3b1b28 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 17:07:58 +0800 Subject: [PATCH 45/54] LETS GO Storage Path changed with directory AND IT WORKS! --- src/main/java/buddy/Buddy.java | 2 +- src/main/java/buddy/storage/Storage.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/buddy/Buddy.java b/src/main/java/buddy/Buddy.java index 00dc5d8f2..92f5994a3 100644 --- a/src/main/java/buddy/Buddy.java +++ b/src/main/java/buddy/Buddy.java @@ -35,7 +35,7 @@ public void run(){ ui.sayByeToUser(); } public static void main(String[] args){ - new Buddy("./buddy.txt").run(); + new Buddy("./Data").run(); } } diff --git a/src/main/java/buddy/storage/Storage.java b/src/main/java/buddy/storage/Storage.java index f05579b62..64fa9f8bd 100644 --- a/src/main/java/buddy/storage/Storage.java +++ b/src/main/java/buddy/storage/Storage.java @@ -19,13 +19,13 @@ public Storage(String filePath){ this.filePath = filePath; } public void createFile(){ - //File directory = new File(filePath); - File newFile = new File(filePath); + File directory = new File(filePath); + File newFile = new File(filePath + "/BuddyTaskList.txt"); try { - /* if (directory.mkdirs()){ + if (directory.mkdirs()){ System.out.println("Directory has been created :)"); - }*/ + } if (newFile.createNewFile()) { System.out.println("File has been created :)"); @@ -39,7 +39,7 @@ public void createFile(){ } public void updateFile(TaskList taskList) throws IOException { - FileWriter overwriteFile = new FileWriter(filePath); + FileWriter overwriteFile = new FileWriter(filePath + "/BuddyTaskList.txt"); for (Task task : taskList) { String taskType = task.getType(); String taskName = task.getTaskName(); @@ -66,7 +66,7 @@ public void updateFile(TaskList taskList) throws IOException { public void loadFile(TaskList taskList) throws FileNotFoundException { - File file = new File(filePath); + File file = new File(filePath + "/BuddyTaskList.txt"); Scanner s = new Scanner(file); while (s.hasNext()) { String line = s.nextLine(); From acc7aeab0a104c960331e2c5d2452312a4ca46e4 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 17:16:03 +0800 Subject: [PATCH 46/54] minor reformatting of code --- src/main/java/buddy/Buddy.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/buddy/Buddy.java b/src/main/java/buddy/Buddy.java index 92f5994a3..36b38d868 100644 --- a/src/main/java/buddy/Buddy.java +++ b/src/main/java/buddy/Buddy.java @@ -13,12 +13,10 @@ public class Buddy { private final Ui ui; public static int taskCount = 0; - public Buddy(String filePath){ taskList = new TaskList(); storage = new Storage(filePath); ui = new Ui(); - } public void run(){ ui.loadFileOrCreateFile(taskList, storage); From beb0c51f7bee4e6e520637af998991bfa0797b14 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 19:06:24 +0800 Subject: [PATCH 47/54] Made minor documentation --- src/main/java/buddy/Buddy.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/buddy/Buddy.java b/src/main/java/buddy/Buddy.java index 36b38d868..aa42018a5 100644 --- a/src/main/java/buddy/Buddy.java +++ b/src/main/java/buddy/Buddy.java @@ -6,6 +6,9 @@ import buddy.tasks.TaskList; import buddy.ui.Ui; +/** + * The main of the application which executes the program. + */ public class Buddy { private final Storage storage; @@ -13,11 +16,19 @@ public class Buddy { private final Ui ui; public static int taskCount = 0; + /** + * Constructor for Buddy class + * @param filePath The filepath of the file + */ public Buddy(String filePath){ taskList = new TaskList(); storage = new Storage(filePath); ui = new Ui(); } + + /** + * This function runs the program till + */ public void run(){ ui.loadFileOrCreateFile(taskList, storage); ui.greetUser(); From 8cc346bf69f54bf79cad0890c9813e482869c3d3 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 20:13:55 +0800 Subject: [PATCH 48/54] Added ALL Documentation in the right format --- src/main/java/buddy/Buddy.java | 8 ++- src/main/java/buddy/commands/Command.java | 11 +++- .../actionCommands/DeleteTaskCommand.java | 7 +++ .../actionCommands/FindTaskCommand.java | 8 +++ .../commands/actionCommands/HelpCommand.java | 6 ++ .../commands/actionCommands/ListCommand.java | 7 +++ .../actionCommands/MarkTaskCommand.java | 7 +++ .../actionCommands/UnmarkTaskCommand.java | 7 +++ .../addTaskCommands/AddDeadlineCommand.java | 8 ++- .../addTaskCommands/AddEventCommand.java | 9 ++- .../addTaskCommands/AddTodoCommand.java | 9 ++- .../InvalidCommandException.java | 5 +- src/main/java/buddy/parser/Parser.java | 16 ++++- src/main/java/buddy/storage/Storage.java | 23 ++++++- src/main/java/buddy/tasks/Deadline.java | 8 ++- src/main/java/buddy/tasks/Event.java | 7 +++ src/main/java/buddy/tasks/Task.java | 62 +++++++++++++++++-- src/main/java/buddy/tasks/TaskList.java | 11 ++++ src/main/java/buddy/tasks/Todo.java | 10 ++- src/main/java/buddy/ui/Ui.java | 19 ++++++ 20 files changed, 229 insertions(+), 19 deletions(-) rename src/main/java/buddy/{exception => exceptions}/InvalidCommandException.java (62%) diff --git a/src/main/java/buddy/Buddy.java b/src/main/java/buddy/Buddy.java index aa42018a5..befda929f 100644 --- a/src/main/java/buddy/Buddy.java +++ b/src/main/java/buddy/Buddy.java @@ -7,9 +7,8 @@ import buddy.ui.Ui; /** - * The main of the application which executes the program. + * The part which executes the entire program */ - public class Buddy { private final Storage storage; private static TaskList taskList; @@ -18,6 +17,7 @@ public class Buddy { /** * Constructor for Buddy class + * * @param filePath The filepath of the file */ public Buddy(String filePath){ @@ -27,7 +27,7 @@ public Buddy(String filePath){ } /** - * This function runs the program till + * This function runs the program till completion (till a "bye" is inputted) */ public void run(){ ui.loadFileOrCreateFile(taskList, storage); @@ -43,6 +43,8 @@ public void run(){ } ui.sayByeToUser(); } + + public static void main(String[] args){ new Buddy("./Data").run(); diff --git a/src/main/java/buddy/commands/Command.java b/src/main/java/buddy/commands/Command.java index 108e115a9..61ea69708 100644 --- a/src/main/java/buddy/commands/Command.java +++ b/src/main/java/buddy/commands/Command.java @@ -1,6 +1,15 @@ package buddy.commands; import buddy.tasks.TaskList; +/** + * Constructor for Command class + */ public abstract class Command { - public abstract void executeCommand(TaskList taskList, String input); // executes the commands differently based on the various types of commands + /** + * Executes the commands by the user for all the different types of commands - actionCommands and addTaskCommands + * + * @param taskList List of tasks + * @param input Command inputted by the user + */ + public abstract void executeCommand(TaskList taskList, String input); } diff --git a/src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java b/src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java index 7e967f9ec..bcd584595 100644 --- a/src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java @@ -3,8 +3,15 @@ import buddy.commands.Command; import buddy.tasks.TaskList; + public class DeleteTaskCommand extends Command { + /** + * Process DeleteTaskCommand by user and deletes task from task list + * + * @param taskList List of tasks + * @param input Command inputted by user + */ @Override public void executeCommand(TaskList taskList, String input) { try{ diff --git a/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java b/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java index 9add06a0f..e723cf054 100644 --- a/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java @@ -8,6 +8,14 @@ import static java.util.stream.Collectors.toList; public class FindTaskCommand extends Command { + + /** + * Process FindTaskCommand by user and finds and outputs the matching task to keyword + * If there are no matching tasks, tells user that there are none + * + * @param taskList List of tasks + * @param input Command inputted by user + */ @Override public void executeCommand(TaskList taskList, String input) { String keyword = input.split(" ")[1].trim().toLowerCase(); diff --git a/src/main/java/buddy/commands/actionCommands/HelpCommand.java b/src/main/java/buddy/commands/actionCommands/HelpCommand.java index 72a995126..1770ac6d5 100644 --- a/src/main/java/buddy/commands/actionCommands/HelpCommand.java +++ b/src/main/java/buddy/commands/actionCommands/HelpCommand.java @@ -6,6 +6,12 @@ import buddy.tasks.TaskList; public class HelpCommand extends Command { + /** + * Process HelpCommand by user and prints help message + * + * @param taskList List of tasks + * @param input Command inputted by user + */ @Override public void executeCommand(TaskList taskList, String input) { System.out.println(Messages.DIVIDER); diff --git a/src/main/java/buddy/commands/actionCommands/ListCommand.java b/src/main/java/buddy/commands/actionCommands/ListCommand.java index bc749363f..0336ec8bb 100644 --- a/src/main/java/buddy/commands/actionCommands/ListCommand.java +++ b/src/main/java/buddy/commands/actionCommands/ListCommand.java @@ -6,6 +6,13 @@ import buddy.tasks.TaskList; public class ListCommand extends Command { + + /** + * Process ListCommand by user and prints out the list of tasks + * + * @param taskList List of tasks + * @param input Command inputted by user + */ @Override public void executeCommand(TaskList taskList, String input) { System.out.println(Messages.DIVIDER); diff --git a/src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java b/src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java index efe620d70..77963c892 100644 --- a/src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java @@ -5,6 +5,13 @@ import buddy.tasks.Task; public class MarkTaskCommand extends Command { + + /** + * Process MarkTaskCommand by user and marks task as done + * + * @param taskList List of tasks + * @param input Command inputted by user + */ @Override public void executeCommand(TaskList taskList, String input) { try{ diff --git a/src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java b/src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java index 4ad70373e..e8639b54e 100644 --- a/src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java @@ -5,6 +5,13 @@ import buddy.tasks.Task; public class UnmarkTaskCommand extends Command { + + /** + * Processes UnmarkTaskCommand by marking the task as not done + * + * @param taskList List of tasks + * @param input Command inputted by user + */ @Override public void executeCommand(TaskList taskList, String input) { try{ diff --git a/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java index 120b07140..550a4f849 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java @@ -1,6 +1,6 @@ package buddy.commands.addTaskCommands; -import buddy.exception.InvalidCommandException; +import buddy.exceptions.InvalidCommandException; import buddy.commands.Command; import java.time.LocalDate; import java.time.format.DateTimeFormatter; @@ -10,6 +10,12 @@ public class AddDeadlineCommand extends Command { + /** + * Process Deadline command by user and adds deadline + * + * @param taskList List of tasks + * @param input Command inputted by user + */ @Override public void executeCommand(TaskList taskList, String input) { try{ diff --git a/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java index 46d5a14f4..852cd60f9 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java @@ -1,12 +1,19 @@ package buddy.commands.addTaskCommands; -import buddy.exception.InvalidCommandException; +import buddy.exceptions.InvalidCommandException; import buddy.commands.Command; import buddy.tasks.TaskList; import buddy.tasks.Event; public class AddEventCommand extends Command { + + /** + * Process Event command by user and adds event + * + * @param taskList List of tasks + * @param input Command inputted by user + */ @Override public void executeCommand(TaskList taskList, String input) { try{ diff --git a/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java index abe1fdddf..9834eb211 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java @@ -1,11 +1,18 @@ package buddy.commands.addTaskCommands; -import buddy.exception.InvalidCommandException; +import buddy.exceptions.InvalidCommandException; import buddy.commands.Command; import buddy.tasks.TaskList; import buddy.tasks.Todo; public class AddTodoCommand extends Command { + + /** + * Process Todo command by user and adds todo + * + * @param taskList List of tasks + * @param input Command inputted by user + */ @Override public void executeCommand(TaskList taskList, String input) { try{ diff --git a/src/main/java/buddy/exception/InvalidCommandException.java b/src/main/java/buddy/exceptions/InvalidCommandException.java similarity index 62% rename from src/main/java/buddy/exception/InvalidCommandException.java rename to src/main/java/buddy/exceptions/InvalidCommandException.java index 58a12b513..21185ecfa 100644 --- a/src/main/java/buddy/exception/InvalidCommandException.java +++ b/src/main/java/buddy/exceptions/InvalidCommandException.java @@ -1,5 +1,8 @@ -package buddy.exception; +package buddy.exceptions; +/** + * Prints the error message when there is an invalid command inputted by the user + */ public class InvalidCommandException extends Exception{ public static void printMessage(){ System.out.println("This is an invalid command! Please check and type in again"); diff --git a/src/main/java/buddy/parser/Parser.java b/src/main/java/buddy/parser/Parser.java index 257c2ee8b..17a1f867b 100644 --- a/src/main/java/buddy/parser/Parser.java +++ b/src/main/java/buddy/parser/Parser.java @@ -11,16 +11,28 @@ import buddy.commands.addTaskCommands.AddTodoCommand; import buddy.commands.addTaskCommands.AddDeadlineCommand; import buddy.commands.addTaskCommands.AddEventCommand; -import buddy.exception.InvalidCommandException; +import buddy.exceptions.InvalidCommandException; import buddy.storage.Storage; import buddy.tasks.TaskList; public class Parser { - + /** + * Tells if the program needs to exit + * + * @param input Command typed by the user + * @return true if the command is equals to "bye" else false + */ public boolean isExit(String input) { return input.equals("bye"); } + /** + * Executes the commands inputted by the user based on what the commands are + * + * @param taskList List of tasks + * @param input Command inputted by the user + * @param storage Storage object to save the task list + */ public void executeInput(TaskList taskList, String input, Storage storage) { String[] inputSplit = input.split(" ", 2); String commandName = inputSplit[0].trim(); diff --git a/src/main/java/buddy/storage/Storage.java b/src/main/java/buddy/storage/Storage.java index 64fa9f8bd..0dc63e237 100644 --- a/src/main/java/buddy/storage/Storage.java +++ b/src/main/java/buddy/storage/Storage.java @@ -15,9 +15,19 @@ public class Storage { private final String filePath; + + /** + * Constructor for Storage class + * + * @param filePath Path to the file where it is stored + */ public Storage(String filePath){ this.filePath = filePath; } + + /** + * Creates a new directory and a new file if they don't exist + */ public void createFile(){ File directory = new File(filePath); File newFile = new File(filePath + "/BuddyTaskList.txt"); @@ -38,6 +48,12 @@ public void createFile(){ } } + /** + * Updates the file by overwriting it with the updated task list + * + * @param taskList List of tasks + * @throws IOException If there is an error with the hard disk + */ public void updateFile(TaskList taskList) throws IOException { FileWriter overwriteFile = new FileWriter(filePath + "/BuddyTaskList.txt"); for (Task task : taskList) { @@ -64,7 +80,12 @@ public void updateFile(TaskList taskList) throws IOException { } - + /** + * Loads the existing file with the task list + * + * @param taskList List of tasks + * @throws FileNotFoundException If there is no file found + */ public void loadFile(TaskList taskList) throws FileNotFoundException { File file = new File(filePath + "/BuddyTaskList.txt"); Scanner s = new Scanner(file); diff --git a/src/main/java/buddy/tasks/Deadline.java b/src/main/java/buddy/tasks/Deadline.java index 3485aa010..4f23a5523 100644 --- a/src/main/java/buddy/tasks/Deadline.java +++ b/src/main/java/buddy/tasks/Deadline.java @@ -4,6 +4,12 @@ public class Deadline extends Task { protected String by; + /** + * Constructor for Deadline class which is a type of Task + * + * @param description Description of deadline + * @param by Deadline date in YYYY-MM-DD format + */ public Deadline(String description, String by) { super(description); this.by = by; @@ -18,8 +24,6 @@ public String getType(){ return "D"; } - - @Override public String toString() { return "[D]" + super.toString() + " (Please do by: " + by + "!)"; diff --git a/src/main/java/buddy/tasks/Event.java b/src/main/java/buddy/tasks/Event.java index bcc977b33..674b58e80 100644 --- a/src/main/java/buddy/tasks/Event.java +++ b/src/main/java/buddy/tasks/Event.java @@ -5,6 +5,13 @@ public class Event extends Task { protected String from; protected String to; + /** + * Constructor for Event class which is a type of Task + * + * @param description Description of Event + * @param from Start of Event + * @param to End of Event + */ public Event(String description, String from, String to) { super(description); this.from = from; diff --git a/src/main/java/buddy/tasks/Task.java b/src/main/java/buddy/tasks/Task.java index 89f99c147..80142537b 100644 --- a/src/main/java/buddy/tasks/Task.java +++ b/src/main/java/buddy/tasks/Task.java @@ -7,48 +7,99 @@ public class Task { protected String description; protected boolean isDone; + /** + * Constructor for Task class + * + * @param description Description of task + */ public Task(String description) { this.description = description; this.isDone = false; } + /** + * Gets the description of the task + * + * @return Description of task + */ public String getTaskName(){ return this.description; } + /** + * Gets the type of the task + * + * @return String with type of task based on the Override + */ public String getType(){ return ""; } + /** + * Gets the status icon of the task (whether done or not) + * + * @return "X" if isDone is true and " " if isDone is false + */ public String getStatusIcon() { return (isDone ? "X" : " "); // mark done task with X } + /** + * Sets isDone + * + * @param isDone True if task is done and false if task is not done + */ public void setDone(boolean isDone) { this.isDone = isDone; } + /** + * Marks task as done with an "X" if task was not done previously + * Else tells user that task has already been completed + */ public void markAsDone(){ - this.isDone = true; System.out.println(Messages.DIVIDER); - System.out.println("Great work on completing this task! Marked as done! :)"); + if (!this.isDone){ + this.isDone = true; + System.out.println("Great work on completing this task! Marked as done! :)"); + } + else{ + System.out.println("This task had already been marked as done previously!"); + } System.out.println(this); System.out.println(Messages.DIVIDER); + } + /** + * Mark task with a " " if task was completed previously (Marks as not done) + * Else tells user that the task was not even completed previously + */ public void markAsUndone(){ - this.isDone = false; System.out.println(Messages.DIVIDER); - System.out.println("Come on, don't procrastinate! Marked as undone!"); + if (this.isDone){ + this.isDone = false; + System.out.println("Come on, don't procrastinate! Marked as undone!"); + } + else{ + + System.out.println("This task was previously not completed! Please do it properly!"); + } System.out.println(this); System.out.println(Messages.DIVIDER); } + /** + * @return String to be printed out when each task is printed + */ @Override public String toString() { return "[" + this.getStatusIcon() + "] " + this.description; } + /** + * Prints message to user after adding a task + */ public void printAfterAddingTask(){ if (Buddy.taskCount == 1){ System.out.println("Got it! I have added this task!: \n" + this + "\n" + "Now you have " + Buddy.taskCount + " task remaining! Almost there, buddy!"); @@ -60,6 +111,9 @@ public void printAfterAddingTask(){ } + /** + * Prints message to user after deleting a task + */ public void printAfterDeletingTask() { if (Buddy.taskCount == 0) { System.out.println( "OK I have deleted this task!: \n" + this + "\n" + "CONGRATS BUDDY ON FINISHING ALL YOUR TASKS! TIME TO RELAX WITH YOUR FRIENDS AND FAMILY! :)"); diff --git a/src/main/java/buddy/tasks/TaskList.java b/src/main/java/buddy/tasks/TaskList.java index e4fb5db05..c0965b8e1 100644 --- a/src/main/java/buddy/tasks/TaskList.java +++ b/src/main/java/buddy/tasks/TaskList.java @@ -5,6 +5,11 @@ import java.util.ArrayList; public class TaskList extends ArrayList { + /** + * Adds task to the task list + * + * @param newTask Task to add + */ public void addTask (Task newTask){ System.out.println(Messages.DIVIDER); this.add(newTask); // new task is added to taskList @@ -13,6 +18,12 @@ public void addTask (Task newTask){ System.out.println(Messages.DIVIDER); } + /** + * Deletes task from the task list + * + * @param indexOfTaskToDelete The index of the task to be deleted in the list + */ + public void deleteTask (int indexOfTaskToDelete){ System.out.println(Messages.DIVIDER); Task taskToBeDeleted = this.get(indexOfTaskToDelete); diff --git a/src/main/java/buddy/tasks/Todo.java b/src/main/java/buddy/tasks/Todo.java index 0aa250f09..fa30a1aa0 100644 --- a/src/main/java/buddy/tasks/Todo.java +++ b/src/main/java/buddy/tasks/Todo.java @@ -1,11 +1,17 @@ package buddy.tasks; public class Todo extends Task { - protected boolean isDone; + + /** + * Constructor for Todo - a type of Task + * + * @param description Description of todo + */ public Todo(String description) { - super(description); // don't need isDone as isDone is already in Task class + super(description); } + @Override public String getType(){ return "T"; diff --git a/src/main/java/buddy/ui/Ui.java b/src/main/java/buddy/ui/Ui.java index 658d48372..bb23114bf 100644 --- a/src/main/java/buddy/ui/Ui.java +++ b/src/main/java/buddy/ui/Ui.java @@ -8,20 +8,39 @@ public class Ui { + /** + * Prints a greeting to greet the user. + */ public static void greetUser(){ System.out.println(Messages.DIVIDER); System.out.println(Messages.GREETING); System.out.println(Messages.INTRODUCTION); System.out.println(Messages.DIVIDER); } + + /** + * Prints the help message + */ public static void displayHelpMessage(){ System.out.println(Messages.HELPMESSAGE); } + + /** + * Prints the message when user types "bye" (Saying bye) + */ public static void sayByeToUser(){ System.out.println(Messages.DIVIDER); System.out.println(Messages.EXITMESSAGE); System.out.println(Messages.DIVIDER); } + + /** + * Loads a file if there is an existing saved file with the list of tasks + * If there is no existing file, create a new file + * + * @param taskList The list of tasks + * @param storage Storage object that handles the data + */ public static void loadFileOrCreateFile(TaskList taskList, Storage storage){ try { storage.loadFile(taskList); From c2fc05734c28e5393a016cf207ce0a6b8a3f6efc Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 20:49:30 +0800 Subject: [PATCH 49/54] Reformatted code and added in some additional checks --- src/main/java/buddy/Buddy.java | 11 +++-- src/main/java/buddy/commands/Command.java | 3 +- .../actionCommands/DeleteTaskCommand.java | 10 ++--- .../actionCommands/FindTaskCommand.java | 11 ++--- .../commands/actionCommands/HelpCommand.java | 2 +- .../commands/actionCommands/ListCommand.java | 9 ++-- .../actionCommands/MarkTaskCommand.java | 11 ++--- .../actionCommands/UnmarkTaskCommand.java | 10 +++-- .../addTaskCommands/AddDeadlineCommand.java | 25 ++++++----- .../addTaskCommands/AddEventCommand.java | 11 +++-- .../addTaskCommands/AddTodoCommand.java | 9 ++-- .../exceptions/InvalidCommandException.java | 8 +++- src/main/java/buddy/messages/Messages.java | 41 +++++++++---------- src/main/java/buddy/parser/Parser.java | 16 +++----- src/main/java/buddy/storage/Storage.java | 14 +++---- src/main/java/buddy/tasks/Deadline.java | 6 +-- src/main/java/buddy/tasks/Event.java | 12 +++--- src/main/java/buddy/tasks/Task.java | 35 +++++++--------- src/main/java/buddy/tasks/TaskList.java | 7 ++-- src/main/java/buddy/tasks/Todo.java | 3 +- src/main/java/buddy/ui/Ui.java | 8 ++-- 21 files changed, 127 insertions(+), 135 deletions(-) diff --git a/src/main/java/buddy/Buddy.java b/src/main/java/buddy/Buddy.java index befda929f..69134fec3 100644 --- a/src/main/java/buddy/Buddy.java +++ b/src/main/java/buddy/Buddy.java @@ -1,6 +1,7 @@ package buddy; import java.util.Scanner; + import buddy.parser.Parser; import buddy.storage.Storage; import buddy.tasks.TaskList; @@ -20,7 +21,7 @@ public class Buddy { * * @param filePath The filepath of the file */ - public Buddy(String filePath){ + public Buddy(String filePath) { taskList = new TaskList(); storage = new Storage(filePath); ui = new Ui(); @@ -29,7 +30,7 @@ public Buddy(String filePath){ /** * This function runs the program till completion (till a "bye" is inputted) */ - public void run(){ + public void run() { ui.loadFileOrCreateFile(taskList, storage); ui.greetUser(); String input; @@ -37,16 +38,14 @@ public void run(){ input = in.nextLine(); Parser processAllCommands = new Parser(); - while (! processAllCommands.isExit(input)) { + while (!processAllCommands.isExit(input)) { processAllCommands.executeInput(taskList, input, storage); input = in.nextLine(); } ui.sayByeToUser(); } - - public static void main(String[] args){ + public static void main(String[] args) { new Buddy("./Data").run(); - } } diff --git a/src/main/java/buddy/commands/Command.java b/src/main/java/buddy/commands/Command.java index 61ea69708..9a8dc184a 100644 --- a/src/main/java/buddy/commands/Command.java +++ b/src/main/java/buddy/commands/Command.java @@ -1,4 +1,5 @@ package buddy.commands; + import buddy.tasks.TaskList; /** @@ -9,7 +10,7 @@ public abstract class Command { * Executes the commands by the user for all the different types of commands - actionCommands and addTaskCommands * * @param taskList List of tasks - * @param input Command inputted by the user + * @param input Command inputted by the user */ public abstract void executeCommand(TaskList taskList, String input); } diff --git a/src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java b/src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java index bcd584595..9bf74d04b 100644 --- a/src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/DeleteTaskCommand.java @@ -1,6 +1,7 @@ package buddy.commands.actionCommands; import buddy.commands.Command; +import buddy.messages.Messages; import buddy.tasks.TaskList; @@ -10,20 +11,19 @@ public class DeleteTaskCommand extends Command { * Process DeleteTaskCommand by user and deletes task from task list * * @param taskList List of tasks - * @param input Command inputted by user + * @param input Command inputted by user */ @Override public void executeCommand(TaskList taskList, String input) { - try{ + try { String[] deleteSplit = input.split(" ", 2); int taskNumberToBeDeleted = Integer.parseInt(deleteSplit[1]); int indexOfTaskInTaskList = taskNumberToBeDeleted - 1; taskList.deleteTask(indexOfTaskInTaskList); - } catch(IndexOutOfBoundsException e){ + } catch (IndexOutOfBoundsException e) { System.out.println("That is not a valid task to delete! Please check your list again and input a valid task"); + System.out.println(Messages.DIVIDER); } - - } } diff --git a/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java b/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java index e723cf054..3b350e197 100644 --- a/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java @@ -4,7 +4,9 @@ import buddy.commands.Command; import buddy.tasks.TaskList; import buddy.tasks.Task; + import java.util.ArrayList; + import static java.util.stream.Collectors.toList; public class FindTaskCommand extends Command { @@ -14,7 +16,7 @@ public class FindTaskCommand extends Command { * If there are no matching tasks, tells user that there are none * * @param taskList List of tasks - * @param input Command inputted by user + * @param input Command inputted by user */ @Override public void executeCommand(TaskList taskList, String input) { @@ -23,16 +25,15 @@ public void executeCommand(TaskList taskList, String input) { matchedTasks = (ArrayList) taskList.stream() // casts list to ArrayList .filter(t -> t.getTaskName().trim().toLowerCase().contains(keyword)).collect(toList()); System.out.println(Messages.DIVIDER); - if (!matchedTasks.isEmpty()){ + if (!matchedTasks.isEmpty()) { System.out.println("Well, here is the list of tasks matching your keyword!"); } - for (Task task : matchedTasks){ + for (Task task : matchedTasks) { System.out.println(task); } - if (matchedTasks.isEmpty()){ + if (matchedTasks.isEmpty()) { System.out.println("Oops, there are no tasks matching the keyword! Try again with another keyword"); } System.out.println(Messages.DIVIDER); - } } diff --git a/src/main/java/buddy/commands/actionCommands/HelpCommand.java b/src/main/java/buddy/commands/actionCommands/HelpCommand.java index 1770ac6d5..475b89c5b 100644 --- a/src/main/java/buddy/commands/actionCommands/HelpCommand.java +++ b/src/main/java/buddy/commands/actionCommands/HelpCommand.java @@ -10,7 +10,7 @@ public class HelpCommand extends Command { * Process HelpCommand by user and prints help message * * @param taskList List of tasks - * @param input Command inputted by user + * @param input Command inputted by user */ @Override public void executeCommand(TaskList taskList, String input) { diff --git a/src/main/java/buddy/commands/actionCommands/ListCommand.java b/src/main/java/buddy/commands/actionCommands/ListCommand.java index 0336ec8bb..3727f8fbb 100644 --- a/src/main/java/buddy/commands/actionCommands/ListCommand.java +++ b/src/main/java/buddy/commands/actionCommands/ListCommand.java @@ -11,25 +11,22 @@ public class ListCommand extends Command { * Process ListCommand by user and prints out the list of tasks * * @param taskList List of tasks - * @param input Command inputted by user + * @param input Command inputted by user */ @Override public void executeCommand(TaskList taskList, String input) { System.out.println(Messages.DIVIDER); - if (!taskList.isEmpty()){ + if (!taskList.isEmpty()) { System.out.println("Here is the list of tasks you have remaining! Come on Buddy!"); - } int index = 1; // index which shows numbers the task for (int i = 0; i < Buddy.taskCount; i++) { System.out.println(index + "." + taskList.get(i)); index++; // increment the number on the task } - if (taskList.isEmpty()){ + if (taskList.isEmpty()) { System.out.println("There is nothing in the list! Please enter a new command"); } System.out.println(Messages.DIVIDER); - - } } diff --git a/src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java b/src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java index 77963c892..fb961c824 100644 --- a/src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/MarkTaskCommand.java @@ -1,6 +1,7 @@ package buddy.commands.actionCommands; import buddy.commands.Command; +import buddy.messages.Messages; import buddy.tasks.TaskList; import buddy.tasks.Task; @@ -10,21 +11,21 @@ public class MarkTaskCommand extends Command { * Process MarkTaskCommand by user and marks task as done * * @param taskList List of tasks - * @param input Command inputted by user + * @param input Command inputted by user */ @Override public void executeCommand(TaskList taskList, String input) { - try{ + try { String[] markSplit = input.split(" ", 2); int taskNumberToBeMarked = Integer.parseInt(markSplit[1]); int indexOfTaskToBeMarked = taskNumberToBeMarked - 1; Task taskToBeMarked = taskList.get(indexOfTaskToBeMarked); taskToBeMarked.markAsDone(); - - }catch(IndexOutOfBoundsException e){ + } catch (IndexOutOfBoundsException e) { + System.out.println(Messages.DIVIDER); System.out.println("That is not a valid task to mark! Please check your list again and input a valid task"); + System.out.println(Messages.DIVIDER); } - } } diff --git a/src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java b/src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java index e8639b54e..e186978f7 100644 --- a/src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/UnmarkTaskCommand.java @@ -1,6 +1,7 @@ package buddy.commands.actionCommands; import buddy.commands.Command; +import buddy.messages.Messages; import buddy.tasks.TaskList; import buddy.tasks.Task; @@ -10,20 +11,21 @@ public class UnmarkTaskCommand extends Command { * Processes UnmarkTaskCommand by marking the task as not done * * @param taskList List of tasks - * @param input Command inputted by user + * @param input Command inputted by user */ @Override public void executeCommand(TaskList taskList, String input) { - try{ + try { String[] unmarkSplit = input.split(" ", 2); int taskNumberToBeUnmarked = Integer.parseInt(unmarkSplit[1]); int indexOfTaskToBeUnmarked = taskNumberToBeUnmarked - 1; Task taskToBeUnmarked = taskList.get(indexOfTaskToBeUnmarked); taskToBeUnmarked.markAsUndone(); - - }catch(IndexOutOfBoundsException e){ + } catch (IndexOutOfBoundsException e) { + System.out.println(Messages.DIVIDER); System.out.println("That is not a valid task to unmark! Please check your list again and input a valid task"); + System.out.println(Messages.DIVIDER); } } diff --git a/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java index 550a4f849..09467d93a 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java @@ -2,8 +2,12 @@ import buddy.exceptions.InvalidCommandException; import buddy.commands.Command; + import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +import buddy.messages.Messages; import buddy.tasks.TaskList; import buddy.tasks.Deadline; @@ -14,31 +18,32 @@ public class AddDeadlineCommand extends Command { * Process Deadline command by user and adds deadline * * @param taskList List of tasks - * @param input Command inputted by user + * @param input Command inputted by user */ @Override public void executeCommand(TaskList taskList, String input) { - try{ + try { String[] deadlineSplit = input.split("/by", 2); String deadlineBy = deadlineSplit[1].trim(); LocalDate toFormat = LocalDate.parse(deadlineBy); - if (toFormat.isBefore(LocalDate.now())){ + if (toFormat.isBefore(LocalDate.now())) { // if deadline date is before today's date, invalid task throw new InvalidCommandException(); } - String deadlineByFormatted = toFormat.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + String deadlineByFormatted = toFormat.format(DateTimeFormatter.ofPattern("MMM d yyyy")); // Deadline must be in this format String[] deadlineAndName = deadlineSplit[0].split(" ", 2); String deadlineName = deadlineAndName[1].trim(); - if (deadlineName.equals("")){ - throw new InvalidCommandException(); + if (deadlineName.equals("")) { + throw new InvalidCommandException(); // if no deadline description inputted, invalid task } Deadline deadlineBeingAdded = new Deadline(deadlineName, deadlineByFormatted); taskList.addTask(deadlineBeingAdded); - - }catch(InvalidCommandException e){ + } catch (InvalidCommandException e) { InvalidCommandException.printMessage(); + } catch (DateTimeParseException e) { + System.out.println(Messages.DIVIDER); + System.out.println("This is the wrong format of deadline date! Please input deadline where is in YYYY-MM-DD!"); + System.out.println(Messages.DIVIDER); } - - } } \ No newline at end of file diff --git a/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java index 852cd60f9..eec24e10c 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java @@ -12,26 +12,25 @@ public class AddEventCommand extends Command { * Process Event command by user and adds event * * @param taskList List of tasks - * @param input Command inputted by user + * @param input Command inputted by user */ @Override public void executeCommand(TaskList taskList, String input) { - try{ + try { String[] eventSplit = input.split("/", 3); - String[] eventAndName= eventSplit[0].split(" ", '2'); + String[] eventAndName = eventSplit[0].split(" ", '2'); String eventName = eventAndName[1]; String[] fromAndStart = eventSplit[1].split(" ", '2'); String start = fromAndStart[1].trim(); String[] toAndEnd = eventSplit[2].split(" ", '2'); String end = toAndEnd[1].trim(); - if (eventName.equals("") || start.equals("") || end.equals("")){ + if (eventName.equals("") || start.equals("") || end.equals("")) { throw new InvalidCommandException(); } Event eventBeingAdded = new Event(eventName, start, end); taskList.addTask(eventBeingAdded); - - }catch(InvalidCommandException e){ + } catch (InvalidCommandException e) { InvalidCommandException.printMessage(); } diff --git a/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java index 9834eb211..733756f47 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java @@ -11,21 +11,20 @@ public class AddTodoCommand extends Command { * Process Todo command by user and adds todo * * @param taskList List of tasks - * @param input Command inputted by user + * @param input Command inputted by user */ @Override public void executeCommand(TaskList taskList, String input) { - try{ + try { String[] todoSplit = input.split(" ", 2); - if (todoSplit[1].equals("")){ + if (todoSplit[1].equals("")) { throw new InvalidCommandException(); } Todo todoBeingAdded = new Todo(todoSplit[1]); taskList.addTask(todoBeingAdded); - }catch (InvalidCommandException e){ + } catch (InvalidCommandException e) { InvalidCommandException.printMessage(); } - } } diff --git a/src/main/java/buddy/exceptions/InvalidCommandException.java b/src/main/java/buddy/exceptions/InvalidCommandException.java index 21185ecfa..19651a826 100644 --- a/src/main/java/buddy/exceptions/InvalidCommandException.java +++ b/src/main/java/buddy/exceptions/InvalidCommandException.java @@ -1,11 +1,15 @@ package buddy.exceptions; +import buddy.messages.Messages; + /** * Prints the error message when there is an invalid command inputted by the user */ -public class InvalidCommandException extends Exception{ - public static void printMessage(){ +public class InvalidCommandException extends Exception { + public static void printMessage() { + System.out.println(Messages.DIVIDER); System.out.println("This is an invalid command! Please check and type in again"); + System.out.println(Messages.DIVIDER); } } \ No newline at end of file diff --git a/src/main/java/buddy/messages/Messages.java b/src/main/java/buddy/messages/Messages.java index 5153ac459..a08dedb7e 100644 --- a/src/main/java/buddy/messages/Messages.java +++ b/src/main/java/buddy/messages/Messages.java @@ -1,31 +1,30 @@ package buddy.messages; public class Messages { - public static final String DIVIDER = "________________________________________________________________________________"; + public static final String DIVIDER = "______________________________________________________________________________________________________________________________________________________________________________________________________________"; public static final String GREETING = "Hello there! I'm Buddy\n" + "How may I assist you?"; public static final String INTRODUCTION = "Here are the possible commands: todo, deadline, event, list, mark, unmark, find, bye\n" + "Type if you are unsure of what these commands do!"; public static final String EXITMESSAGE = "Hope I was of help to you! Have a great day and see you again, Buddy :)"; public static final String HELPMESSAGE = "These are the various commands and their functions. Please type in the FORMAT that is stated below\n" + - "There are 3 add task commands which add 3 kinds of buddy.tasks: todo, deadline and event\n" + - "todo: Adds a todo to your task list\n" + - "FORMAT: todo \n" + - "deadline: Adds a deadline to your task list\n" + - - "FORMAT: deadline /by (where YYYY is year, MM is month and DD is day)\n" + - "event: Adds an event to your task list\n" + - "FORMAT: event /from /to \n" + - "There are 5 other action commands: list, mark, unmark, find and bye\n" + - "list: lists all the buddy.tasks that you have remaining\n" + - "FORMAT: list\n" + - "mark: marks a task as done with an X\n" + - "FORMAT: mark \n" + - "unmark: marks a task as not done\n" + - "FORMAT: unmark \n" + - "find: finds a task which contains the keyword that you typed\n" + - "FORMAT: find \n" + - "bye: exits the application\n" + - "FORMAT: bye\n" + - "Hope that this was useful!"; + "There are 3 add task commands which add 3 kinds of buddy.tasks: todo, deadline and event\n" + + "todo: Adds a todo to your task list\n" + + "FORMAT: todo \n" + + "deadline: Adds a deadline to your task list\n" + + "FORMAT: deadline /by (where YYYY is year, MM is month and DD is day)\n" + + "event: Adds an event to your task list\n" + + "FORMAT: event /from /to \n" + + "There are 5 other action commands: list, mark, unmark, find and bye\n" + + "list: lists all the buddy.tasks that you have remaining\n" + + "FORMAT: list\n" + + "mark: marks a task as done with an X\n" + + "FORMAT: mark \n" + + "unmark: marks a task as not done\n" + + "FORMAT: unmark \n" + + "find: finds a task which contains the keyword that you typed\n" + + "FORMAT: find \n" + + "bye: exits the application\n" + + "FORMAT: bye\n" + + "Hope that this was useful!"; } diff --git a/src/main/java/buddy/parser/Parser.java b/src/main/java/buddy/parser/Parser.java index 17a1f867b..1aa599635 100644 --- a/src/main/java/buddy/parser/Parser.java +++ b/src/main/java/buddy/parser/Parser.java @@ -1,6 +1,7 @@ package buddy.parser; import java.io.IOException; + import buddy.commands.Command; import buddy.commands.actionCommands.DeleteTaskCommand; import buddy.commands.actionCommands.HelpCommand; @@ -30,8 +31,8 @@ public boolean isExit(String input) { * Executes the commands inputted by the user based on what the commands are * * @param taskList List of tasks - * @param input Command inputted by the user - * @param storage Storage object to save the task list + * @param input Command inputted by the user + * @param storage Storage object to save the task list */ public void executeInput(TaskList taskList, String input, Storage storage) { String[] inputSplit = input.split(" ", 2); @@ -87,21 +88,14 @@ public void executeInput(TaskList taskList, String input, Storage storage) { default: throw new InvalidCommandException(); } - } catch (InvalidCommandException e) { InvalidCommandException.printMessage(); } - try{ + try { storage.updateFile(taskList); - }catch (IOException e){ + } catch (IOException e) { System.out.println("IO Error"); } - - - - - } - } diff --git a/src/main/java/buddy/storage/Storage.java b/src/main/java/buddy/storage/Storage.java index 0dc63e237..e0dde3655 100644 --- a/src/main/java/buddy/storage/Storage.java +++ b/src/main/java/buddy/storage/Storage.java @@ -2,11 +2,13 @@ import buddy.Buddy; import buddy.tasks.TaskList; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; + import buddy.tasks.Task; import buddy.tasks.Todo; import buddy.tasks.Deadline; @@ -21,21 +23,21 @@ public class Storage { * * @param filePath Path to the file where it is stored */ - public Storage(String filePath){ + public Storage(String filePath) { this.filePath = filePath; } /** * Creates a new directory and a new file if they don't exist */ - public void createFile(){ + public void createFile() { File directory = new File(filePath); File newFile = new File(filePath + "/BuddyTaskList.txt"); try { - if (directory.mkdirs()){ + if (directory.mkdirs()) { System.out.println("Directory has been created :)"); - } + } if (newFile.createNewFile()) { System.out.println("File has been created :)"); @@ -77,7 +79,6 @@ public void updateFile(TaskList taskList) throws IOException { } } overwriteFile.close(); - } /** @@ -131,8 +132,5 @@ public void loadFile(TaskList taskList) throws FileNotFoundException { } } - - } - } diff --git a/src/main/java/buddy/tasks/Deadline.java b/src/main/java/buddy/tasks/Deadline.java index 4f23a5523..0b125ccc9 100644 --- a/src/main/java/buddy/tasks/Deadline.java +++ b/src/main/java/buddy/tasks/Deadline.java @@ -8,19 +8,19 @@ public class Deadline extends Task { * Constructor for Deadline class which is a type of Task * * @param description Description of deadline - * @param by Deadline date in YYYY-MM-DD format + * @param by Deadline date in YYYY-MM-DD format */ public Deadline(String description, String by) { super(description); this.by = by; } - public String getDeadline(){ + public String getDeadline() { return by; } @Override - public String getType(){ + public String getType() { return "D"; } diff --git a/src/main/java/buddy/tasks/Event.java b/src/main/java/buddy/tasks/Event.java index 674b58e80..fba22cff4 100644 --- a/src/main/java/buddy/tasks/Event.java +++ b/src/main/java/buddy/tasks/Event.java @@ -9,8 +9,8 @@ public class Event extends Task { * Constructor for Event class which is a type of Task * * @param description Description of Event - * @param from Start of Event - * @param to End of Event + * @param from Start of Event + * @param to End of Event */ public Event(String description, String from, String to) { super(description); @@ -18,17 +18,19 @@ public Event(String description, String from, String to) { this.to = to; } - public String getStart(){ + public String getStart() { return this.from; } - public String getEnd(){ + + public String getEnd() { return this.to; } @Override - public String getType(){ + public String getType() { return "E"; } + @Override public String toString() { return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")"; diff --git a/src/main/java/buddy/tasks/Task.java b/src/main/java/buddy/tasks/Task.java index 80142537b..772d0e0fd 100644 --- a/src/main/java/buddy/tasks/Task.java +++ b/src/main/java/buddy/tasks/Task.java @@ -22,7 +22,7 @@ public Task(String description) { * * @return Description of task */ - public String getTaskName(){ + public String getTaskName() { return this.description; } @@ -31,7 +31,7 @@ public String getTaskName(){ * * @return String with type of task based on the Override */ - public String getType(){ + public String getType() { return ""; } @@ -57,13 +57,12 @@ public void setDone(boolean isDone) { * Marks task as done with an "X" if task was not done previously * Else tells user that task has already been completed */ - public void markAsDone(){ + public void markAsDone() { System.out.println(Messages.DIVIDER); - if (!this.isDone){ + if (!this.isDone) { this.isDone = true; System.out.println("Great work on completing this task! Marked as done! :)"); - } - else{ + } else { System.out.println("This task had already been marked as done previously!"); } System.out.println(this); @@ -75,15 +74,14 @@ public void markAsDone(){ * Mark task with a " " if task was completed previously (Marks as not done) * Else tells user that the task was not even completed previously */ - public void markAsUndone(){ + public void markAsUndone() { System.out.println(Messages.DIVIDER); - if (this.isDone){ + if (this.isDone) { this.isDone = false; System.out.println("Come on, don't procrastinate! Marked as undone!"); - } - else{ + } else { - System.out.println("This task was previously not completed! Please do it properly!"); + System.out.println("This task was previously not completed already! Please do it properly!"); } System.out.println(this); System.out.println(Messages.DIVIDER); @@ -100,15 +98,12 @@ public String toString() { /** * Prints message to user after adding a task */ - public void printAfterAddingTask(){ - if (Buddy.taskCount == 1){ + public void printAfterAddingTask() { + if (Buddy.taskCount == 1) { System.out.println("Got it! I have added this task!: \n" + this + "\n" + "Now you have " + Buddy.taskCount + " task remaining! Almost there, buddy!"); - } - else{ + } else { System.out.println("Got it! I have added this task! \n" + this + "\n" + "Now you have " + Buddy.taskCount + " tasks remaining! Let's finish them faster and relax!"); - } - } /** @@ -116,13 +111,11 @@ public void printAfterAddingTask(){ */ public void printAfterDeletingTask() { if (Buddy.taskCount == 0) { - System.out.println( "OK I have deleted this task!: \n" + this + "\n" + "CONGRATS BUDDY ON FINISHING ALL YOUR TASKS! TIME TO RELAX WITH YOUR FRIENDS AND FAMILY! :)"); + System.out.println("OK I have deleted this task!: \n" + this + "\n" + "CONGRATS BUDDY ON FINISHING ALL YOUR TASKS! TIME TO RELAX WITH YOUR FRIENDS AND FAMILY! :)"); } else if (Buddy.taskCount == 1) { System.out.println("YAY ONE LESS TO GO! I have deleted this task!: \n" + this + "\n" + "Now you have JUST " + Buddy.taskCount + " task remaining! CHOP CHOP FINISH IT"); - } else{ + } else { System.out.println("YAY ONE LESS TO GO! I have deleted this task!: \n" + this + "\n" + "Now you have " + Buddy.taskCount + " tasks remaining! Type list to see remaining tasks"); - } } - } diff --git a/src/main/java/buddy/tasks/TaskList.java b/src/main/java/buddy/tasks/TaskList.java index c0965b8e1..0412630a7 100644 --- a/src/main/java/buddy/tasks/TaskList.java +++ b/src/main/java/buddy/tasks/TaskList.java @@ -2,6 +2,7 @@ import buddy.Buddy; import buddy.messages.Messages; + import java.util.ArrayList; public class TaskList extends ArrayList { @@ -10,7 +11,7 @@ public class TaskList extends ArrayList { * * @param newTask Task to add */ - public void addTask (Task newTask){ + public void addTask(Task newTask) { System.out.println(Messages.DIVIDER); this.add(newTask); // new task is added to taskList Buddy.taskCount++; // increments number of buddy.tasks @@ -23,14 +24,12 @@ public void addTask (Task newTask){ * * @param indexOfTaskToDelete The index of the task to be deleted in the list */ - - public void deleteTask (int indexOfTaskToDelete){ + public void deleteTask(int indexOfTaskToDelete) { System.out.println(Messages.DIVIDER); Task taskToBeDeleted = this.get(indexOfTaskToDelete); Buddy.taskCount--; // decrements number of buddy.tasks taskToBeDeleted.printAfterDeletingTask(); this.remove(indexOfTaskToDelete); // delete task from taskList System.out.println(Messages.DIVIDER); - } } diff --git a/src/main/java/buddy/tasks/Todo.java b/src/main/java/buddy/tasks/Todo.java index fa30a1aa0..96944db62 100644 --- a/src/main/java/buddy/tasks/Todo.java +++ b/src/main/java/buddy/tasks/Todo.java @@ -11,9 +11,8 @@ public Todo(String description) { super(description); } - @Override - public String getType(){ + public String getType() { return "T"; } diff --git a/src/main/java/buddy/ui/Ui.java b/src/main/java/buddy/ui/Ui.java index bb23114bf..29b1b8a29 100644 --- a/src/main/java/buddy/ui/Ui.java +++ b/src/main/java/buddy/ui/Ui.java @@ -11,7 +11,7 @@ public class Ui { /** * Prints a greeting to greet the user. */ - public static void greetUser(){ + public static void greetUser() { System.out.println(Messages.DIVIDER); System.out.println(Messages.GREETING); System.out.println(Messages.INTRODUCTION); @@ -21,14 +21,14 @@ public static void greetUser(){ /** * Prints the help message */ - public static void displayHelpMessage(){ + public static void displayHelpMessage() { System.out.println(Messages.HELPMESSAGE); } /** * Prints the message when user types "bye" (Saying bye) */ - public static void sayByeToUser(){ + public static void sayByeToUser() { System.out.println(Messages.DIVIDER); System.out.println(Messages.EXITMESSAGE); System.out.println(Messages.DIVIDER); @@ -41,7 +41,7 @@ public static void sayByeToUser(){ * @param taskList The list of tasks * @param storage Storage object that handles the data */ - public static void loadFileOrCreateFile(TaskList taskList, Storage storage){ + public static void loadFileOrCreateFile(TaskList taskList, Storage storage) { try { storage.loadFile(taskList); From 9aff198f41622d07ea983bcd0fd742a32cd595ea Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 22:53:53 +0800 Subject: [PATCH 50/54] Fixed many bugs --- docs/README.md | 16 ++++++++++++---- src/main/java/META-INF/MANIFEST.MF | 2 +- src/main/java/buddy/commands/Command.java | 3 ++- .../commands/actionCommands/FindTaskCommand.java | 6 +++++- .../addTaskCommands/AddDeadlineCommand.java | 3 +++ .../addTaskCommands/AddEventCommand.java | 3 +++ .../commands/addTaskCommands/AddTodoCommand.java | 3 +++ src/main/java/buddy/messages/Messages.java | 6 +++--- 8 files changed, 32 insertions(+), 10 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..e4295f89c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,14 +1,22 @@ # User Guide +Buddy is a very helpful tool in helping you manage your daily tasks +and helping you be more organised. It also helps you improve your day to day productivity! +Get immersed in this cli-optimised application! + ## Features -### Feature-ABC +### Add tasks to your task list +Add various types of tasks - todo, deadline and event. -Description of the feature. +### Delete tasks from your task list +Delete tasks from the list. -### Feature-XYZ +### Keep track of the progress of your tasks +Mark/Unmark tasks from the list to keep track of what you have completed. -Description of the feature. +### Find tasks in your task list +Find tasks that match a keyword ## Usage diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF index 90913dd96..c6d2c7caa 100644 --- a/src/main/java/META-INF/MANIFEST.MF +++ b/src/main/java/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ Manifest-Version: 1.0 -Main-Class: Buddy +Main-Class: buddy.Buddy diff --git a/src/main/java/buddy/commands/Command.java b/src/main/java/buddy/commands/Command.java index 9a8dc184a..7419249e4 100644 --- a/src/main/java/buddy/commands/Command.java +++ b/src/main/java/buddy/commands/Command.java @@ -1,5 +1,6 @@ package buddy.commands; +import buddy.exceptions.InvalidCommandException; import buddy.tasks.TaskList; /** @@ -12,5 +13,5 @@ public abstract class Command { * @param taskList List of tasks * @param input Command inputted by the user */ - public abstract void executeCommand(TaskList taskList, String input); + public abstract void executeCommand(TaskList taskList, String input) throws InvalidCommandException; } diff --git a/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java b/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java index 3b350e197..f33201056 100644 --- a/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java +++ b/src/main/java/buddy/commands/actionCommands/FindTaskCommand.java @@ -1,5 +1,6 @@ package buddy.commands.actionCommands; +import buddy.exceptions.InvalidCommandException; import buddy.messages.Messages; import buddy.commands.Command; import buddy.tasks.TaskList; @@ -19,7 +20,10 @@ public class FindTaskCommand extends Command { * @param input Command inputted by user */ @Override - public void executeCommand(TaskList taskList, String input) { + public void executeCommand(TaskList taskList, String input) throws InvalidCommandException { + if (input.equals("find")){ + throw new InvalidCommandException(); + } String keyword = input.split(" ")[1].trim().toLowerCase(); ArrayList matchedTasks; matchedTasks = (ArrayList) taskList.stream() // casts list to ArrayList diff --git a/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java index 09467d93a..058fa32f5 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java @@ -23,6 +23,9 @@ public class AddDeadlineCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { try { + if (input.equals("deadline")){ + throw new InvalidCommandException(); + } String[] deadlineSplit = input.split("/by", 2); String deadlineBy = deadlineSplit[1].trim(); LocalDate toFormat = LocalDate.parse(deadlineBy); diff --git a/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java index eec24e10c..2928800b8 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java @@ -17,6 +17,9 @@ public class AddEventCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { try { + if (input.equals("event")){ + throw new InvalidCommandException(); + } String[] eventSplit = input.split("/", 3); String[] eventAndName = eventSplit[0].split(" ", '2'); String eventName = eventAndName[1]; diff --git a/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java index 733756f47..c0fd18352 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java @@ -16,6 +16,9 @@ public class AddTodoCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { try { + if (input.equals("todo")){ + throw new InvalidCommandException(); + } String[] todoSplit = input.split(" ", 2); if (todoSplit[1].equals("")) { throw new InvalidCommandException(); diff --git a/src/main/java/buddy/messages/Messages.java b/src/main/java/buddy/messages/Messages.java index a08dedb7e..fe72a2c5a 100644 --- a/src/main/java/buddy/messages/Messages.java +++ b/src/main/java/buddy/messages/Messages.java @@ -1,14 +1,14 @@ package buddy.messages; public class Messages { - public static final String DIVIDER = "______________________________________________________________________________________________________________________________________________________________________________________________________________"; + public static final String DIVIDER = "___________________________________________________________________________________________________________________________________"; public static final String GREETING = "Hello there! I'm Buddy\n" + "How may I assist you?"; public static final String INTRODUCTION = "Here are the possible commands: todo, deadline, event, list, mark, unmark, find, bye\n" + "Type if you are unsure of what these commands do!"; public static final String EXITMESSAGE = "Hope I was of help to you! Have a great day and see you again, Buddy :)"; public static final String HELPMESSAGE = "These are the various commands and their functions. Please type in the FORMAT that is stated below\n" + - "There are 3 add task commands which add 3 kinds of buddy.tasks: todo, deadline and event\n" + + "There are 3 add task commands which add 3 kinds of tasks: todo, deadline and event\n" + "todo: Adds a todo to your task list\n" + "FORMAT: todo \n" + "deadline: Adds a deadline to your task list\n" + @@ -16,7 +16,7 @@ public class Messages { "event: Adds an event to your task list\n" + "FORMAT: event /from /to \n" + "There are 5 other action commands: list, mark, unmark, find and bye\n" + - "list: lists all the buddy.tasks that you have remaining\n" + + "list: lists all the tasks that you have remaining\n" + "FORMAT: list\n" + "mark: marks a task as done with an X\n" + "FORMAT: mark \n" + From 15e388b009ad0fb258eb09db3dc41b319d6e2952 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 23:23:16 +0800 Subject: [PATCH 51/54] Added User Guide --- docs/README.md | 85 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 9 deletions(-) diff --git a/docs/README.md b/docs/README.md index e4295f89c..01aa113bd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -20,18 +20,85 @@ Find tasks that match a keyword ## Usage -### `Keyword` - Describe action +### `todo` - Adds a Todo task -Describe the action and its outcome. +Format: `todo ` -Example of usage: +- Adds a todo with `` +- `` should not be empty -`keyword (optional arguments)` +Examples of usage: +- `todo cs2113 project` +- `todo cs2102 assignment` -Expected outcome: +### `deadline` - Adds a Deadline task +Format: `deadline /by ` -Description of the outcome. +- Adds a task with a `` to be completed by `` +- Deadline date should be in `` format +- Deadline date cannot be before today's date +- Deadline date should not be empty -``` -expected output -``` +Examples of usage: +- `deadline cs2113 ip /by 2023-03-03` +- `deadline cs1010 assignment /by 2024-04-04` + +### `event` - Adds a Event task +Format: `event /from /to ` + +- Adds a task with a `` with a start `` to end `` +- `` should not be empty +- `` and `` should not be empty + +Examples of usage: +- `event cs2113 exam /from 4pm /to 6pm` +- `event NUS Open House /from 24 Dec 2023 6am /to 6pm` + +### `mark` - Marks a task as done +Format: `mark ` + +- Marks a task as done +- `` should be within the task list + +Examples of usage: +- `mark 2` +- `mark 1` + +### `unmark` - Marks a task as not done +Format: `unmark ` + +- Marks a task as not done +- `` should be within the task list + +Examples of usage: +- `unmark 2` +- `unmark 4` + +### `delete` - Deletes a task from the task list +Format: `delete ` + +- Deletes a task +- `` should be within the task list + +Examples of usage: +- `delete 2` +- `delete 1` + +### `find` - Finds a task by keyword +Format: `find ` + +- Finds matching tasks +- `` should be one word + +Examples of usage: +- `find cs2113` +- `find todo` + +### `bye` - Exits the program +Format: `bye` + +- Exits the program. + +### HOW DO I SAVE MY TASK LIST? + +- The program auto saves your task list and loads it when you run the program! \ No newline at end of file From cb8a6f0e6eed3f419a539453f692b830e88625c3 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 23:38:42 +0800 Subject: [PATCH 52/54] FINAL CHANGES FINALISED BUDDY YAY --- Data/BuddyTaskList.txt | 0 .../buddy/commands/addTaskCommands/AddDeadlineCommand.java | 5 +++-- .../java/buddy/commands/addTaskCommands/AddEventCommand.java | 3 ++- .../java/buddy/commands/addTaskCommands/AddTodoCommand.java | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 Data/BuddyTaskList.txt diff --git a/Data/BuddyTaskList.txt b/Data/BuddyTaskList.txt new file mode 100644 index 000000000..e69de29bb diff --git a/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java index 058fa32f5..f4c9208f7 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddDeadlineCommand.java @@ -16,6 +16,7 @@ public class AddDeadlineCommand extends Command { /** * Process Deadline command by user and adds deadline + * Throws exception if command is in wrong format * * @param taskList List of tasks * @param input Command inputted by user @@ -23,7 +24,7 @@ public class AddDeadlineCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { try { - if (input.equals("deadline")){ + if (!input.contains("/")){ throw new InvalidCommandException(); } String[] deadlineSplit = input.split("/by", 2); @@ -35,7 +36,7 @@ public void executeCommand(TaskList taskList, String input) { String deadlineByFormatted = toFormat.format(DateTimeFormatter.ofPattern("MMM d yyyy")); // Deadline must be in this format String[] deadlineAndName = deadlineSplit[0].split(" ", 2); String deadlineName = deadlineAndName[1].trim(); - if (deadlineName.equals("")) { + if (deadlineName.equals("") || deadlineName.equals(" ")) { throw new InvalidCommandException(); // if no deadline description inputted, invalid task } Deadline deadlineBeingAdded = new Deadline(deadlineName, deadlineByFormatted); diff --git a/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java index 2928800b8..04a4d7be4 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddEventCommand.java @@ -10,6 +10,7 @@ public class AddEventCommand extends Command { /** * Process Event command by user and adds event + * Throws exception if command is in wrong format * * @param taskList List of tasks * @param input Command inputted by user @@ -17,7 +18,7 @@ public class AddEventCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { try { - if (input.equals("event")){ + if ( !(input.contains("/from") && input.contains("/to")) ){ throw new InvalidCommandException(); } String[] eventSplit = input.split("/", 3); diff --git a/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java b/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java index c0fd18352..a904e09ea 100644 --- a/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java +++ b/src/main/java/buddy/commands/addTaskCommands/AddTodoCommand.java @@ -9,6 +9,7 @@ public class AddTodoCommand extends Command { /** * Process Todo command by user and adds todo + * Throws exception if command is in wrong format * * @param taskList List of tasks * @param input Command inputted by user @@ -16,7 +17,7 @@ public class AddTodoCommand extends Command { @Override public void executeCommand(TaskList taskList, String input) { try { - if (input.equals("todo")){ + if (!input.contains(" ")){ throw new InvalidCommandException(); } String[] todoSplit = input.split(" ", 2); From 0a0118ea7285121a8b123f4622339cf4fdb694ed Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 23:42:31 +0800 Subject: [PATCH 53/54] slight change --- Data/BuddyTaskList.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Data/BuddyTaskList.txt diff --git a/Data/BuddyTaskList.txt b/Data/BuddyTaskList.txt deleted file mode 100644 index e69de29bb..000000000 From 57d9fcb50791b19f55859decd55c93c9b7df92b2 Mon Sep 17 00:00:00 2001 From: SaiChaitanya13 Date: Fri, 3 Mar 2023 23:50:17 +0800 Subject: [PATCH 54/54] small change for merge --- src/main/java/buddy/Buddy.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/buddy/Buddy.java b/src/main/java/buddy/Buddy.java index 69134fec3..cab52f7fd 100644 --- a/src/main/java/buddy/Buddy.java +++ b/src/main/java/buddy/Buddy.java @@ -44,6 +44,7 @@ public void run() { } ui.sayByeToUser(); } + public static void main(String[] args) { new Buddy("./Data").run();