From bee5ee2b7a8a0a2d45eb04483817910afb86cd3c Mon Sep 17 00:00:00 2001 From: NoorSarrah <77370767+NoorSarrah@users.noreply.github.com> Date: Wed, 27 Jan 2021 21:03:40 +0800 Subject: [PATCH 01/21] Level-1 --- src/main/java/Duke.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..e490da2eb 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,3 +1,4 @@ +import java.util.Scanner; public class Duke { public static void main(String[] args) { String logo = " ____ _ \n" @@ -6,5 +7,19 @@ public static void main(String[] args) { + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); + Scanner myObj = new Scanner(System.in); + System.out.println("Hello! I'm Duke"); + System.out.println("What can I do for you?\n"); + + String command = myObj.nextLine(); + + + while(!command.equals("bye")) { + System.out.println(command+"\n"); + command = myObj.nextLine(); + + } + System.out.println("Bye. Hope to see you again soon!"); + } } From 6456e443f6b5f600c8a85991bbd8e101542854e8 Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Fri, 29 Jan 2021 20:11:40 +0800 Subject: [PATCH 02/21] Level-2 --- src/main/java/Duke.java | 42 +++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e490da2eb..27c571a18 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -6,20 +6,46 @@ public static void main(String[] args) { + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + String dash = "-"; Scanner myObj = new Scanner(System.in); + + // print welcome message + System.out.println("Hello from\n" + logo); + System.out.println(dash.repeat(50)); System.out.println("Hello! I'm Duke"); - System.out.println("What can I do for you?\n"); + System.out.println("What can I do for you?"); + System.out.println(dash.repeat(50)); + // scan input String command = myObj.nextLine(); - - while(!command.equals("bye")) { - System.out.println(command+"\n"); + String[] tasks = new String[100]; + int count = 1; + while (!command.equals("bye") && !command.equals("list")) { + // add task into array + tasks[count] = command; + count++; + // echo task + System.out.println(dash.repeat(50)); + System.out.println("added: " + command); + System.out.println(dash.repeat(50)); command = myObj.nextLine(); - } - System.out.println("Bye. Hope to see you again soon!"); - + // print list when command=list + if (command.equals("list")) { + for(int i=1; i Date: Fri, 29 Jan 2021 20:14:29 +0800 Subject: [PATCH 03/21] Level-2 --- src/main/java/Duke.java | 42 +++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e490da2eb..27c571a18 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -6,20 +6,46 @@ public static void main(String[] args) { + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + String dash = "-"; Scanner myObj = new Scanner(System.in); + + // print welcome message + System.out.println("Hello from\n" + logo); + System.out.println(dash.repeat(50)); System.out.println("Hello! I'm Duke"); - System.out.println("What can I do for you?\n"); + System.out.println("What can I do for you?"); + System.out.println(dash.repeat(50)); + // scan input String command = myObj.nextLine(); - - while(!command.equals("bye")) { - System.out.println(command+"\n"); + String[] tasks = new String[100]; + int count = 1; + while (!command.equals("bye") && !command.equals("list")) { + // add task into array + tasks[count] = command; + count++; + // echo task + System.out.println(dash.repeat(50)); + System.out.println("added: " + command); + System.out.println(dash.repeat(50)); command = myObj.nextLine(); - } - System.out.println("Bye. Hope to see you again soon!"); - + // print list when command=list + if (command.equals("list")) { + for(int i=1; i Date: Mon, 1 Feb 2021 11:10:27 +0800 Subject: [PATCH 04/21] Update code --- src/main/java/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 27c571a18..1e2b64e8a 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -5,7 +5,7 @@ public static void main(String[] args) { + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; + + "|____/ \\__,_|_|\\_\\_______|\n"; String dash = "-"; Scanner myObj = new Scanner(System.in); From 0e12fff1b6f9cdc592f69562039ad0cfac27e342 Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Mon, 1 Feb 2021 11:44:00 +0800 Subject: [PATCH 05/21] test --- src/main/java/Task.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..f5339d154 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,15 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getStatusIcon() { + return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols + } + + if(description.equals("")) +} From 671e8f96eff47b5887a82d443ce444de34415038 Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Mon, 1 Feb 2021 11:47:51 +0800 Subject: [PATCH 06/21] test_1 --- src/main/java/Duke.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 7e9deb358..dbd0e25c1 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -46,6 +46,7 @@ public static void main(String[] args) { // exit program when input=bye if(command.equals("bye")) { System.out.println(dash.repeat(50)); + System.out.println(dash.repeat(49)); System.out.println("Bye. Hope to see you again soon!"); System.out.println(dash.repeat(50)); } From 1a893f8a44b43d6eb1c1a34e97d6c036b1cd6e80 Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Tue, 2 Feb 2021 01:18:03 +0800 Subject: [PATCH 07/21] Level-3 --- src/main/java/Duke.java | 42 +++++++++++--------------- src/main/java/List.java | 67 +++++++++++++++++++++++++++++++++++++++++ src/main/java/Task.java | 6 ++-- 3 files changed, 89 insertions(+), 26 deletions(-) create mode 100644 src/main/java/List.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index dbd0e25c1..0006a3674 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,7 +1,8 @@ import java.util.Scanner; public class Duke { public static void main(String[] args) { - + List list = new List(); + //boolean isExit = false; String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -10,7 +11,6 @@ public static void main(String[] args) { + "|____/ \\__,_|_|\\_\\___|\n"; String dash = "-"; - Scanner myObj = new Scanner(System.in); // print welcome message System.out.println("Hello from\n" + logo); @@ -19,34 +19,28 @@ public static void main(String[] args) { System.out.println("What can I do for you?"); System.out.println(dash.repeat(50)); - // scan input + Scanner myObj = new Scanner(System.in); String command = myObj.nextLine(); - - String[] tasks = new String[100]; - int count = 1; - while (!command.equals("bye") && !command.equals("list")) { - // add task into array - tasks[count] = command; - count++; - // echo task - System.out.println(dash.repeat(50)); - System.out.println("added: " + command); - System.out.println(dash.repeat(50)); - command = myObj.nextLine(); - } - // print list when command=list - if (command.equals("list")) { - for(int i=1; i Date: Tue, 2 Feb 2021 01:27:47 +0800 Subject: [PATCH 08/21] A-Coding Standard --- src/main/java/Duke.java | 2 +- src/main/java/List.java | 34 ++++++---------------------------- 2 files changed, 7 insertions(+), 29 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 0006a3674..0b2ca6726 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -32,7 +32,7 @@ else if (command.contains("done")) { list.taskCompleted(command); } // adds tasks into list - else {//(!command.equals("list") && !command.equals("done") && !command.equals("bye")) + else if (!command.equals("list") && !command.equals("done") && !command.equals("bye")) { System.out.println("added: " + command); list.addTasks(command); } diff --git a/src/main/java/List.java b/src/main/java/List.java index bbd80710f..08f84f552 100644 --- a/src/main/java/List.java +++ b/src/main/java/List.java @@ -23,45 +23,23 @@ public void taskCompleted(String command) { int count = Integer.parseInt(command); --count; // array starts from 0 this.list[count].markAsDone(); - System.out.println("-".repeat(50)); + printDash(); System.out.println("Nice! I've marked this task as done: "); System.out.println(this.list[count].getStatusIcon()); - System.out.println("-".repeat(50)); + printDash(); } // print list as a checklist when command=list public void printList() { - System.out.println("-".repeat(50)); + printDash(); System.out.println("Here are the tasks in your list: "); for (int i = 0; i < size; ++i) { System.out.println((i + 1) + "." + " " + this.list[i].getStatusIcon()); } + printDash(); + } + public void printDash() { System.out.println("-".repeat(50)); } } - /* while (!command.equals("bye") && !command.equals("list")) { - // add task into array - tasks[count] = command; - count++; - // echo task - System.out.println(dash.repeat(50)); - System.out.println("added: " + command); - System.out.println(dash.repeat(50)); - command = myObj.nextLine(); - }*/ - /*else { - tasks[value - 1].markAsDone(); - System.out.println(dash.repeat(50)); - System.out.println("Task " + value + " does not exit!"); - System.out.println(dash.repeat(50)); - } - } else { - System.out.println(dash.repeat(50)); - System.out.println("added: " + command); - System.out.println(dash.repeat(50)); - Task t = new Task(command); - tasks[count] = t; - count++; - } -}*/ From 2bd564b0bf8c09afc31b0d2cd3292ccda7d29295 Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Mon, 8 Feb 2021 22:09:02 +0800 Subject: [PATCH 09/21] Level - 4: ToDos, Events, Deadlines --- src/main/java/Deadline.java | 18 ++++++++ src/main/java/Duke.java | 91 +++++++++++++++++++++++++++++++------ src/main/java/Event.java | 15 ++++++ src/main/java/List.java | 30 ++++++++---- src/main/java/Task.java | 7 ++- src/main/java/Todo.java | 11 +++++ 6 files changed, 147 insertions(+), 25 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/Todo.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..0693884b1 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,18 @@ +public class Deadline extends Task{ + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + @Override + public String getStatusIcon() { + return "[D]" + super.getStatusIcon(); + } + + @Override + public String toString() { + return super.toString() + "(" + "by: " + by + ")"; + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 0b2ca6726..d359f4710 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,8 +1,24 @@ import java.util.Scanner; public class Duke { + public static Task[] tasks = new Task[100]; + public static int size = 0; + + // mark and display task that is completed + public static void taskCompleted(String command) { + // remove done from string + command = command.replace("done", " "); + command = command.strip(); + // convert string 2 into int 2 + int count = Integer.parseInt(command); + --count; // array starts from 0 + tasks[count].markAsDone(); + printDash(); + System.out.println("Nice! I've marked this task as done: "); + System.out.println(tasks[count].toString()); + printDash(); + } + public static void main(String[] args) { - List list = new List(); - //boolean isExit = false; String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -15,35 +31,82 @@ public static void main(String[] args) { // print welcome message System.out.println("Hello from\n" + logo); System.out.println(dash.repeat(50)); - System.out.println("Hello! I'm Duke"); - System.out.println("What can I do for you?"); + System.out.println("\tHello! I'm Duke"); + System.out.println("\tWhat can I do for you?"); System.out.println(dash.repeat(50)); Scanner myObj = new Scanner(System.in); String command = myObj.nextLine(); - //Task[] tasks = new Task[100]; + while (!command.equals("bye")) { // prints a checklist if (command.equals("list")) { - list.printList(); + printList(); } // marks current task as completed else if (command.contains("done")) { - list.taskCompleted(command); + taskCompleted(command); } // adds tasks into list - else if (!command.equals("list") && !command.equals("done") && !command.equals("bye")) { - System.out.println("added: " + command); - list.addTasks(command); + else { + addTasks(command); } command = myObj.nextLine(); } // exit program when input=bye - if (command.equals("bye")) { - System.out.println(dash.repeat(50)); - System.out.println("Bye. Hope to see you again soon!"); - System.out.println(dash.repeat(50)); + System.out.println(dash.repeat(50)); + System.out.println("Bye. Hope to see you again soon!"); + System.out.println(dash.repeat(50)); + + } + public static void addTasks(String description){ + System.out.println("\tGot it. I've added this task: "); + if(description.contains("todo")){ + description = description.replace("todo", ""); + description = description.strip(); + runTodo(description); + } + else if(description.contains("deadline")){ + description = description.replace("deadline", ""); + description = description.strip(); + runDeadline(description); + } + else if(description.contains("event")){ + description = description.replace("event", ""); + description = description.strip(); + runEvent(description); } + System.out.println(tasks[size++].toString()); + System.out.println("\tNow you have " + size + " tasks in the list"); + + } + // print list as a checklist when command=list + public static void printList() { + printDash(); + if(size != 0) { + System.out.println("Here are the tasks in your list: "); + for (int i = 1; i <= size; ++i) { + System.out.println(i + ". " + tasks[i-1].toString()); + } + } + else { + System.out.println("You do not have any pending task."); + } + printDash(); + } + public static void runDeadline(String description){ + String[] details = description.split(" /by"); + tasks[size] = new Deadline(details[0], details[1]); + } + public static void runTodo(String description) { + tasks[size] = new Todo(description); + } + public static void runEvent(String description){ + String[] details = description.split(" /at"); + tasks[size] = new Event(details[0], details[1]); + } + public static void printDash() { + System.out.println("-".repeat(50)); } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..04ccf0feb --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,15 @@ +public class Event extends Task{ + protected String by; + public Event(String description, String by) { + super(description); + this.by = by; + } + @Override + public String getStatusIcon() { + return "[E]" + super.getStatusIcon(); + } + @Override + public String toString() { + return super.toString() + "(" + "at: " + by + ")"; + } +} diff --git a/src/main/java/List.java b/src/main/java/List.java index 08f84f552..22854340d 100644 --- a/src/main/java/List.java +++ b/src/main/java/List.java @@ -1,17 +1,26 @@ -public class List { - private Task[] list; +/*public class List { + private Task[] tasks; private static int size; // list struct public List() { - this.list = new Task[100]; + this.tasks = new Task[100]; this.size = 0; } // add items to the list public void addTasks(String description) { - this.list[size] = new Task(description); - ++this.size; + System.out.println("Got it. I've added this task: "); + if(description.contains("todo")){ + this.tasks[size] = new Task(description); + } + else if(description.contains("deadline")){ + this.tasks[size] = new Deadline(description, "baa"); //use substring to put in two arguments + } + else if(description.contains("event")){ + this.tasks[size] = new Event(description, "boo"); //use substring to put in two arguments + } + ++this.size; //increment } // mark and display task that is completed @@ -22,10 +31,11 @@ public void taskCompleted(String command) { // convert string 2 into int 2 int count = Integer.parseInt(command); --count; // array starts from 0 - this.list[count].markAsDone(); + this.tasks[count].markAsDone(); printDash(); System.out.println("Nice! I've marked this task as done: "); - System.out.println(this.list[count].getStatusIcon()); + + System.out.println(this.tasks[count].getStatusIcon()); printDash(); } @@ -34,12 +44,14 @@ public void printList() { printDash(); System.out.println("Here are the tasks in your list: "); for (int i = 0; i < size; ++i) { - System.out.println((i + 1) + "." + " " + this.list[i].getStatusIcon()); + System.out.println((i + 1) + "." + " " + this.tasks[i]); } printDash(); } public void printDash() { System.out.println("-".repeat(50)); } -} + + +}*/ diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 851cadfc6..684cca62d 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -6,12 +6,15 @@ public Task(String description) { this.description = description; this.isDone = false; } - + public String toString() { + return getStatusIcon() + description; + } public String getStatusIcon() { - return (isDone ? "[X]" + " " + description : "[ ]" + " " + description); //return tick or X symbols + return (isDone ? "[X]" : "[ ]" ); //return tick or X symbols } public void markAsDone(){ isDone = true; } + } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..049b5ebea --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,11 @@ +public class Todo extends Task{ + public Todo(String description) { + super(description); + } + @Override + public String getStatusIcon() { return "[T]" + super.getStatusIcon(); + } + @Override + public String toString() { return super.toString(); + } +} From fdb778c584f75d89d8d31e4f1bca3bfc09e75a3d Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Tue, 9 Feb 2021 14:43:18 +0800 Subject: [PATCH 10/21] Alignment and indendation --- src/main/java/Deadline.java | 4 +-- src/main/java/Duke.java | 72 +++++++++++++++++++------------------ src/main/java/Event.java | 4 +-- src/main/java/Todo.java | 4 +-- 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 0693884b1..b92aa2ca1 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -8,11 +8,11 @@ public Deadline(String description, String by) { @Override public String getStatusIcon() { - return "[D]" + super.getStatusIcon(); + return "[D]" + super.getStatusIcon() + " "; } @Override public String toString() { - return super.toString() + "(" + "by: " + by + ")"; + return "\t " + super.toString() + "(" + "by:" + by + ")"; } } diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index d359f4710..07564ea6e 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,20 +3,6 @@ public class Duke { public static Task[] tasks = new Task[100]; public static int size = 0; - // mark and display task that is completed - public static void taskCompleted(String command) { - // remove done from string - command = command.replace("done", " "); - command = command.strip(); - // convert string 2 into int 2 - int count = Integer.parseInt(command); - --count; // array starts from 0 - tasks[count].markAsDone(); - printDash(); - System.out.println("Nice! I've marked this task as done: "); - System.out.println(tasks[count].toString()); - printDash(); - } public static void main(String[] args) { @@ -26,14 +12,12 @@ public static void main(String[] args) { + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - String dash = "-"; - // print welcome message System.out.println("Hello from\n" + logo); - System.out.println(dash.repeat(50)); + System.out.println("-".repeat(50)); System.out.println("\tHello! I'm Duke"); System.out.println("\tWhat can I do for you?"); - System.out.println(dash.repeat(50)); + printDash(); Scanner myObj = new Scanner(System.in); String command = myObj.nextLine(); @@ -54,57 +38,75 @@ else if (command.contains("done")) { command = myObj.nextLine(); } // exit program when input=bye - System.out.println(dash.repeat(50)); + printDash(); System.out.println("Bye. Hope to see you again soon!"); - System.out.println(dash.repeat(50)); - + printDash(); } - public static void addTasks(String description){ + + public static void addTasks(String description) { + printDash(); System.out.println("\tGot it. I've added this task: "); - if(description.contains("todo")){ + if (description.contains("todo")) { description = description.replace("todo", ""); description = description.strip(); runTodo(description); - } - else if(description.contains("deadline")){ + } else if (description.contains("deadline")) { description = description.replace("deadline", ""); description = description.strip(); runDeadline(description); - } - else if(description.contains("event")){ + } else if (description.contains("event")) { description = description.replace("event", ""); description = description.strip(); runEvent(description); } System.out.println(tasks[size++].toString()); System.out.println("\tNow you have " + size + " tasks in the list"); + printDash(); + } + // mark and display task that is completed + public static void taskCompleted(String command) { + // remove done from string + command = command.replace("done", " "); + command = command.strip(); + // convert string 2 into int 2 + int count = Integer.parseInt(command); + --count; // array starts from 0 + tasks[count].markAsDone(); + printDash(); + System.out.println("Nice! I've marked this task as done: "); + System.out.println(tasks[count].toString()); + printDash(); } + // print list as a checklist when command=list public static void printList() { printDash(); - if(size != 0) { - System.out.println("Here are the tasks in your list: "); + if (size != 0) { + System.out.println("\tHere are the tasks in your list: "); for (int i = 1; i <= size; ++i) { - System.out.println(i + ". " + tasks[i-1].toString()); + System.out.println("\t" + i + "." + tasks[i - 1].toString()); } - } - else { - System.out.println("You do not have any pending task."); + } else { + System.out.println("\tYou do not have any pending task."); } printDash(); } - public static void runDeadline(String description){ + + public static void runDeadline(String description) { String[] details = description.split(" /by"); tasks[size] = new Deadline(details[0], details[1]); } + public static void runTodo(String description) { tasks[size] = new Todo(description); } - public static void runEvent(String description){ + + public static void runEvent(String description) { String[] details = description.split(" /at"); tasks[size] = new Event(details[0], details[1]); } + public static void printDash() { System.out.println("-".repeat(50)); } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 04ccf0feb..7e54fd6bf 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -6,10 +6,10 @@ public Event(String description, String by) { } @Override public String getStatusIcon() { - return "[E]" + super.getStatusIcon(); + return "[E]" + super.getStatusIcon() + " " ; } @Override public String toString() { - return super.toString() + "(" + "at: " + by + ")"; + return "\t" + super.toString() + "(" + "at:" + by + ")"; } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 049b5ebea..1502955cb 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -3,9 +3,9 @@ public Todo(String description) { super(description); } @Override - public String getStatusIcon() { return "[T]" + super.getStatusIcon(); + public String getStatusIcon() { return "[T]" + super.getStatusIcon() + " "; } @Override - public String toString() { return super.toString(); + public String toString() { return "\t " + super.toString(); } } From 6f8663940f9dd375375670d97ee7a3accec7277b Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Sun, 14 Feb 2021 12:47:32 +0800 Subject: [PATCH 11/21] FirstDraft_Level - 5 --- src/main/java/Duke.java | 81 +++++++++++++++++++++++++++------------- src/main/java/Event.java | 2 +- 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 07564ea6e..16f8ecccb 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,9 +1,9 @@ import java.util.Scanner; public class Duke { + public static Task[] tasks = new Task[100]; public static int size = 0; - public static void main(String[] args) { String logo = " ____ _ \n" @@ -26,18 +26,18 @@ public static void main(String[] args) { // prints a checklist if (command.equals("list")) { printList(); - } - // marks current task as completed - else if (command.contains("done")) { + + // marks current task as completed + } else if (command.contains("done")) { taskCompleted(command); - } - // adds tasks into list - else { + + // add tasks to list + } else { addTasks(command); } command = myObj.nextLine(); } - // exit program when input=bye + // exit program printDash(); System.out.println("Bye. Hope to see you again soon!"); printDash(); @@ -45,20 +45,39 @@ else if (command.contains("done")) { public static void addTasks(String description) { printDash(); - System.out.println("\tGot it. I've added this task: "); if (description.contains("todo")) { - description = description.replace("todo", ""); - description = description.strip(); - runTodo(description); + try { + description = description.substring(5); + runTodo(description); + } catch (StringIndexOutOfBoundsException e) { + System.out.println("\tOOPS!!! The description of a todo cannot be empty."); + printDash(); + return; + } } else if (description.contains("deadline")) { - description = description.replace("deadline", ""); - description = description.strip(); - runDeadline(description); + try { + description = description.substring(9); + runDeadline(description); + } catch (StringIndexOutOfBoundsException e) { + System.out.println("\tOOPS!!! The description of a deadline cannot be empty."); + printDash(); + return; + } } else if (description.contains("event")) { - description = description.replace("event", ""); - description = description.strip(); - runEvent(description); + try { + description = description.substring(6); + runEvent(description); + } catch (StringIndexOutOfBoundsException e) { + System.out.println("\tOOPS!!! The description of a event cannot be empty"); + printDash(); + return; + } + } else { + System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); + printDash(); + return; } + System.out.println("\tGot it. I've added this task: "); System.out.println(tasks[size++].toString()); System.out.println("\tNow you have " + size + " tasks in the list"); printDash(); @@ -66,16 +85,28 @@ public static void addTasks(String description) { // mark and display task that is completed public static void taskCompleted(String command) { + int count = 0; // remove done from string command = command.replace("done", " "); command = command.strip(); - // convert string 2 into int 2 - int count = Integer.parseInt(command); - --count; // array starts from 0 - tasks[count].markAsDone(); printDash(); - System.out.println("Nice! I've marked this task as done: "); - System.out.println(tasks[count].toString()); + try { + count = Integer.parseInt(command); // convert string 2 into int 2 + } catch (NumberFormatException e) { + System.out.println("\tOOPS!!! Please indicate task number"); + printDash(); + return; + } + try { + --count; // array starts from 0 + tasks[count].markAsDone(); + System.out.println("\tNice! I've marked this task as done: "); + System.out.println(tasks[count].toString()); + } catch (NullPointerException e) { + System.out.println("\tOOPS!!! Please enter valid task number"); + printDash(); + return; + } printDash(); } @@ -108,7 +139,7 @@ public static void runEvent(String description) { } public static void printDash() { - System.out.println("-".repeat(50)); + System.out.println("-".repeat(80)); } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 7e54fd6bf..526385c87 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -10,6 +10,6 @@ public String getStatusIcon() { } @Override public String toString() { - return "\t" + super.toString() + "(" + "at:" + by + ")"; + return "\t " + super.toString() + "(" + "at:" + by + ")"; } } From 9776c4892f30494554b003d6ccd00b7a8024ce84 Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Fri, 19 Feb 2021 21:25:01 +0800 Subject: [PATCH 12/21] Level-6: Delete tasks function & ArrayList --- src/main/java/Duke.java | 90 ++++++++++++++++++++++++---------------- src/main/java/Event.java | 2 +- src/main/java/Task.java | 4 +- 3 files changed, 57 insertions(+), 39 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 07564ea6e..1dad9eb1e 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,24 +1,12 @@ import java.util.Scanner; +import java.util.ArrayList; + public class Duke { - public static Task[] tasks = new Task[100]; + //public static Task[] tasks = new Task[100]; public static int size = 0; - - + public static ArrayList tasks = new ArrayList<>(); public static void main(String[] args) { - - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - - // print welcome message - System.out.println("Hello from\n" + logo); - System.out.println("-".repeat(50)); - System.out.println("\tHello! I'm Duke"); - System.out.println("\tWhat can I do for you?"); - printDash(); - + printWelcomeMessage(); Scanner myObj = new Scanner(System.in); String command = myObj.nextLine(); @@ -26,13 +14,15 @@ public static void main(String[] args) { // prints a checklist if (command.equals("list")) { printList(); - } - // marks current task as completed - else if (command.contains("done")) { + + // marks current task as completed + } else if (command.contains("done")) { taskCompleted(command); - } - // adds tasks into list - else { + + // adds tasks into list + } else if (command.contains("delete")) { + deleteTasks(command); + } else { addTasks(command); } command = myObj.nextLine(); @@ -43,6 +33,22 @@ else if (command.contains("done")) { printDash(); } + public static void printWelcomeMessage() { + + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + + // print welcome message + System.out.println("Hello from\n" + logo); + printDash(); + System.out.println("\tHello! I'm Duke"); + System.out.println("\tWhat can I do for you?"); + printDash(); + } + public static void addTasks(String description) { printDash(); System.out.println("\tGot it. I've added this task: "); @@ -59,33 +65,45 @@ public static void addTasks(String description) { description = description.strip(); runEvent(description); } - System.out.println(tasks[size++].toString()); - System.out.println("\tNow you have " + size + " tasks in the list"); + System.out.println(tasks.get(tasks.size()-1).toString()); + System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); printDash(); } + public static void deleteTasks(String command) { + + command = command.replace("delete", " "); + command = command.strip(); + + int count = Integer.parseInt(command); + --count; // array starts from 0 + System.out.println("\tNoted. I've removed this task:\n" + tasks.get(count).toString()); + + tasks.remove(tasks.get(count)); + System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); + } - // mark and display task that is completed public static void taskCompleted(String command) { // remove done from string command = command.replace("done", " "); command = command.strip(); - // convert string 2 into int 2 + int count = Integer.parseInt(command); --count; // array starts from 0 - tasks[count].markAsDone(); + tasks.get(count).markAsDone(); + printDash(); - System.out.println("Nice! I've marked this task as done: "); - System.out.println(tasks[count].toString()); + System.out.println("\tNice! I've marked this task as done: "); + System.out.println(tasks.get(count).toString()); printDash(); } // print list as a checklist when command=list public static void printList() { printDash(); - if (size != 0) { + if (tasks.size() != 0) { System.out.println("\tHere are the tasks in your list: "); - for (int i = 1; i <= size; ++i) { - System.out.println("\t" + i + "." + tasks[i - 1].toString()); + for (int i = 1; i <= tasks.size(); ++i) { + System.out.println("\t" + i + "." + tasks.get(i - 1).toString()); } } else { System.out.println("\tYou do not have any pending task."); @@ -95,16 +113,16 @@ public static void printList() { public static void runDeadline(String description) { String[] details = description.split(" /by"); - tasks[size] = new Deadline(details[0], details[1]); + tasks.add(new Deadline(details[0], details[1])); } public static void runTodo(String description) { - tasks[size] = new Todo(description); + tasks.add(new Todo(description)); } public static void runEvent(String description) { String[] details = description.split(" /at"); - tasks[size] = new Event(details[0], details[1]); + tasks.add(new Event(details[0], details[1])); } public static void printDash() { diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 7e54fd6bf..526385c87 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -10,6 +10,6 @@ public String getStatusIcon() { } @Override public String toString() { - return "\t" + super.toString() + "(" + "at:" + by + ")"; + return "\t " + super.toString() + "(" + "at:" + by + ")"; } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 684cca62d..6a72e93d4 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -7,14 +7,14 @@ public Task(String description) { this.isDone = false; } public String toString() { - return getStatusIcon() + description; + return getStatusIcon() + this.description; } public String getStatusIcon() { return (isDone ? "[X]" : "[ ]" ); //return tick or X symbols } public void markAsDone(){ - isDone = true; + this.isDone = true; } } From ab566072064323679efd43d1724f7b4268bc5c09 Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Fri, 19 Feb 2021 23:24:51 +0800 Subject: [PATCH 13/21] Level-7: Saving & Uploading Data --- duke.txt | 1 + src/main/java/Deadline.java | 15 +++++++---- src/main/java/Duke.java | 53 ++++++++++++++++++++++++++++++++++++- src/main/java/Event.java | 14 +++++++--- src/main/java/Task.java | 4 +++ src/main/java/Todo.java | 9 +++++-- 6 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 duke.txt diff --git a/duke.txt b/duke.txt new file mode 100644 index 000000000..25fc8cd9d --- /dev/null +++ b/duke.txt @@ -0,0 +1 @@ +T ==> [X] ==> be happy diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index b92aa2ca1..878fa9a6a 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -7,12 +7,17 @@ public Deadline(String description, String by) { } @Override - public String getStatusIcon() { - return "[D]" + super.getStatusIcon() + " "; + public String toString() { + return "\t[D] " + super.toString() + "(" + "by:" + by + ")"; + } + public String getDescription() { + return this.description; + } + public String getBy() { + return this.by; } - @Override - public String toString() { - return "\t " + super.toString() + "(" + "by:" + by + ")"; + public String stringToSave() { + return "D ==> " + getStatusIcon() + " ==> " + getDescription() + " ==> " + getBy(); } } diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 07564ea6e..ed7037384 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,3 +1,7 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; import java.util.Scanner; public class Duke { public static Task[] tasks = new Task[100]; @@ -6,6 +10,7 @@ public class Duke { public static void main(String[] args) { + String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" @@ -18,7 +23,19 @@ public static void main(String[] args) { System.out.println("\tHello! I'm Duke"); System.out.println("\tWhat can I do for you?"); printDash(); - + String pathOfFile = new File("").getAbsolutePath(); + File tasksFile = new File(pathOfFile + "/duke.txt"); + try { + if (tasksFile.createNewFile()) { + System.out.println("\tTo save your task locally,\n" + + "\tA new file has been created at:\n\t" + + tasksFile.getAbsolutePath() + "\n"); + } + uploadTasks(tasksFile.getAbsolutePath()); + } catch (IOException e) { + System.out.println("\tThere was an I/O error:\nBye!\n"); + e.printStackTrace(); + } Scanner myObj = new Scanner(System.in); String command = myObj.nextLine(); @@ -41,8 +58,42 @@ else if (command.contains("done")) { printDash(); System.out.println("Bye. Hope to see you again soon!"); printDash(); + if (command.equals("bye")) { + try { + saveTasks(tasksFile.getAbsolutePath()); + } catch (IOException e) { + System.out.println("No file was saved due to an I/O error.\n"); + } + } + } + public static void uploadTasks(String pathOfFile) throws FileNotFoundException { + File f = new File(pathOfFile); + Scanner s = new Scanner(f); + while (s.hasNext()) { + String[] task = s.nextLine().split(" ==> "); + if (task[0].equals("T")) { + tasks[size] = new Todo(task[2]); + } else if (task[0].equals("D")) { + tasks[size] = new Deadline(task[2], task[3]); + } else { + tasks[size] = new Event(task[2], task[3]); + } + if (task[1].equals("[X]")) { + tasks[size].markAsDone(); + } + size++; + } + } + public static void saveTasks(String pathOfFile) throws IOException { + FileWriter fw = new FileWriter(pathOfFile); + for (int i=0; i " + getStatusIcon() + " ==> " + getDescription() + " ==> " + getBy(); } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 684cca62d..e35a4a78f 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -17,4 +17,8 @@ public void markAsDone(){ isDone = true; } + public String stringToSave() { + return ""; + } + } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 1502955cb..ce0c3aaa9 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -3,9 +3,14 @@ public Todo(String description) { super(description); } @Override - public String getStatusIcon() { return "[T]" + super.getStatusIcon() + " "; + public String toString() { return "\t[T] " + super.toString(); + } + public String getDescription() { + return this.description; } @Override - public String toString() { return "\t " + super.toString(); + public String stringToSave() { + return "T ==> " + getStatusIcon() + " ==> " + getDescription(); } + } From a9abe0bbc8f816d33748e46863924f65c825cb15 Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Thu, 25 Feb 2021 22:25:44 +0800 Subject: [PATCH 14/21] Changing magic numbers and strings --- src/main/java/Deadline.java | 13 ++++++++----- src/main/java/Duke.java | 19 +++++++++++-------- src/main/java/Event.java | 13 ++++++++----- src/main/java/META-INF/MANIFEST.MF | 3 +++ src/main/java/Task.java | 4 ++++ src/main/java/Todo.java | 5 +++-- 6 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 878fa9a6a..68196bd5e 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -4,20 +4,23 @@ public class Deadline extends Task{ public Deadline(String description, String by) { super(description); this.by = by; + this.SYMBOL = "D"; } - @Override - public String toString() { - return "\t[D] " + super.toString() + "(" + "by:" + by + ")"; - } public String getDescription() { return this.description; } public String getBy() { return this.by; } + + @Override + public String toString() { + return "\t[" + SYMBOL+ "]" + super.toString() + "(" + "by:" + by + ")"; + } + @Override public String stringToSave() { - return "D ==> " + getStatusIcon() + " ==> " + getDescription() + " ==> " + getBy(); + return SYMBOL + getStatusIcon() + ARROW + getDescription() + ARROW + getBy(); } } diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e739c84e1..e7f3dc274 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -6,7 +6,10 @@ import java.util.ArrayList; public class Duke { - //public static Task[] tasks = new Task[100]; + static int TODO_LENGTH = 5; + static int DEADLINE_LENGTH = 9; + static int EVENT_LENGTH = 6; + public static ArrayList tasks = new ArrayList<>(); public static void main(String[] args) { @@ -48,13 +51,11 @@ public static void main(String[] args) { } else if (command.contains("done")) { taskCompleted(command); - // adds tasks into list } else if (command.contains("delete")) { deleteTasks(command); // add tasks to list - } else { addTasks(command); } @@ -71,6 +72,7 @@ public static void main(String[] args) { } } + public static void uploadTasks(String pathOfFile) throws FileNotFoundException { File f = new File(pathOfFile); Scanner s = new Scanner(f); @@ -83,7 +85,6 @@ public static void uploadTasks(String pathOfFile) throws FileNotFoundException { } else { tasks.add(new Event(task[2], task[3])); } - if (task[1].equals("[X]")) { tasks.get(tasks.size()-1).markAsDone(); } @@ -101,7 +102,7 @@ public static void addTasks(String description) { printDash(); if (description.contains("todo")) { try { - description = description.substring(5); + description = description.substring(TODO_LENGTH); runTodo(description); } catch (StringIndexOutOfBoundsException e) { System.out.println("\tOOPS!!! The description of a todo cannot be empty."); @@ -110,7 +111,7 @@ public static void addTasks(String description) { } } else if (description.contains("deadline")) { try { - description = description.substring(9); + description = description.substring(DEADLINE_LENGTH); runDeadline(description); } catch (StringIndexOutOfBoundsException e) { System.out.println("\tOOPS!!! The description of a deadline cannot be empty."); @@ -119,7 +120,7 @@ public static void addTasks(String description) { } } else if (description.contains("event")) { try { - description = description.substring(6); + description = description.substring(EVENT_LENGTH); runEvent(description); } catch (StringIndexOutOfBoundsException e) { System.out.println("\tOOPS!!! The description of a event cannot be empty"); @@ -136,8 +137,9 @@ public static void addTasks(String description) { System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); printDash(); } - public static void deleteTasks(String command) { + // remove tasks from list + public static void deleteTasks(String command) { command = command.replace("delete", " "); command = command.strip(); @@ -149,6 +151,7 @@ public static void deleteTasks(String command) { System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); } + // update list when tasks are done public static void taskCompleted(String command) { int count = 0; // remove done from string diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 9af7e47b4..8720386c2 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -3,20 +3,23 @@ public class Event extends Task{ public Event(String description, String by) { super(description); this.by = by; + this.SYMBOL = "E"; } - @Override - public String toString() { - return "\t[E]" + super.toString() + "(" + "at:" + by + ")"; - } + public String getDescription() { return this.description; } public String getBy() { return this.by; } + @Override + public String toString() { + return "\t[" + SYMBOL + "]" + super.toString() + "(" + "at:" + by + ")"; + } + @Override public String stringToSave() { - return "E ==> " + getStatusIcon() + " ==> " + getDescription() + " ==> " + getBy(); + return SYMBOL + ARROW + getStatusIcon() + ARROW + getDescription() + ARROW + getBy(); } } diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..9f37e4e0a --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Duke + diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 4ec6b73f9..e2c60780a 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,14 +1,18 @@ public class Task { protected String description; protected boolean isDone; + protected String SYMBOL; + protected String ARROW = " ==> "; public Task(String description) { this.description = description; this.isDone = false; } + public String toString() { return getStatusIcon() + this.description; } + public String getStatusIcon() { return (isDone ? "[X]" : "[ ]" ); //return tick or X symbols } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index ce0c3aaa9..52b5845f3 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -1,16 +1,17 @@ public class Todo extends Task{ public Todo(String description) { super(description); + this.SYMBOL = "T"; } @Override - public String toString() { return "\t[T] " + super.toString(); + public String toString() { return "\t[ " + SYMBOL + "]" + super.toString(); } public String getDescription() { return this.description; } @Override public String stringToSave() { - return "T ==> " + getStatusIcon() + " ==> " + getDescription(); + return SYMBOL + ARROW + getStatusIcon() + ARROW + getDescription(); } } From 5b23d1cb65b94a8d681f87d62ad7e4abdc1e3155 Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Thu, 4 Mar 2021 20:28:49 +0800 Subject: [PATCH 15/21] A-MoreOOP --- duke.txt | 2 +- src/main/java/Duke.java | 213 +++++------------------------------- src/main/java/Storage.java | 75 +++++++++++++ src/main/java/Task.java | 4 + src/main/java/TaskList.java | 121 ++++++++++++++++++++ src/main/java/Ui.java | 30 +++++ 6 files changed, 260 insertions(+), 185 deletions(-) create mode 100644 src/main/java/Storage.java create mode 100644 src/main/java/TaskList.java create mode 100644 src/main/java/Ui.java diff --git a/duke.txt b/duke.txt index d6f89ae19..7eaf84342 100644 --- a/duke.txt +++ b/duke.txt @@ -1 +1 @@ -T ==> [ ] ==> be happy +T ==> [ ] ==> fghhjfg diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index e7f3dc274..8713a5a4d 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,216 +1,61 @@ import java.io.File; import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; import java.util.Scanner; -import java.util.ArrayList; public class Duke { static int TODO_LENGTH = 5; static int DEADLINE_LENGTH = 9; static int EVENT_LENGTH = 6; - public static ArrayList tasks = new ArrayList<>(); + protected Storage storage; + protected TaskList taskList; + protected Ui ui; + + public Duke(String filePath) { + ui = new Ui(filePath); + storage = new Storage(filePath); + try { + taskList = new TaskList(storage.uploadTasks()); + } catch (FileNotFoundException e) { + ui.showLoadingError(); + taskList = new TaskList(storage.createNewFile()); + } + } public static void main(String[] args) { + String pathOfFile = new File("").getAbsolutePath(); + new Duke(pathOfFile+"/duke.txt").run(); - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; + } - // print welcome message - System.out.println("Hello from\n" + logo); - System.out.println("-".repeat(50)); - System.out.println("\tHello! I'm Duke"); - System.out.println("\tWhat can I do for you?"); - printDash(); - String pathOfFile = new File("").getAbsolutePath(); - File tasksFile = new File(pathOfFile + "/duke.txt"); - try { - if (tasksFile.createNewFile()) { - System.out.println("\tTo save your task locally,\n" + - "\tA new file has been created at:\n\t" + - tasksFile.getAbsolutePath() + "\n"); - } - uploadTasks(tasksFile.getAbsolutePath()); - } catch (IOException e) { - System.out.println("\tThere was an I/O error:\nBye!\n"); - e.printStackTrace(); - } + public static void printDash() { + System.out.println("-".repeat(80)); + } + + public void run() { + Ui.printGreetMessage(); Scanner myObj = new Scanner(System.in); String command = myObj.nextLine(); - while (!command.equals("bye")) { // prints a checklist if (command.equals("list")) { - printList(); + taskList.printList(); // marks current task as completed } else if (command.contains("done")) { - taskCompleted(command); + taskList.taskCompleted(command); // adds tasks into list } else if (command.contains("delete")) { - deleteTasks(command); + taskList.deleteTasks(command); // add tasks to list } else { - addTasks(command); + taskList.addTasks(command); } command = myObj.nextLine(); } - // exit program - printDash(); - System.out.println("Bye. Hope to see you again soon!"); - printDash(); - try { - saveTasks(tasksFile.getAbsolutePath()); - } catch (IOException e) { - System.out.println("No file was saved due to an I/O error.\n"); - } - - } - - public static void uploadTasks(String pathOfFile) throws FileNotFoundException { - File f = new File(pathOfFile); - Scanner s = new Scanner(f); - while (s.hasNext()) { - String[] task = s.nextLine().split(" ==> "); - if (task[0].equals("T")) { - tasks.add(new Todo(task[2])); - } else if (task[0].equals("D")) { - tasks.add(new Deadline(task[2], task[3])); - } else { - tasks.add(new Event(task[2], task[3])); - } - if (task[1].equals("[X]")) { - tasks.get(tasks.size()-1).markAsDone(); - } - } - } - public static void saveTasks(String pathOfFile) throws IOException { - FileWriter fw = new FileWriter(pathOfFile); - for (Task task : tasks) { - fw.write(task.stringToSave()); - fw.write(System.lineSeparator()); - } - fw.close(); - } - public static void addTasks(String description) { - printDash(); - if (description.contains("todo")) { - try { - description = description.substring(TODO_LENGTH); - runTodo(description); - } catch (StringIndexOutOfBoundsException e) { - System.out.println("\tOOPS!!! The description of a todo cannot be empty."); - printDash(); - return; - } - } else if (description.contains("deadline")) { - try { - description = description.substring(DEADLINE_LENGTH); - runDeadline(description); - } catch (StringIndexOutOfBoundsException e) { - System.out.println("\tOOPS!!! The description of a deadline cannot be empty."); - printDash(); - return; - } - } else if (description.contains("event")) { - try { - description = description.substring(EVENT_LENGTH); - runEvent(description); - } catch (StringIndexOutOfBoundsException e) { - System.out.println("\tOOPS!!! The description of a event cannot be empty"); - printDash(); - return; - } - } else { - System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); - printDash(); - return; - } - System.out.println("\tGot it. I've added this task: "); - System.out.println(tasks.get(tasks.size()-1).toString()); - System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); - printDash(); - } - - // remove tasks from list - public static void deleteTasks(String command) { - command = command.replace("delete", " "); - command = command.strip(); - - int count = Integer.parseInt(command); - --count; // array starts from 0 - System.out.println("\tNoted. I've removed this task:\n" + tasks.get(count).toString()); - - tasks.remove(tasks.get(count)); - System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); + storage.exitProgram(); } - - // update list when tasks are done - public static void taskCompleted(String command) { - int count = 0; - // remove done from string - command = command.replace("done", " "); - command = command.strip(); - count = Integer.parseInt(command); - --count; // array starts from 0 - tasks.get(count).markAsDone(); - - try { - count = Integer.parseInt(command); // convert string 2 into int 2 - } catch (NumberFormatException e) { - System.out.println("\tOOPS!!! Please indicate task number"); - printDash(); - return; - } - try { - --count; // array starts from 0 - tasks.get(count).markAsDone(); - System.out.println("\tNice! I've marked this task as done: "); - System.out.println(tasks.get(count).toString()); - } catch (NullPointerException e) { - System.out.println("\tOOPS!!! Please enter valid task number"); - printDash(); - return; - } - printDash(); - } - - // print list as a checklist when command=list - public static void printList() { - printDash(); - if (tasks.size() != 0) { - System.out.println("\tHere are the tasks in your list: "); - for (int i = 1; i <= tasks.size(); ++i) { - System.out.println("\t" + i + "." + tasks.get(i - 1).toString()); - } - } else { - System.out.println("\tYou do not have any pending task."); - } - printDash(); - } - - public static void runDeadline(String description) { - String[] details = description.split(" /by"); - tasks.add(new Deadline(details[0], details[1])); - } - - public static void runTodo(String description) { - tasks.add(new Todo(description)); - } - - public static void runEvent(String description) { - String[] details = description.split(" /at"); - tasks.add(new Event(details[0], details[1])); - } - - public static void printDash() { - System.out.println("-".repeat(80)); - } - } + diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 000000000..66475ee4f --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,75 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +public class Storage { + protected String filepath; + protected ArrayList tasks = new ArrayList<>(); + public Storage(String filepath) { + this.filepath = filepath; + } + + public ArrayList createNewFile() { + + String pathOfFile = new File("").getAbsolutePath(); + File tasksFile = new File(pathOfFile + "/duke.txt"); + try { + if (tasksFile.createNewFile()) { + System.out.println("\tTo save your task locally,\n" + + "\tA new file has been created at:\n\t" + + tasksFile.getAbsolutePath() + "\n"); + } + } catch (IOException e) { + System.out.println("\tThere was an I/O error:\nBye!\n"); + e.printStackTrace(); + } + return tasks; + } + + public String getFilepath() { + return this.filepath; + } + + public ArrayList uploadTasks() throws FileNotFoundException { + File f = new File(getFilepath()); + Scanner s = new Scanner(f); + while (s.hasNext()) { + String[] task = s.nextLine().split(" ==> "); + if (task[0].equals("T")) { + tasks.add(new Todo(task[2])); + } else if (task[0].equals("D")) { + tasks.add(new Deadline(task[2], task[3])); + } else { + tasks.add(new Event(task[2], task[3])); + } + if (task[1].equals("[X]")) { + tasks.get(tasks.size()-1).markAsDone(); + } + } + return tasks; + } + + public void saveTasks() throws IOException { + FileWriter fw = new FileWriter(getFilepath()); + for (Task task : tasks) { + fw.write(task.stringToSave()); + fw.write(System.lineSeparator()); + } + fw.close(); + } + + public void exitProgram() { + Duke.printDash(); + System.out.println("Bye. Hope to see you again soon!"); + Duke.printDash(); + try { + saveTasks(); + } catch (IOException e) { + System.out.println("No file was saved due to an I/O error.\n"); + } + } + +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index e2c60780a..1a0ef47ae 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,9 +1,13 @@ +import java.util.ArrayList; + public class Task { protected String description; protected boolean isDone; protected String SYMBOL; protected String ARROW = " ==> "; +// public ArrayList tasks = new ArrayList<>(); + public Task(String description) { this.description = description; this.isDone = false; diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 000000000..358f4f8a5 --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,121 @@ +import java.util.ArrayList; + +public class TaskList { + protected ArrayList tasks; + public TaskList(ArrayList tasks) { + this.tasks = tasks; + } + + // print list as a checklist when command=list + public void printList() { + Duke.printDash(); + if (tasks.size() != 0) { + System.out.println("\tHere are the tasks in your list: "); + for (int i = 1; i <= tasks.size(); ++i) { + System.out.println("\t" + i + "." + tasks.get(i - 1).toString()); + } + } else { + System.out.println("\tYou do not have any pending task."); + } + Duke.printDash(); + } + + public void addTasks(String description) { + Duke.printDash(); + if (description.contains("todo")) { + try { + description = description.substring(Duke.TODO_LENGTH); + runTodo(description); + } catch (StringIndexOutOfBoundsException e) { + System.out.println("\tOOPS!!! The description of a todo cannot be empty."); + Duke.printDash(); + return; + } + } else if (description.contains("deadline")) { + try { + description = description.substring(Duke.DEADLINE_LENGTH); + runDeadline(description); + } catch (StringIndexOutOfBoundsException e) { + System.out.println("\tOOPS!!! The description of a deadline cannot be empty."); + Duke.printDash(); + return; + } + } else if (description.contains("event")) { + try { + description = description.substring(Duke.EVENT_LENGTH); + runEvent(description); + } catch (StringIndexOutOfBoundsException e) { + System.out.println("\tOOPS!!! The description of a event cannot be empty"); + Duke.printDash(); + return; + } + } else { + System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); + Duke.printDash(); + return; + } + System.out.println("\tGot it. I've added this task: "); + System.out.println(tasks.get(tasks.size()-1).toString()); + System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); + Duke.printDash(); + } + + // remove tasks from list + public void deleteTasks(String command) { + command = command.replace("delete", " "); + command = command.strip(); + + int count = Integer.parseInt(command); + --count; // array starts from 0 + System.out.println("\tNoted. I've removed this task:\n" + tasks.get(count).toString()); + + tasks.remove(tasks.get(count)); + System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); + } + + // update list when tasks are done + public void taskCompleted(String command) { + int count; + // remove done from string + command = command.replace("done", " "); + command = command.strip(); + count = Integer.parseInt(command); + --count; // array starts from 0 + tasks.get(count).markAsDone(); + + try { + count = Integer.parseInt(command); // convert string 2 into int 2 + } catch (NumberFormatException e) { + System.out.println("\tOOPS!!! Please indicate task number"); + Duke.printDash(); + return; + } + try { + --count; // array starts from 0 + tasks.get(count).markAsDone(); + System.out.println("\tNice! I've marked this task as done: "); + System.out.println(tasks.get(count).toString()); + } catch (NullPointerException e) { + System.out.println("\tOOPS!!! Please enter valid task number"); + Duke.printDash(); + return; + } + Duke.printDash(); + } + + public void runDeadline(String description) { + String[] details = description.split(" /by"); + tasks.add(new Deadline(details[0], details[1])); + } + + public void runTodo(String description) { + tasks.add(new Todo(description)); + } + + public void runEvent(String description) { + String[] details = description.split(" /at"); + tasks.add(new Event(details[0], details[1])); + } + + +} diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 000000000..873b379b3 --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,30 @@ +public class Ui { + protected String filepath; + public Ui (String filepath) { + this.filepath = filepath; + } + + public String getFilePath() { + return filepath; + } + + static void printGreetMessage() { + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + + // print welcome message + System.out.println("Hello from\n" + logo); + Duke.printDash(); + System.out.println("\tHello! I'm Duke"); + System.out.println("\tWhat can I do for you?"); + Duke.printDash(); + } + + public void showLoadingError() { + System.out.println("\tUnable to access file at "+ getFilePath()); + } + +} From bc4f45501991d167eb6e1f78ae0770188e0d1661 Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Thu, 4 Mar 2021 21:00:01 +0800 Subject: [PATCH 16/21] Level-9 --- src/main/java/Duke.java | 4 ++++ src/main/java/Task.java | 4 ++++ src/main/java/TaskList.java | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 8713a5a4d..b923bff74 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -49,6 +49,10 @@ public void run() { } else if (command.contains("delete")) { taskList.deleteTasks(command); + // finds task + } else if (command.contains("find")) { + taskList.filterList(command.substring(5)); + // add tasks to list } else { taskList.addTasks(command); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 1a0ef47ae..36ba936d6 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -29,4 +29,8 @@ public String stringToSave() { return ""; } + public String getDescription() { + return this.description; + } + } diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 358f4f8a5..a13a48afc 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -19,6 +19,12 @@ public void printList() { } Duke.printDash(); } + public void filterList(String filterString) { + Duke.printDash(); + tasks.stream() + .filter((s) -> s.getDescription().contains(filterString)) + .forEach(s -> System.out.println(s.toString())); + } public void addTasks(String description) { Duke.printDash(); From 4e8c643cb4deaf198bfb14793a2e759a810fd888 Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Thu, 4 Mar 2021 21:24:33 +0800 Subject: [PATCH 17/21] A-JavaDoc --- src/main/java/Storage.java | 20 ++++++++++++++++++++ src/main/java/Task.java | 3 +++ src/main/java/TaskList.java | 33 ++++++++++++++++++++++++++++++--- src/main/java/Ui.java | 8 ++++++-- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 66475ee4f..e9d0ecc1d 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -8,10 +8,16 @@ public class Storage { protected String filepath; protected ArrayList tasks = new ArrayList<>(); + public Storage(String filepath) { this.filepath = filepath; } + /** + * creates new file + * + * @return tasks array + */ public ArrayList createNewFile() { String pathOfFile = new File("").getAbsolutePath(); @@ -33,6 +39,11 @@ public String getFilepath() { return this.filepath; } + /** + * + * @return + * @throws FileNotFoundException + */ public ArrayList uploadTasks() throws FileNotFoundException { File f = new File(getFilepath()); Scanner s = new Scanner(f); @@ -52,6 +63,11 @@ public ArrayList uploadTasks() throws FileNotFoundException { return tasks; } + /** + * saves tasks into file + * + * @throws IOException + */ public void saveTasks() throws IOException { FileWriter fw = new FileWriter(getFilepath()); for (Task task : tasks) { @@ -61,6 +77,9 @@ public void saveTasks() throws IOException { fw.close(); } + /** + * exits program + */ public void exitProgram() { Duke.printDash(); System.out.println("Bye. Hope to see you again soon!"); @@ -73,3 +92,4 @@ public void exitProgram() { } } + diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 1a0ef47ae..68bfaa25b 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -29,4 +29,7 @@ public String stringToSave() { return ""; } + public String getDescription() { + return this.description; + } } diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 358f4f8a5..1755c7695 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -1,3 +1,4 @@ + import java.util.ArrayList; public class TaskList { @@ -6,7 +7,9 @@ public TaskList(ArrayList tasks) { this.tasks = tasks; } - // print list as a checklist when command=list + /** + * print list as a checklist when command=list + */ public void printList() { Duke.printDash(); if (tasks.size() != 0) { @@ -20,6 +23,22 @@ public void printList() { Duke.printDash(); } + /** + * finds for string in task Array List + * + * @param filterString + */ + public void filterList(String filterString) { + Duke.printDash(); + tasks.stream() + .filter((s) -> s.getDescription().contains(filterString)) + .forEach(s -> System.out.println(s.toString())); + } + + /** + * adds tasks into Array List + * @param description + */ public void addTasks(String description) { Duke.printDash(); if (description.contains("todo")) { @@ -60,7 +79,11 @@ public void addTasks(String description) { Duke.printDash(); } - // remove tasks from list + /** + * remove tasks from Array List + * + * @param command + */ public void deleteTasks(String command) { command = command.replace("delete", " "); command = command.strip(); @@ -73,7 +96,11 @@ public void deleteTasks(String command) { System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); } - // update list when tasks are done + /** + * update list when tasks are done + * + * @param command + */ public void taskCompleted(String command) { int count; // remove done from string diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 873b379b3..2d214856a 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -8,6 +8,9 @@ public String getFilePath() { return filepath; } + /** + * print welcome message + */ static void printGreetMessage() { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -15,14 +18,15 @@ static void printGreetMessage() { + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - // print welcome message System.out.println("Hello from\n" + logo); Duke.printDash(); System.out.println("\tHello! I'm Duke"); System.out.println("\tWhat can I do for you?"); Duke.printDash(); } - + /** + * print loading error message + */ public void showLoadingError() { System.out.println("\tUnable to access file at "+ getFilePath()); } From 0a78e32d6893f6d6939337e728503f075a25e997 Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Fri, 5 Mar 2021 22:02:40 +0800 Subject: [PATCH 18/21] A-CodeQuality --- duke.txt | 1 - src/main/java/Duke.java | 3 ++- src/main/java/Storage.java | 5 +++-- src/main/java/Task.java | 6 +----- src/main/java/TaskList.java | 7 +++++-- src/main/java/Todo.java | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 duke.txt diff --git a/duke.txt b/duke.txt deleted file mode 100644 index 7eaf84342..000000000 --- a/duke.txt +++ /dev/null @@ -1 +0,0 @@ -T ==> [ ] ==> fghhjfg diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index b923bff74..9c2038425 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -6,6 +6,7 @@ public class Duke { static int TODO_LENGTH = 5; static int DEADLINE_LENGTH = 9; static int EVENT_LENGTH = 6; + static int FIND_LENGTH = 5; protected Storage storage; protected TaskList taskList; @@ -51,7 +52,7 @@ public void run() { // finds task } else if (command.contains("find")) { - taskList.filterList(command.substring(5)); + taskList.filterList(command.substring(FIND_LENGTH)); // add tasks to list } else { diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index e9d0ecc1d..125e04fab 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -8,7 +8,6 @@ public class Storage { protected String filepath; protected ArrayList tasks = new ArrayList<>(); - public Storage(String filepath) { this.filepath = filepath; } @@ -41,7 +40,7 @@ public String getFilepath() { /** * - * @return + * @return tasks * @throws FileNotFoundException */ public ArrayList uploadTasks() throws FileNotFoundException { @@ -79,6 +78,8 @@ public void saveTasks() throws IOException { /** * exits program + * + * saves tasks into duke.txt */ public void exitProgram() { Duke.printDash(); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 68bfaa25b..c306e3303 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,13 +1,9 @@ -import java.util.ArrayList; - public class Task { protected String description; protected boolean isDone; protected String SYMBOL; protected String ARROW = " ==> "; -// public ArrayList tasks = new ArrayList<>(); - public Task(String description) { this.description = description; this.isDone = false; @@ -18,7 +14,7 @@ public String toString() { } public String getStatusIcon() { - return (isDone ? "[X]" : "[ ]" ); //return tick or X symbols + return (isDone ? "[X] " : "[ ] " ); //return tick or X symbols } public void markAsDone(){ diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 1755c7695..7549087e3 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -1,4 +1,3 @@ - import java.util.ArrayList; public class TaskList { @@ -24,7 +23,7 @@ public void printList() { } /** - * finds for string in task Array List + * finds keyword from list of tasks * * @param filterString */ @@ -33,6 +32,7 @@ public void filterList(String filterString) { tasks.stream() .filter((s) -> s.getDescription().contains(filterString)) .forEach(s -> System.out.println(s.toString())); + Duke.printDash(); } /** @@ -85,6 +85,7 @@ public void addTasks(String description) { * @param command */ public void deleteTasks(String command) { + Duke.printDash(); command = command.replace("delete", " "); command = command.strip(); @@ -94,6 +95,7 @@ public void deleteTasks(String command) { tasks.remove(tasks.get(count)); System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); + Duke.printDash(); } /** @@ -102,6 +104,7 @@ public void deleteTasks(String command) { * @param command */ public void taskCompleted(String command) { + Duke.printDash(); int count; // remove done from string command = command.replace("done", " "); diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 52b5845f3..8c3029b79 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -4,7 +4,7 @@ public Todo(String description) { this.SYMBOL = "T"; } @Override - public String toString() { return "\t[ " + SYMBOL + "]" + super.toString(); + public String toString() { return "\t[" + SYMBOL + "]" + super.toString(); } public String getDescription() { return this.description; From 179da2498b62119d4938841f1f3cfb05c581546a Mon Sep 17 00:00:00 2001 From: NoorSarrah <77370767+NoorSarrah@users.noreply.github.com> Date: Fri, 5 Mar 2021 22:27:38 +0800 Subject: [PATCH 19/21] A-UserGuide --- README.md | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 193 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 303bc3d19..37aa9b8c2 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,36 @@ -# Duke project template +# Duke Project +---------------------------------------------------------------------------------------- +#### By Noor Sarrah -This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. +This program is named after Java mascot Duke. +Given below are the instructions on how to use it -## Setting up in Intellij + +## Table of Contents +1. [Quick Start](#Quickstart) -Prerequisites: JDK 11, update IntelliJ to the most recent version. + 1. [Setting up in Intellij](#SetUpIntellij) + 1. [Setting up Duke](#SetUpDuke) + +1. [Running Duke](#RunDuke) -### On IntelliJ version 2020.3.1 (latest) and beyond + 1. [Command: **`todo `**](#todo) + 2. [Command: **`deadline /by <...>`**](#deadline) + 3. [Command: **`event /at <...>`**](#event) + 4. [Command: **`done `**](#done) + 5. [Command: **`list`**](list) + 6. [Command: **`delete `**](#delete) + 7. [Command: **`find `**](#find) + 8. [Command: **`bye`**](#bye) + +1. [Command Summary](#Commandsummary) + + +## Quick Start + + +### Setting up in Intellij +#### On IntelliJ version 2020.3.1 (latest) and beyond 1. Open IntelliJ (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) 1. Import the project into IntelliJ as follows: @@ -14,13 +38,169 @@ Prerequisites: JDK 11, update IntelliJ to the most recent version. 1. Select the project directory, and click `OK` 1. If there are any further prompts, accept the defaults. 1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk). -1. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()`. If the setup is correct, you should see something like the output below. + +### Setting up Duke +1. On the terminal, locate your home folder where you have saved the .jar file. + + 1. cd to change directory + 1. ls to view files in the current directory + +1. Once you have entered the home folder, type the following command: java -jar + + 1. You should see the Duke logo along with a welcome message. Duke is now ready to be used! + 1. You would see this greeting message, for example: + + ``` + Unable to access file at C:\Users\User\Desktop\ip final/duke.txt + To save your task locally, + A new file has been created at: + C:\Users\User\Desktop\ip final\duke.txt + +Hello from + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| + +-------------------------------------------------------------------------------- +Hello! I'm Duke +What can I do for you? +-------------------------------------------------------------------------------- ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +Back to [Table of Contents](#table-of-contents) + + +## Running Duke + + +i. Command: `todo `
Adds a To-Do to your list
[T] symbol represents To-Do task
e.g. `todo read book` + +Output: +``` +-------------------------------------------------------------------------------- + Got it. I've added this task: + [T][ ] read book + Now you have 1 task in the list. +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +ii. Command `deadline /by <…>`
Adds a Deadline to your list
[D] symbol represents Deadline task
Time should be stated inside <…>
e.g. `deadline finish homework /by 2pm Monday` + +Output: +``` +-------------------------------------------------------------------------------- + Got it. I've added this task: + [D][ ] finish homework (by: 2pm Monday) + Now you have 2 tasks in the list. +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +iii. Command `event /at <…>`
Adds an Event to your list
[E] symbol represents Event task
Time should be stated inside <…>
e.g. `event family dinner/at 5-6pm Saturday` + +Output: +``` +-------------------------------------------------------------------------------- + Got it. I've added this task: + [E][ ] family dinner(at: 7-10pm Saturday) + Now you have 3 tasks in the list. +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +iv. Command `done `
Marks task with in list as 'done'
indicated by [X] in field beside task
e.g. `done 2` + +Output: +``` +-------------------------------------------------------------------------------- + Nice! I've marked this task as done: + [D][X] finish homework (by: 2pm Monday) +-------------------------------------------------------------------------------- + +``` + +Your *tasks.txt* file will look like this: +``` +T --> --> be happy +D --> X --> finish homework --> 2pm Monday +E --> --> family dinner --> 7-10pm Saturday + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +v. Command `list`
Prints all the tasks along with dates and times
e.g. `list` + +Output: +``` +-------------------------------------------------------------------------------- + Here are the tasks in your list: + 1. [T][ ] read book + 2. [D][ ] finish homework(by: 2pm Monday) + 3. [E][ ] book club(at: 11-12pm Tuesday) + 4. [E][ ] family dinner(at: 7-10pm Saturday) +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +vi. Command `delete `
Removes task with in list
e.g. `delete 2` + +Output: +``` +-------------------------------------------------------------------------------- + Noted. I've removed this task: + [D][X] finish homework (by: 2pm Moday) + Now you have 2 tasks in the list. +--------------------------------------------------------------------------------- +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +vii. Command `find `
Finds and filters out the tasks with
e.g. `find book` + +Output: +``` +--------------------------------------------------------------------------------- + Here are the matching tasks in your list: + 1. [T][X] read book + 2. [E][X] book club (at: 11-12pm Tuesday) +--------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +viii. Command `bye`
Exits the program.
e.g. `bye` + +Output: +``` +-------------------------------------------------------------------------------- +Bye. Hope to see you again soon! +-------------------------------------------------------------------------------- +``` +NOTE: Before ending the program, all the tasks will be saved in *tasks.txt* file. + + +## Command Summary +Command |Function +------------ | ------------- +`todo `| Adds a To-Do to your list +`deadline /by <...>` | Adds a Deadline to your list +`event /at <...>` | Adds an Event to your list +`done ` |Marks a task at task number in list as done +`delete ` | Removes a task at task number from list +`list` | Prints all the tasks along with dates and times +`find ` | Finds and filters out the tasks with a desired keyword +`bye` | Exits the program. + From 17c7b91c96fa6d4907e2de1077b9552d643fed82 Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Fri, 5 Mar 2021 22:55:32 +0800 Subject: [PATCH 20/21] A-UserGuide --- docs/README.md | 208 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 197 insertions(+), 11 deletions(-) diff --git a/docs/README.md b/docs/README.md index fd4406959..00ad1f9bd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,20 +1,206 @@ -# User Guide +# Duke Project +---------------------------------------------------------------------------------------- +#### By Noor Sarrah -## Features +This program is named after Java mascot Duke. +Given below are the instructions on how to use it -### Feature 1 -Description of feature. + +## Table of Contents +1. [Quick Start](#Quickstart) -## Usage + 1. [Setting up in Intellij](#SetUpIntellij) + 1. [Setting up Duke](#SetUpDuke) -### `Keyword` - Describe action +1. [Running Duke](#RunDuke) -Describe action and its outcome. + 1. [Command: **`todo `**](#todo) + 2. [Command: **`deadline /by <...>`**](#deadline) + 3. [Command: **`event /at <...>`**](#event) + 4. [Command: **`done `**](#done) + 5. [Command: **`list`**](list) + 6. [Command: **`delete `**](#delete) + 7. [Command: **`find `**](#find) + 8. [Command: **`bye`**](#bye) -Example of usage: +1. [Command Summary](#Commandsummary) -`keyword (optional arguments)` + +## Quick Start -Expected outcome: + +### Setting up in Intellij +#### On IntelliJ version 2020.3.1 (latest) and beyond + +1. Open IntelliJ (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) +1. Import the project into IntelliJ as follows: + 1. Click `Open` + 1. Select the project directory, and click `OK` + 1. If there are any further prompts, accept the defaults. +1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk). + + +### Setting up Duke +1. On the terminal, locate your home folder where you have saved the .jar file. + + 1. cd to change directory + 1. ls to view files in the current directory + +1. Once you have entered the home folder, type the following command: java -jar + + 1. You should see the Duke logo along with a welcome message. Duke is now ready to be used! + 1. You would see this greeting message, for example: + + ``` + Unable to access file at C:\Users\User\Desktop\ip final/duke.txt + To save your task locally, + A new file has been created at: + C:\Users\User\Desktop\ip final\duke.txt + +Hello from + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| + +-------------------------------------------------------------------------------- +Hello! I'm Duke +What can I do for you? +-------------------------------------------------------------------------------- + ``` +Back to [Table of Contents](#table-of-contents) + + +## Running Duke + + +i. Command: `todo `
Adds a To-Do to your list
[T] symbol represents To-Do task
e.g. `todo read book` + +Output: +``` +-------------------------------------------------------------------------------- + Got it. I've added this task: + [T][ ] read book + Now you have 1 task in the list. +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +ii. Command `deadline /by <…>`
Adds a Deadline to your list
[D] symbol represents Deadline task
Time should be stated inside <…>
e.g. `deadline finish homework /by 2pm Monday` + +Output: +``` +-------------------------------------------------------------------------------- + Got it. I've added this task: + [D][ ] finish homework (by: 2pm Monday) + Now you have 2 tasks in the list. +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +iii. Command `event /at <…>`
Adds an Event to your list
[E] symbol represents Event task
Time should be stated inside <…>
e.g. `event family dinner/at 5-6pm Saturday` + +Output: +``` +-------------------------------------------------------------------------------- + Got it. I've added this task: + [E][ ] family dinner(at: 7-10pm Saturday) + Now you have 3 tasks in the list. +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +iv. Command `done `
Marks task with in list as 'done'
indicated by [X] in field beside task
e.g. `done 2` + +Output: +``` +-------------------------------------------------------------------------------- + Nice! I've marked this task as done: + [D][X] finish homework (by: 2pm Monday) +-------------------------------------------------------------------------------- + +``` + +Your *tasks.txt* file will look like this: +``` +T --> --> be happy +D --> X --> finish homework --> 2pm Monday +E --> --> family dinner --> 7-10pm Saturday + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +v. Command `list`
Prints all the tasks along with dates and times
e.g. `list` + +Output: +``` +-------------------------------------------------------------------------------- + Here are the tasks in your list: + 1. [T][ ] read book + 2. [D][ ] finish homework(by: 2pm Monday) + 3. [E][ ] book club(at: 11-12pm Tuesday) + 4. [E][ ] family dinner(at: 7-10pm Saturday) +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +vi. Command `delete `
Removes task with in list
e.g. `delete 2` + +Output: +``` +-------------------------------------------------------------------------------- + Noted. I've removed this task: + [D][X] finish homework (by: 2pm Moday) + Now you have 2 tasks in the list. +--------------------------------------------------------------------------------- +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +vii. Command `find `
Finds and filters out the tasks with
e.g. `find book` + +Output: +``` +--------------------------------------------------------------------------------- + Here are the matching tasks in your list: + 1. [T][X] read book + 2. [E][X] book club (at: 11-12pm Tuesday) +--------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +viii. Command `bye`
Exits the program.
e.g. `bye` + +Output: +``` +-------------------------------------------------------------------------------- +Bye. Hope to see you again soon! +-------------------------------------------------------------------------------- +``` +NOTE: Before ending the program, all the tasks will be saved in *tasks.txt* file. + + +## Command Summary +Command |Function +------------ | ------------- +`todo `| Adds a To-Do to your list +`deadline /by <...>` | Adds a Deadline to your list +`event /at <...>` | Adds an Event to your list +`done ` |Marks a task at task number in list as done +`delete ` | Removes a task at task number from list +`list` | Prints all the tasks along with dates and times +`find ` | Finds and filters out the tasks with a desired keyword +`bye` | Exits the program. -`outcome` From a7ea9dcb49da448916990e0737cac3d12baa551e Mon Sep 17 00:00:00 2001 From: NoorSarrah Date: Sat, 27 Mar 2021 23:45:41 +0800 Subject: [PATCH 21/21] Final IP --- src/main/java/Deadline.java | 5 + src/main/java/Duke.java | 14 +-- src/main/java/EmptyLineException.java | 9 ++ src/main/java/Event.java | 6 ++ src/main/java/List.java | 57 ----------- src/main/java/META-INF/MANIFEST.MF | 3 - src/main/java/Storage.java | 32 +++---- src/main/java/Task.java | 4 + src/main/java/TaskList.java | 132 +++++++++++++++----------- src/main/java/Todo.java | 4 + src/main/java/Ui.java | 58 ++++++++++- 11 files changed, 187 insertions(+), 137 deletions(-) create mode 100644 src/main/java/EmptyLineException.java delete mode 100644 src/main/java/List.java delete mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 68196bd5e..ec050c094 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,6 +1,11 @@ public class Deadline extends Task{ protected String by; + /** + * + * @param description + * @param by + */ public Deadline(String description, String by) { super(description); this.by = by; diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 9c2038425..5bb8f9de9 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,7 +3,7 @@ import java.util.Scanner; public class Duke { - static int TODO_LENGTH = 5; + static int TODO_LENGTH = 4; static int DEADLINE_LENGTH = 9; static int EVENT_LENGTH = 6; static int FIND_LENGTH = 5; @@ -29,10 +29,6 @@ public static void main(String[] args) { } - public static void printDash() { - System.out.println("-".repeat(80)); - } - public void run() { Ui.printGreetMessage(); Scanner myObj = new Scanner(System.in); @@ -55,8 +51,14 @@ public void run() { taskList.filterList(command.substring(FIND_LENGTH)); // add tasks to list - } else { + } else if (command.contains("todo") + || command.contains("deadline") + || command.contains("event")) { taskList.addTasks(command); + } else { + Ui.printDash(); + System.out.println("\tOOPS!!! Please enter a valid command."); + Ui.printDash(); } command = myObj.nextLine(); } diff --git a/src/main/java/EmptyLineException.java b/src/main/java/EmptyLineException.java new file mode 100644 index 000000000..7f324c9e9 --- /dev/null +++ b/src/main/java/EmptyLineException.java @@ -0,0 +1,9 @@ +public class EmptyLineException extends Exception { + public EmptyLineException() { + /*switch (type) { + case "whitespace": + System.out.println("\tOOPS!!! Please enter valid description for Todo"); + break; + }*/ + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 8720386c2..78ad5a841 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,5 +1,11 @@ public class Event extends Task{ protected String by; + + /** + * + * @param description + * @param by + */ public Event(String description, String by) { super(description); this.by = by; diff --git a/src/main/java/List.java b/src/main/java/List.java deleted file mode 100644 index 22854340d..000000000 --- a/src/main/java/List.java +++ /dev/null @@ -1,57 +0,0 @@ -/*public class List { - private Task[] tasks; - private static int size; - - // list struct - public List() { - this.tasks = new Task[100]; - this.size = 0; - } - - // add items to the list - public void addTasks(String description) { - System.out.println("Got it. I've added this task: "); - if(description.contains("todo")){ - this.tasks[size] = new Task(description); - } - else if(description.contains("deadline")){ - this.tasks[size] = new Deadline(description, "baa"); //use substring to put in two arguments - } - else if(description.contains("event")){ - this.tasks[size] = new Event(description, "boo"); //use substring to put in two arguments - } - ++this.size; //increment - } - - // mark and display task that is completed - public void taskCompleted(String command) { - // remove done from string - command = command.replace("done", " "); - command = command.strip(); - // convert string 2 into int 2 - int count = Integer.parseInt(command); - --count; // array starts from 0 - this.tasks[count].markAsDone(); - printDash(); - System.out.println("Nice! I've marked this task as done: "); - - System.out.println(this.tasks[count].getStatusIcon()); - printDash(); - } - - // print list as a checklist when command=list - public void printList() { - printDash(); - System.out.println("Here are the tasks in your list: "); - for (int i = 0; i < size; ++i) { - System.out.println((i + 1) + "." + " " + this.tasks[i]); - } - printDash(); - } - public void printDash() { - System.out.println("-".repeat(50)); - } - - -}*/ - diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF deleted file mode 100644 index 9f37e4e0a..000000000 --- a/src/main/java/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: Duke - diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 125e04fab..ecea45ca9 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -44,21 +44,21 @@ public String getFilepath() { * @throws FileNotFoundException */ public ArrayList uploadTasks() throws FileNotFoundException { - File f = new File(getFilepath()); - Scanner s = new Scanner(f); - while (s.hasNext()) { - String[] task = s.nextLine().split(" ==> "); - if (task[0].equals("T")) { - tasks.add(new Todo(task[2])); - } else if (task[0].equals("D")) { - tasks.add(new Deadline(task[2], task[3])); - } else { - tasks.add(new Event(task[2], task[3])); + File f = new File(getFilepath()); + Scanner s = new Scanner(f); + while (s.hasNext()) { + String[] task = s.nextLine().split(" ==> "); + if (task[0].equals("T")) { + tasks.add(new Todo(task[2])); + } else if (task[0].equals("D")) { + tasks.add(new Deadline(task[2], task[3])); + } else { + tasks.add(new Event(task[2], task[3])); + } + if (task[1].equals("[X]")) { + tasks.get(tasks.size() - 1).markAsDone(); + } } - if (task[1].equals("[X]")) { - tasks.get(tasks.size()-1).markAsDone(); - } - } return tasks; } @@ -82,9 +82,9 @@ public void saveTasks() throws IOException { * saves tasks into duke.txt */ public void exitProgram() { - Duke.printDash(); + Ui.printDash(); System.out.println("Bye. Hope to see you again soon!"); - Duke.printDash(); + Ui.printDash(); try { saveTasks(); } catch (IOException e) { diff --git a/src/main/java/Task.java b/src/main/java/Task.java index c306e3303..00c9a70ba 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -4,6 +4,10 @@ public class Task { protected String SYMBOL; protected String ARROW = " ==> "; + /** + * + * @param description + */ public Task(String description) { this.description = description; this.isDone = false; diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 7549087e3..c42a6ba42 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -10,16 +10,16 @@ public TaskList(ArrayList tasks) { * print list as a checklist when command=list */ public void printList() { - Duke.printDash(); + Ui.printDash(); if (tasks.size() != 0) { - System.out.println("\tHere are the tasks in your list: "); + Ui.validListMessage(); for (int i = 1; i <= tasks.size(); ++i) { System.out.println("\t" + i + "." + tasks.get(i - 1).toString()); } } else { - System.out.println("\tYou do not have any pending task."); + Ui.emptyListMessage(); } - Duke.printDash(); + Ui.printDash(); } /** @@ -28,55 +28,56 @@ public void printList() { * @param filterString */ public void filterList(String filterString) { - Duke.printDash(); + Ui.printDash(); tasks.stream() .filter((s) -> s.getDescription().contains(filterString)) .forEach(s -> System.out.println(s.toString())); - Duke.printDash(); + Ui.printDash(); } /** * adds tasks into Array List - * @param description + * @param line */ - public void addTasks(String description) { - Duke.printDash(); - if (description.contains("todo")) { + public void addTasks(String line) { + Ui.printDash(); + String[] action = line.split(" "); + if (action[0].equals("todo")) { try { - description = description.substring(Duke.TODO_LENGTH); - runTodo(description); - } catch (StringIndexOutOfBoundsException e) { - System.out.println("\tOOPS!!! The description of a todo cannot be empty."); - Duke.printDash(); + line = line.substring(Duke.TODO_LENGTH).trim(); + runTodo(line); + } catch (NullPointerException | EmptyLineException | StringIndexOutOfBoundsException | ArrayIndexOutOfBoundsException e) { + System.out.println("\tOOPS!!! Please enter a valid command."); + Ui.printDash(); return; } - } else if (description.contains("deadline")) { + } else if (action[0].equals("deadline")) { try { - description = description.substring(Duke.DEADLINE_LENGTH); - runDeadline(description); - } catch (StringIndexOutOfBoundsException e) { - System.out.println("\tOOPS!!! The description of a deadline cannot be empty."); - Duke.printDash(); + line = line.substring(Duke.DEADLINE_LENGTH); + runDeadline(line); + } catch (EmptyLineException | StringIndexOutOfBoundsException | ArrayIndexOutOfBoundsException e) { + System.out.println("\tOOPS!!! Please enter a valid command."); + Ui.printDash(); return; } - } else if (description.contains("event")) { + } else if (action[0].contains("event")) { try { - description = description.substring(Duke.EVENT_LENGTH); - runEvent(description); - } catch (StringIndexOutOfBoundsException e) { - System.out.println("\tOOPS!!! The description of a event cannot be empty"); - Duke.printDash(); + line = line.substring(Duke.EVENT_LENGTH); + runEvent(line); + } catch (EmptyLineException | StringIndexOutOfBoundsException | ArrayIndexOutOfBoundsException e) { + System.out.println("\tOOPS!!! Please enter a valid command."); + Ui.printDash(); return; } } else { - System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); - Duke.printDash(); + Ui.invalidCommandMessage(); + Ui.printDash(); return; } - System.out.println("\tGot it. I've added this task: "); + Ui.addedTaskMessage(); System.out.println(tasks.get(tasks.size()-1).toString()); System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); - Duke.printDash(); + Ui.printDash(); } /** @@ -85,17 +86,21 @@ public void addTasks(String description) { * @param command */ public void deleteTasks(String command) { - Duke.printDash(); + Ui.printDash(); command = command.replace("delete", " "); command = command.strip(); + try { + int count = Integer.parseInt(command); + --count; // array starts from 0 + System.out.println("\tNoted. I've removed this task:\n" + tasks.get(count).toString()); - int count = Integer.parseInt(command); - --count; // array starts from 0 - System.out.println("\tNoted. I've removed this task:\n" + tasks.get(count).toString()); - - tasks.remove(tasks.get(count)); - System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); - Duke.printDash(); + tasks.remove(tasks.get(count)); + System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); + Ui.printDash(); + } catch (NumberFormatException e) { + Ui.invalidTaskNumberMessage(); + Ui.printDash(); + } } /** @@ -104,9 +109,8 @@ public void deleteTasks(String command) { * @param command */ public void taskCompleted(String command) { - Duke.printDash(); + Ui.printDash(); int count; - // remove done from string command = command.replace("done", " "); command = command.strip(); count = Integer.parseInt(command); @@ -116,35 +120,57 @@ public void taskCompleted(String command) { try { count = Integer.parseInt(command); // convert string 2 into int 2 } catch (NumberFormatException e) { - System.out.println("\tOOPS!!! Please indicate task number"); - Duke.printDash(); + Ui.emptyTaskNumberMessage(); + Ui.printDash(); return; } try { --count; // array starts from 0 tasks.get(count).markAsDone(); - System.out.println("\tNice! I've marked this task as done: "); + Ui.taskIsDoneMessage(); System.out.println(tasks.get(count).toString()); } catch (NullPointerException e) { - System.out.println("\tOOPS!!! Please enter valid task number"); - Duke.printDash(); + Ui.invalidTaskNumberMessage(); + Ui.printDash(); return; } - Duke.printDash(); + Ui.printDash(); } - public void runDeadline(String description) { - String[] details = description.split(" /by"); + /** + * + * @param description + */ + public void runDeadline(String description) throws EmptyLineException { + String[] details = description.trim().split("/by"); + if (details.length != 2 || details[0].trim().isEmpty() || details[1].trim().isEmpty()) { + throw new EmptyLineException(); + } tasks.add(new Deadline(details[0], details[1])); } - public void runTodo(String description) { + /** + * + * @param description + * @throws EmptyLineException + */ + public void runTodo(String description) throws EmptyLineException { + if (description.length() == 0) { + throw new EmptyLineException(); + } tasks.add(new Todo(description)); } - public void runEvent(String description) { - String[] details = description.split(" /at"); - tasks.add(new Event(details[0], details[1])); + /** + * + * @param description + */ + public void runEvent(String description) throws EmptyLineException { + String[] details = description.split("/at"); + if (details.length != 2 || details[0].trim().isEmpty() || details[1].trim().isEmpty()) { + throw new EmptyLineException(); + } + tasks.add(new Event(details[0].trim(), details[1])); } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 8c3029b79..a942450d5 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -1,4 +1,8 @@ public class Todo extends Task{ + /** + * + * @param description + */ public Todo(String description) { super(description); this.SYMBOL = "T"; diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 2d214856a..250288d9d 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -4,6 +4,10 @@ public Ui (String filepath) { this.filepath = filepath; } + public static void printDash() { + System.out.println("-".repeat(80)); + } + public String getFilePath() { return filepath; } @@ -19,11 +23,12 @@ static void printGreetMessage() { + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); - Duke.printDash(); + printDash(); System.out.println("\tHello! I'm Duke"); System.out.println("\tWhat can I do for you?"); - Duke.printDash(); + printDash(); } + /** * print loading error message */ @@ -31,4 +36,53 @@ public void showLoadingError() { System.out.println("\tUnable to access file at "+ getFilePath()); } + /** + * print empty task number message + */ + public static void emptyTaskNumberMessage() { + System.out.println("\tOOPS!!! Please indicate task number"); + } + + /** + * print list message + */ + public static void validListMessage() { + System.out.println("\ttHere are the tasks in your list: "); + } + + /** + * print empty list message + */ + public static void emptyListMessage() { + System.out.println("\tYou do not have any pending task."); + } + + /** + * print invalid command message + */ + public static void invalidCommandMessage() { + System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); + } + + /** + * print added task message + */ + public static void addedTaskMessage() { + System.out.println("\tGot it. I've added this task: "); + } + + /** + * print invalid task number message + */ + public static void invalidTaskNumberMessage() { + System.out.println("\tOOPS!!! Please enter valid task number"); + } + + /** + * print completed task message + */ + public static void taskIsDoneMessage() { + System.out.println("\tNice! I've marked this task as done: "); + } + }