From 85d198231d609506e626759148bb07807a91b305 Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Thu, 26 Aug 2021 22:51:51 +0800 Subject: [PATCH 01/26] Level 1 --- src/main/java/Duke.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..7ff195af6 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,23 @@ public static void main(String[] args) { + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); + + System.out.println("____________________________________________________________\n" + + "Hello! I'm Duke\n" + + "What can I do for you?\n" + + "____________________________________________________________\n"); + Scanner input = new Scanner(System.in); + while (true){ + String str = input.nextLine(); + if (str.equals("bye")) { + System.out.println("____________________________________________________________\n" + + "Bye. Hope to see you again soon!\n" + + "____________________________________________________________\n"); + break; + } + System.out.println("____________________________________________________________\n" + + str + "\n" + + "____________________________________________________________\n"); + } } } From cac3d8e5690d66855f69f761fca84f6fadbd3eee Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Thu, 26 Aug 2021 22:56:36 +0800 Subject: [PATCH 02/26] Level 2 --- src/main/java/Duke.java | 57 +++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 7ff195af6..5b29b68e0 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,5 +1,31 @@ import java.util.Scanner; -public class Duke { + +public class Main { + + private static String[] l = new String[100]; + private static int listSize = 0; + + public static void addToList(String input) { + l[listSize] = input; + listSize++; + System.out.println(" ____________________________________________________________\n"+ + "Added: "+input + "\n" + + " ____________________________________________________________\n"); + } + + public static void printItems(){ + if (listSize == 0){ + System.out.println("The list is empty."); + } + else{ + System.out.println(" ____________________________________________________________\n"); + for (int i = 1; i<=listSize; i++){ + System.out.println(i + ". " + l[i-1]); + } + System.out.println(" ____________________________________________________________\n"); + } + } + public static void main(String[] args) { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -8,22 +34,27 @@ public static void main(String[] args) { + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); - System.out.println("____________________________________________________________\n" + - "Hello! I'm Duke\n" + - "What can I do for you?\n" + - "____________________________________________________________\n"); + System.out.println(" ____________________________________________________________\n" + + " Hello! I'm Duke\n" + + " What can I do for you?\n" + + " ____________________________________________________________\n"); Scanner input = new Scanner(System.in); while (true){ String str = input.nextLine(); - if (str.equals("bye")) { - System.out.println("____________________________________________________________\n" + - "Bye. Hope to see you again soon!\n" + - "____________________________________________________________\n"); + if (str.equals("bye")){ + System.out.println(" ____________________________________________________________\n" + + " Bye. Hope to see you again soon!\n" + + " ____________________________________________________________\n"); break; } - System.out.println("____________________________________________________________\n" + - str + "\n" + - "____________________________________________________________\n"); + else if (str.equals("list")){ + printItems(); + } + else { + addToList(str); + } } + + } -} +} \ No newline at end of file From 1fd8497819721022968bdc0ad3917725008e148e Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Thu, 26 Aug 2021 23:02:31 +0800 Subject: [PATCH 03/26] Level 3 --- src/main/java/Duke.java | 69 +++++++++++++++++++++-------------------- src/main/java/list.java | 44 ++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 33 deletions(-) create mode 100644 src/main/java/list.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5b29b68e0..efd764d3a 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,30 +1,8 @@ import java.util.Scanner; +import java.lang.String; -public class Main { +public class Duke { - private static String[] l = new String[100]; - private static int listSize = 0; - - public static void addToList(String input) { - l[listSize] = input; - listSize++; - System.out.println(" ____________________________________________________________\n"+ - "Added: "+input + "\n" + - " ____________________________________________________________\n"); - } - - public static void printItems(){ - if (listSize == 0){ - System.out.println("The list is empty."); - } - else{ - System.out.println(" ____________________________________________________________\n"); - for (int i = 1; i<=listSize; i++){ - System.out.println(i + ". " + l[i-1]); - } - System.out.println(" ____________________________________________________________\n"); - } - } public static void main(String[] args) { String logo = " ____ _ \n" @@ -34,24 +12,49 @@ public static void main(String[] args) { + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); - System.out.println(" ____________________________________________________________\n" + - " Hello! I'm Duke\n" + - " What can I do for you?\n" + - " ____________________________________________________________\n"); + System.out.println("____________________________________________________________\n" + + "Hello! I'm Duke\n" + + "What can I do for you?\n" + + "____________________________________________________________\n"); Scanner input = new Scanner(System.in); while (true){ String str = input.nextLine(); if (str.equals("bye")){ - System.out.println(" ____________________________________________________________\n" + - " Bye. Hope to see you again soon!\n" + - " ____________________________________________________________\n"); + System.out.println("____________________________________________________________\n" + + "Bye. Hope to see you again soon!\n" + + "____________________________________________________________\n"); break; } else if (str.equals("list")){ - printItems(); + System.out.println("____________________________________________________________\n" + + "Here are the tasks in your list: "); + list.printItems(); + System.out.println("____________________________________________________________"); + } + else if (str.contains("Done ") == true){ + String nums = ""; + for (int i=0;i list.listSize){ + System.out.println("____________________________________________________________\n" + + "The index is out of range.\n" + + "____________________________________________________________\n"); + } + else{ + list.mark(index); + System.out.println("____________________________________________________________\n" + + "Nice! I've marked this task as done: "); + list.markedItems(); + System.out.println("____________________________________________________________"); + } } else { - addToList(str); + list.addToList(str); } } diff --git a/src/main/java/list.java b/src/main/java/list.java new file mode 100644 index 000000000..6693a4d7b --- /dev/null +++ b/src/main/java/list.java @@ -0,0 +1,44 @@ +public class list { + private static String[] l = new String[100]; + public static int listSize = 0; + private static int[] isDone = new int[100]; + + public static void addToList(String input) { + l[listSize] = input; + listSize++; + System.out.println("____________________________________________________________\n"+ + "Added: "+input + "\n" + + "____________________________________________________________\n"); + } + + public static void printItems(){ + if (listSize == 0){ + System.out.println("The list is empty."); + } + else{ + for (int i = 1; i<=listSize; i++){ + System.out.print(i + ". " ); + System.out.print("["); + if (isDone[i-1] == 1){ + System.out.print("X"); + } + else{ + System.out.print(" "); + } + System.out.print("] " + l[i-1] + "\n"); + } + } + } + + public static void mark(int number){ + isDone[number-1] = 1; + } + + public static void markedItems(){ + for (int i=0;i Date: Thu, 26 Aug 2021 23:16:07 +0800 Subject: [PATCH 04/26] A-CodingStandard --- src/main/java/Duke.java | 60 +++++++++++++++++++---------------------- src/main/java/List.java | 42 +++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 33 deletions(-) create mode 100644 src/main/java/List.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index efd764d3a..42be18259 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,8 +2,6 @@ import java.lang.String; public class Duke { - - public static void main(String[] args) { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -12,52 +10,48 @@ public static void main(String[] args) { + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); - System.out.println("____________________________________________________________\n" + - "Hello! I'm Duke\n" + - "What can I do for you?\n" + - "____________________________________________________________\n"); + System.out.println("____________________________________________________________\n" + + "Hello! I'm Duke\n" + + "What can I do for you?\n" + + "____________________________________________________________\n"); Scanner input = new Scanner(System.in); - while (true){ + while (true) { String str = input.nextLine(); - if (str.equals("bye")){ - System.out.println("____________________________________________________________\n" + - "Bye. Hope to see you again soon!\n" + - "____________________________________________________________\n"); + if (str.equals("bye")) { + System.out.println("____________________________________________________________\n" + + "Bye. Hope to see you again soon!\n" + + "____________________________________________________________\n"); break; } - else if (str.equals("list")){ - System.out.println("____________________________________________________________\n" + - "Here are the tasks in your list: "); - list.printItems(); + else if (str.equals("list")) { + System.out.println("____________________________________________________________\n" + + "Here are the tasks in your list: "); + List.printItems(); System.out.println("____________________________________________________________"); } - else if (str.contains("Done ") == true){ + else if (str.contains("Done ") == true) { String nums = ""; - for (int i=0;i list.listSize){ - System.out.println("____________________________________________________________\n" + - "The index is out of range.\n" + - "____________________________________________________________\n"); - } - else{ - list.mark(index); - System.out.println("____________________________________________________________\n" + - "Nice! I've marked this task as done: "); - list.markedItems(); + if (index > List.listSize) { + System.out.println("____________________________________________________________\n" + + "The index is out of range.\n" + + "____________________________________________________________\n"); + } else { + List.mark(index); + System.out.println("____________________________________________________________\n" + + "Nice! I've marked this task as done: "); + List.markedItems(); System.out.println("____________________________________________________________"); } - } - else { - list.addToList(str); + } else { + List.addToList(str); } } - - } } \ No newline at end of file diff --git a/src/main/java/List.java b/src/main/java/List.java new file mode 100644 index 000000000..eb883f3cc --- /dev/null +++ b/src/main/java/List.java @@ -0,0 +1,42 @@ +public class List { + private static String[] currentList = new String[100]; + public static int listSize = 0; + private static int[] isDone = new int[100]; + + public static void addToList(String input) { + currentList[listSize] = input; + listSize++; + System.out.println("____________________________________________________________\n" + + "Added: " + input + "\n" + + "____________________________________________________________\n"); + } + + public static void printItems() { + if (listSize == 0) { + System.out.println("The list is empty."); + } else { + for (int i = 1; i <= listSize; i++) { + System.out.print(i + ". " ); + System.out.print("["); + if (isDone[i-1] == 1) { + System.out.print("X"); + } else { + System.out.print(" "); + } + System.out.print("] " + currentList[i-1] + "\n"); + } + } + } + + public static void mark(int number) { + isDone[number-1] = 1; + } + + public static void markedItems() { + for (int i = 0; i < isDone.length; i++) { + if (isDone[i] == 1) { + System.out.println("[X] " + currentList[i]); + } + } + } +} From 6141721ad6757213107c95bc3265c8ff5024a5dc Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Thu, 2 Sep 2021 11:08:16 +0800 Subject: [PATCH 05/26] commit --- src/main/java/list.java | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/list.java b/src/main/java/list.java index 6693a4d7b..eb883f3cc 100644 --- a/src/main/java/list.java +++ b/src/main/java/list.java @@ -1,43 +1,41 @@ -public class list { - private static String[] l = new String[100]; +public class List { + private static String[] currentList = new String[100]; public static int listSize = 0; private static int[] isDone = new int[100]; public static void addToList(String input) { - l[listSize] = input; + currentList[listSize] = input; listSize++; - System.out.println("____________________________________________________________\n"+ - "Added: "+input + "\n" + - "____________________________________________________________\n"); + System.out.println("____________________________________________________________\n" + + "Added: " + input + "\n" + + "____________________________________________________________\n"); } - public static void printItems(){ - if (listSize == 0){ + public static void printItems() { + if (listSize == 0) { System.out.println("The list is empty."); - } - else{ - for (int i = 1; i<=listSize; i++){ + } else { + for (int i = 1; i <= listSize; i++) { System.out.print(i + ". " ); System.out.print("["); - if (isDone[i-1] == 1){ + if (isDone[i-1] == 1) { System.out.print("X"); - } - else{ + } else { System.out.print(" "); } - System.out.print("] " + l[i-1] + "\n"); + System.out.print("] " + currentList[i-1] + "\n"); } } } - public static void mark(int number){ + public static void mark(int number) { isDone[number-1] = 1; } - public static void markedItems(){ - for (int i=0;i Date: Sat, 4 Sep 2021 11:19:00 +0800 Subject: [PATCH 06/26] level4 A codeQuality --- src/main/java/Duke.java | 44 +++++++++++++++++----------- src/main/java/list.java | 63 ++++++++++++++++++++++++++++------------- 2 files changed, 71 insertions(+), 36 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 42be18259..deefab755 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,6 +2,7 @@ import java.lang.String; public class Duke { + public static void main(String[] args) { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -14,43 +15,54 @@ public static void main(String[] args) { + "Hello! I'm Duke\n" + "What can I do for you?\n" + "____________________________________________________________\n"); + + list.initializing(); Scanner input = new Scanner(System.in); while (true) { String str = input.nextLine(); + //input = NULL + if (str.trim().equals("")) { + continue; + } + //input = bye if (str.equals("bye")) { System.out.println("____________________________________________________________\n" + "Bye. Hope to see you again soon!\n" + "____________________________________________________________\n"); break; } + //input = list else if (str.equals("list")) { - System.out.println("____________________________________________________________\n" - + "Here are the tasks in your list: "); - List.printItems(); + System.out.println("____________________________________________________________\n" + + "Here are the tasks in your list: "); + list.printItems(); System.out.println("____________________________________________________________"); } - else if (str.contains("Done ") == true) { + //input = Done xx + else if (str.contains("Done ") == true){ String nums = ""; - for (int i = 0; i < str.length(); i++) { + for (int i=0;i List.listSize) { - System.out.println("____________________________________________________________\n" - + "The index is out of range.\n" - + "____________________________________________________________\n"); - } else { - List.mark(index); - System.out.println("____________________________________________________________\n" - + "Nice! I've marked this task as done: "); - List.markedItems(); + if (index > list.listSize){ + System.out.println("____________________________________________________________\n" + + "The index is out of range.\n" + + "____________________________________________________________\n"); + } + else{ + list.mark(index); + System.out.println("____________________________________________________________\n" + + "Nice! I've marked this task as done: "); + list.printMarkedItems(); System.out.println("____________________________________________________________"); } } else { - List.addToList(str); + //input = task + list.addToList(str); } } } diff --git a/src/main/java/list.java b/src/main/java/list.java index eb883f3cc..ed6d9c677 100644 --- a/src/main/java/list.java +++ b/src/main/java/list.java @@ -1,41 +1,64 @@ -public class List { - private static String[] currentList = new String[100]; +public class list { + private static String[] l = new String[100]; public static int listSize = 0; - private static int[] isDone = new int[100]; + private static String[] isDone = new String[100]; + private static String[] type = new String[100]; + + public static void initializing() { + for (int i = 0; i < 100; i++) { + isDone[i] = " "; + type[i] = " "; + } + } public static void addToList(String input) { - currentList[listSize] = input; + if (input.contains("todo")) { + l[listSize] = input.substring(5); + type[listSize] = "T"; + } else if (input.contains("deadline")) { + String by = input.substring(input.indexOf("/") + 4); + l[listSize] = input.substring(9, input.indexOf("/")) + " (by: " + by + + ")"; + type[listSize] = "D"; + } else if (input.contains("event")) { + String at = input.substring(input.indexOf("/") + 4); + l[listSize] = input.substring(6, input.indexOf("/")) + "(at: " + at + + ")"; + type[listSize] = "E"; + } listSize++; System.out.println("____________________________________________________________\n" - + "Added: " + input + "\n" + + "Got it. I've added this task: \n" + + " [" + type[listSize - 1] + "]" + + "[" + isDone[listSize - 1] + "]" + + l[listSize - 1] + "\n" + + "Now you have " + listSize + " tasks in the list.\n" + "____________________________________________________________\n"); } - public static void printItems() { + public static void printItems(){ if (listSize == 0) { System.out.println("The list is empty."); + System.out.println("The list is empty."); + return; } else { - for (int i = 1; i <= listSize; i++) { + for (int i = 1; i <= listSize; i++){ System.out.print(i + ". " ); - System.out.print("["); - if (isDone[i-1] == 1) { - System.out.print("X"); - } else { - System.out.print(" "); - } - System.out.print("] " + currentList[i-1] + "\n"); + System.out.print("[" + type[i - 1] + "]" + "[" + + isDone[i - 1] + "] " + l[i-1] + "\n"); } } } - public static void mark(int number) { - isDone[number-1] = 1; + public static void mark(int number){ + isDone[number-1] = "X"; } - public static void markedItems() { - for (int i = 0; i < isDone.length; i++) { - if (isDone[i] == 1) { - System.out.println("[X] " + currentList[i]); + public static void printMarkedItems(){ + for (int i=0;i Date: Thu, 9 Sep 2021 12:23:38 +0800 Subject: [PATCH 07/26] Level 5 --- src/main/java/Deadline.java | 2 ++ src/main/java/DukeException.java | 2 ++ src/main/java/Event.java | 2 ++ src/main/java/Task.java | 2 ++ src/main/java/Todo.java | 2 ++ 5 files changed, 10 insertions(+) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/DukeException.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/Task.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..623a1f49d --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class Deadline { +} diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java new file mode 100644 index 000000000..882a05274 --- /dev/null +++ b/src/main/java/DukeException.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class DukeException { +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..fe6147652 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class Event { +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..4ec445449 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class Task { +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..73a10cb4d --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class Todo { +} From 1a6a0acd3a43e1f42a77aebd2fc7f7a350cf806f Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Thu, 9 Sep 2021 22:40:50 +0800 Subject: [PATCH 08/26] Level 5 --- src/main/java/Deadline.java | 14 ++- src/main/java/Duke.java | 177 ++++++++++++++++++++++--------- src/main/java/DukeException.java | 3 +- src/main/java/Event.java | 14 ++- src/main/java/Task.java | 19 +++- src/main/java/Todo.java | 10 +- 6 files changed, 184 insertions(+), 53 deletions(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 623a1f49d..a4a2c1c0d 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,2 +1,14 @@ -package PACKAGE_NAME;public class Deadline { +public class Deadline extends Task { + public String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + @Override + public String toString() { + return "[D]" + super.toString() + "(by: " + this.by + + ")"; + } } diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index deefab755..46f60792e 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,7 +3,76 @@ public class Duke { + public static final String line = "____________________________________________________________\n"; + public static final int MAX_NUM_OF_TASKS = 100; + public static final int TODO_POS = 5; + public static final int BY_POS = 4; + public static final int DEADLINE_POS = 9; + public static final int AT_POS = 4; + public static final int EVENT_POS = 6; + + public static int numOfTasks = 0; + public static void main(String[] args) { + + greeting(); + + Task[] tasks = new Task[MAX_NUM_OF_TASKS]; + + Scanner input = new Scanner(System.in); + while (true) { + String inputString = input.nextLine(); + if (inputString.equals("bye")) { + exit(); + break; + } else if (inputString.equals("list")) { + printList(tasks); + } else if (inputString.contains("done") == true) { + try { + setDone(inputString, tasks); + } + catch(IndexOutOfBoundsException i) { + System.out.println(line + + "☹ OOPS!!! The index of done indstruction cannot be empty.\n" + + line); + } + catch(NumberFormatException n) { + System.out.println(line + + "☹ OOPS!!! The index of done indstruction should be a number.\n" + + line); + } + catch(NullPointerException p) { + System.out.println(line + + "☹ OOPS!!! The index is out of range.\n" + + line); + } + } else { + try { + addTask(inputString, tasks); + } + catch(IndexOutOfBoundsException i) { + String type = ""; + if (inputString.contains("todo")) { + type = "todo"; + } else if (inputString.contains("deadline")) { + type = "deadline"; + } else if (inputString.contains("event")) { + type = "event"; + } + System.out.println(line + + "☹ OOPS!!! The description of a " + type + " cannot be empty.\n" + + line); + } + catch(NullPointerException n) { + System.out.println(line + + "☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n" + + line); + } + } + } + } + + public static final void greeting() { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" @@ -11,59 +80,71 @@ public static void main(String[] args) { + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); - System.out.println("____________________________________________________________\n" + System.out.println(line + "Hello! I'm Duke\n" + "What can I do for you?\n" - + "____________________________________________________________\n"); + + line); + } - list.initializing(); - Scanner input = new Scanner(System.in); - while (true) { - String str = input.nextLine(); - //input = NULL - if (str.trim().equals("")) { - continue; - } - //input = bye - if (str.equals("bye")) { - System.out.println("____________________________________________________________\n" - + "Bye. Hope to see you again soon!\n" - + "____________________________________________________________\n"); - break; - } - //input = list - else if (str.equals("list")) { - System.out.println("____________________________________________________________\n" + - "Here are the tasks in your list: "); - list.printItems(); - System.out.println("____________________________________________________________"); + public static final void exit() { + System.out.println(line + + "Bye. Hope to see you again soon!\n" + + line); + } + + public static final void printList(Task[] tasks) { + if (numOfTasks == 0) { + System.out.println(line + + "The list is empty.\n" + + line); + } else { + System.out.println(line + + "Here are the tasks in your list: "); + + for (int index = 0; index < numOfTasks; index++) { + System.out.println((index + 1) + ". " + + tasks[index].toString()); } - //input = Done xx - else if (str.contains("Done ") == true){ - String nums = ""; - for (int i=0;i list.listSize){ - System.out.println("____________________________________________________________\n" + - "The index is out of range.\n" + - "____________________________________________________________\n"); - } - else{ - list.mark(index); - System.out.println("____________________________________________________________\n" + - "Nice! I've marked this task as done: "); - list.printMarkedItems(); - System.out.println("____________________________________________________________"); - } - } else { - //input = task - list.addToList(str); + System.out.println(line); + } + } + + public static final void setDone(String input, Task[] tasks) { + String num = ""; + for (int i = 0; i < input.length(); i++) { + char c = input.charAt(i); + if (Character.isDigit(c) == true) { + num += c; } } + int index = Integer.parseInt(num); + tasks[index - 1].markedAsDone(); + System.out.println(line + + "Nice! I've marked this task as done: \n" + + tasks[index - 1] + "\n" + + line); + } + + public static final void addTask(String input, Task[] tasks) throws NullPointerException { + if (input.contains("todo") == true) { + tasks[numOfTasks] = new Todo(input.substring(TODO_POS)); + } else if (input.contains("deadline") == true) { + String by = input.substring(input.indexOf("/") + BY_POS); + tasks[numOfTasks] = new Deadline(input.substring(DEADLINE_POS, + input.indexOf("/")), by); + } else if (input.contains("event") == true) { + String at = input.substring(input.indexOf("/") + AT_POS); + tasks[numOfTasks] = new Event(input.substring(EVENT_POS, + input.indexOf("/")), at); + } else { + System.out.print(tasks[numOfTasks + 1].toString()); + } + numOfTasks++; + System.out.println(line + + "Got it. I've added this task: \n" + + tasks[numOfTasks - 1] + "\n" + + "Now you have " + numOfTasks + + " tasks in the list\n" + + line); } } \ No newline at end of file diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java index 882a05274..5e322ffd4 100644 --- a/src/main/java/DukeException.java +++ b/src/main/java/DukeException.java @@ -1,2 +1,3 @@ -package PACKAGE_NAME;public class DukeException { +public class DukeException extends Exception { + } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index fe6147652..b111f0b64 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,2 +1,14 @@ -package PACKAGE_NAME;public class Event { +public class Event extends Task { + public String at; + + public Event(String description, String at) { + super(description); + this.at = at; + } + + @Override + public String toString() { + return "[E]" + super.toString() + "(at: " + this.at + + ")"; + } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 4ec445449..d20f062a2 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,2 +1,19 @@ -package PACKAGE_NAME;public class Task { +public class Task { + protected String description; + protected String isDone; + + public Task(String description) { + this.description = description; + this.isDone = " "; + } + + public final void markedAsDone() { + this.isDone = "X"; + } + + @Override + public String toString() { + String status; + return "[" + isDone + "] " + this.description; + } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 73a10cb4d..f42295d3e 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -1,2 +1,10 @@ -package PACKAGE_NAME;public class Todo { +public class Todo extends Task{ + + public Todo(String description) { + super(description); + } + @Override + public String toString() { + return "[T]" + super.toString(); + } } From 9f131cc81aa2b3e851c91e91c60781cf9fd71279 Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Thu, 9 Sep 2021 23:05:26 +0800 Subject: [PATCH 09/26] Add branch --- src/main/java/Todo.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index f42295d3e..60bd80871 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -3,6 +3,7 @@ public class Todo extends Task{ public Todo(String description) { super(description); } + @Override public String toString() { return "[T]" + super.toString(); From 7cac7da28566c1cd1d41abad41f30f87444fc02e Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Fri, 10 Sep 2021 23:33:01 +0800 Subject: [PATCH 10/26] Add DukeException --- src/main/java/Duke.java | 14 +++++++++----- src/main/java/DukeException.java | 8 ++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 46f60792e..ded31972f 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -26,7 +26,13 @@ public static void main(String[] args) { exit(); break; } else if (inputString.equals("list")) { - printList(tasks); + try { + printList(tasks); + } + catch(DukeException d) { + System.out.println(line + + d.getMessage() + "\n" + line); + } } else if (inputString.contains("done") == true) { try { setDone(inputString, tasks); @@ -92,11 +98,9 @@ public static final void exit() { + line); } - public static final void printList(Task[] tasks) { + public static final void printList(Task[] tasks) throws DukeException{ if (numOfTasks == 0) { - System.out.println(line - + "The list is empty.\n" - + line); + throw new DukeException("The list is empty!"); } else { System.out.println(line + "Here are the tasks in your list: "); diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java index 5e322ffd4..3e1e3c056 100644 --- a/src/main/java/DukeException.java +++ b/src/main/java/DukeException.java @@ -1,3 +1,11 @@ public class DukeException extends Exception { + public DukeException() { + super(); + } + + public DukeException(String message) { + super(message); + } + } From 6be3ec007176fbf88a773f5ac35f372a83d56f99 Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Fri, 10 Sep 2021 23:39:16 +0800 Subject: [PATCH 11/26] Add exceptions --- src/main/java/Duke.java | 1 + src/main/java/DukeException.java | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index ded31972f..0acea9378 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -143,6 +143,7 @@ public static final void addTask(String input, Task[] tasks) throws NullPointerE } else { System.out.print(tasks[numOfTasks + 1].toString()); } + numOfTasks++; System.out.println(line + "Got it. I've added this task: \n" diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java index 3e1e3c056..5350398d9 100644 --- a/src/main/java/DukeException.java +++ b/src/main/java/DukeException.java @@ -7,5 +7,4 @@ public DukeException() { public DukeException(String message) { super(message); } - } From 5aa495ed94d07fa484470d0b5b9916a928f7b8f4 Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Fri, 10 Sep 2021 23:43:07 +0800 Subject: [PATCH 12/26] Add exception --- src/main/java/Duke.java | 1 + src/main/java/DukeException.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 0acea9378..f3aaabcc2 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -121,6 +121,7 @@ public static final void setDone(String input, Task[] tasks) { num += c; } } + int index = Integer.parseInt(num); tasks[index - 1].markedAsDone(); System.out.println(line diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java index 5350398d9..e3c50c477 100644 --- a/src/main/java/DukeException.java +++ b/src/main/java/DukeException.java @@ -7,4 +7,5 @@ public DukeException() { public DukeException(String message) { super(message); } + } From ecee40d0ab637b5afae2f3c9f84b913c1d090fd6 Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Fri, 10 Sep 2021 23:45:13 +0800 Subject: [PATCH 13/26] Add exceptions --- 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 f3aaabcc2..f0416b8c3 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -121,7 +121,7 @@ public static final void setDone(String input, Task[] tasks) { num += c; } } - + int index = Integer.parseInt(num); tasks[index - 1].markedAsDone(); System.out.println(line From 1b59f7829b95931467b98c179f8740dda6779693 Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Thu, 16 Sep 2021 19:16:49 +0800 Subject: [PATCH 14/26] Level 6 --- src/main/java/Duke.java | 78 ++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 29 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index f0416b8c3..3e8d7281f 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,5 +1,6 @@ import java.util.Scanner; import java.lang.String; +import java.util.ArrayList; public class Duke { @@ -11,18 +12,17 @@ public class Duke { public static final int AT_POS = 4; public static final int EVENT_POS = 6; - public static int numOfTasks = 0; - public static void main(String[] args) { greeting(); - Task[] tasks = new Task[MAX_NUM_OF_TASKS]; + ArrayList tasks = new ArrayList(); Scanner input = new Scanner(System.in); while (true) { String inputString = input.nextLine(); if (inputString.equals("bye")) { + saveDataToFile("tasks", tasks); exit(); break; } else if (inputString.equals("list")) { @@ -52,6 +52,8 @@ public static void main(String[] args) { + "☹ OOPS!!! The index is out of range.\n" + line); } + } else if (inputString.contains("delete") == true) { + deleteTask(inputString, tasks); } else { try { addTask(inputString, tasks); @@ -65,14 +67,15 @@ public static void main(String[] args) { } else if (inputString.contains("event")) { type = "event"; } - System.out.println(line - + "☹ OOPS!!! The description of a " + type + " cannot be empty.\n" - + line); - } - catch(NullPointerException n) { - System.out.println(line - + "☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n" - + line); + if (type == "") { + System.out.println(line + + "☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n" + + line); + } else { + System.out.println(line + + "☹ OOPS!!! The description of a " + type + " cannot be empty.\n" + + line); + } } } } @@ -98,22 +101,22 @@ public static final void exit() { + line); } - public static final void printList(Task[] tasks) throws DukeException{ - if (numOfTasks == 0) { + public static final void printList(ArrayList tasks) throws DukeException{ + if (tasks.size() == 0) { throw new DukeException("The list is empty!"); } else { System.out.println(line + "Here are the tasks in your list: "); - for (int index = 0; index < numOfTasks; index++) { + for (int index = 0; index < tasks.size(); index++) { System.out.println((index + 1) + ". " - + tasks[index].toString()); + + tasks.get(index).toString()); } System.out.println(line); } } - public static final void setDone(String input, Task[] tasks) { + public static final void setDone(String input, ArrayList tasks) { String num = ""; for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); @@ -123,34 +126,51 @@ public static final void setDone(String input, Task[] tasks) { } int index = Integer.parseInt(num); - tasks[index - 1].markedAsDone(); + tasks.get(index - 1).markedAsDone(); System.out.println(line + "Nice! I've marked this task as done: \n" - + tasks[index - 1] + "\n" + + tasks.get(index - 1) + "\n" + line); } - public static final void addTask(String input, Task[] tasks) throws NullPointerException { + public static final void addTask(String input, ArrayList tasks) throws NullPointerException { if (input.contains("todo") == true) { - tasks[numOfTasks] = new Todo(input.substring(TODO_POS)); + tasks.add(new Todo(input.substring(TODO_POS))); } else if (input.contains("deadline") == true) { String by = input.substring(input.indexOf("/") + BY_POS); - tasks[numOfTasks] = new Deadline(input.substring(DEADLINE_POS, - input.indexOf("/")), by); + tasks.add(new Deadline(input.substring(DEADLINE_POS, + input.indexOf("/")), by)); } else if (input.contains("event") == true) { String at = input.substring(input.indexOf("/") + AT_POS); - tasks[numOfTasks] = new Event(input.substring(EVENT_POS, - input.indexOf("/")), at); + tasks.add(new Event(input.substring(EVENT_POS, + input.indexOf("/")), at)); } else { - System.out.print(tasks[numOfTasks + 1].toString()); + System.out.print(tasks.get(tasks.size() + 1).toString()); } - numOfTasks++; System.out.println(line + "Got it. I've added this task: \n" - + tasks[numOfTasks - 1] + "\n" - + "Now you have " + numOfTasks + + tasks.get(tasks.size() - 1) + "\n" + + "Now you have " + tasks.size() + " tasks in the list\n" + line); } -} \ No newline at end of file + + public static final void deleteTask(String input, ArrayList tasks) { + String num = ""; + for (int i = 0; i < input.length(); i++) { + char c = input.charAt(i); + if (Character.isDigit(c) == true) { + num += c; + } + } + + int index = Integer.parseInt(num); + Task removedTask = tasks.get(index - 1); + tasks.remove(index - 1); + System.out.println(line + + "Noted. I've removed this task: \n" + + removedTask.toString() + + "\nNow you have " + tasks.size() + + " tasks in the list.\n" + line); + } From 8cfb82a6b883c181624416bac06f3c7bbcdd56d8 Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Thu, 16 Sep 2021 20:20:36 +0800 Subject: [PATCH 15/26] Level 7 --- src/main/java/Duke.java | 128 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 117 insertions(+), 11 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 3e8d7281f..d99a73bfb 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,6 +1,7 @@ import java.util.Scanner; import java.lang.String; import java.util.ArrayList; +import java.io.*; public class Duke { @@ -15,9 +16,16 @@ public class Duke { public static void main(String[] args) { greeting(); - ArrayList tasks = new ArrayList(); + if (getDatafromFile("tasks").size() > 0) { + tasks = getDatafromFile("tasks"); + System.out.println("Tasks have been loaded."); + } else { + System.out.println("No task can be loaded."); + } + + Scanner input = new Scanner(System.in); while (true) { String inputString = input.nextLine(); @@ -28,32 +36,40 @@ public static void main(String[] args) { } else if (inputString.equals("list")) { try { printList(tasks); - } - catch(DukeException d) { + } catch (DukeException d) { System.out.println(line + d.getMessage() + "\n" + line); } } else if (inputString.contains("done") == true) { try { setDone(inputString, tasks); - } - catch(IndexOutOfBoundsException i) { + } catch (IndexOutOfBoundsException i) { System.out.println(line - + "☹ OOPS!!! The index of done indstruction cannot be empty.\n" + + "☹ OOPS!!! The index is out of range.\n" + line); - } - catch(NumberFormatException n) { + } catch (NumberFormatException n) { System.out.println(line + "☹ OOPS!!! The index of done indstruction should be a number.\n" + line); + } catch (NullPointerException p) { + System.out.println(line + + "☹ OOPS!!! The index of done indstruction cannot be empty.\n" + + line); } - catch(NullPointerException p) { + } else if (inputString.contains("delete") == true) { + try { + deleteTask(inputString, tasks); + } catch (IndexOutOfBoundsException i) { System.out.println(line + "☹ OOPS!!! The index is out of range.\n" + line); + } catch (NumberFormatException n) { + System.out.println(line + + "☹ OOPS!!! The index of delete indstruction should be a number.\n" + + line); } - } else if (inputString.contains("delete") == true) { - deleteTask(inputString, tasks); + } else if (inputString.contains("clear") == true) { + clearList(tasks); } else { try { addTask(inputString, tasks); @@ -174,3 +190,93 @@ public static final void deleteTask(String input, ArrayList tasks) { + "\nNow you have " + tasks.size() + " tasks in the list.\n" + line); } + + public static final void clearList(ArrayList tasks) { + while (tasks.size() > 0) { + tasks.remove(0); + } + System.out.println(line + + "The list has been cleared. Now the list is empty.\n" + + line); + } + + public static final ArrayList getDatafromFile(String fileName) { + ArrayList tasks = new ArrayList(); + String Path="C:\\Users\\XUEY0013\\Documents\\ip\\src\\main\\" + fileName+ ".txt"; + BufferedReader reader = null; + try { + FileInputStream fileInputStream = new FileInputStream(Path); + InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); + reader = new BufferedReader(inputStreamReader); + String tempString = ""; + Task task = new Task("null"); + while ((tempString = reader.readLine()) != null) { + if (tempString.charAt(4) == 'T') { + task = (new Todo(tempString.substring(10))); + } else if (tempString.charAt(4) == 'E') { + String event = tempString.substring(10, + tempString.indexOf("(") - 1); + String at = tempString.substring(tempString.indexOf(":") + 2, + tempString.indexOf(")")); + task = (new Event(event, at)); + } else if (tempString.charAt(4) == 'D') { + String deadline = tempString.substring(10, + tempString.indexOf("(") - 1); + String by = tempString.substring(tempString.indexOf(":") + 2, + tempString.indexOf(")")); + task = (new Deadline(deadline, by)); + } + + if (tempString.charAt(7) == 'X') { + task.markedAsDone(); + } + + tasks.add(task); + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return tasks; + } + + public static final void saveDataToFile(String fileName,ArrayList tasks) { + BufferedWriter writer = null; + File file = new File("C:\\Users\\XUEY0013\\Documents\\ip\\src\\main\\"+ fileName + ".txt"); + if(!file.exists()){ + try { + file.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { + writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file,false), "UTF-8")); + for (Task task : tasks) { + int i = 0; + writer.write(i + 1 + ". " + task.toString()); + i++; + writer.write("\n"); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if(writer != null){ + writer.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + System.out.println("The list of tasks have been saved!"); + } +} \ No newline at end of file From e060cf4089f1a522c3a0f7658e755ee1b7437f00 Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Fri, 17 Sep 2021 21:57:41 +0800 Subject: [PATCH 16/26] Changes. --- 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 d99a73bfb..175110119 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -195,6 +195,7 @@ public static final void clearList(ArrayList tasks) { while (tasks.size() > 0) { tasks.remove(0); } + System.out.println(line + "The list has been cleared. Now the list is empty.\n" + line); From 0cf473f1715a3f21e4201841c47146d431976695 Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Fri, 17 Sep 2021 22:31:20 +0800 Subject: [PATCH 17/26] Changed level7 --- src/main/java/Duke.java | 33 ++++++++++++++++++-------------- src/main/java/DukeException.java | 2 +- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 175110119..5352fdb89 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -12,17 +12,18 @@ public class Duke { public static final int DEADLINE_POS = 9; public static final int AT_POS = 4; public static final int EVENT_POS = 6; + public static final int TYPE_POS = 4; + public static final int TASK_POS = 10; public static void main(String[] args) { greeting(); - ArrayList tasks = new ArrayList(); + ArrayList tasks = getDatafromFile("tasks"); - if (getDatafromFile("tasks").size() > 0) { - tasks = getDatafromFile("tasks"); - System.out.println("Tasks have been loaded."); + if (tasks.size() == 0) { + System.out.println("No tasks can be loaded."); } else { - System.out.println("No task can be loaded."); + System.out.println("Tasks have been loaded."); } @@ -203,25 +204,29 @@ public static final void clearList(ArrayList tasks) { public static final ArrayList getDatafromFile(String fileName) { ArrayList tasks = new ArrayList(); - String Path="C:\\Users\\XUEY0013\\Documents\\ip\\src\\main\\" + fileName+ ".txt"; + String path = "C:\\Users\\XUEY0013\\Documents\\ip\\src\\main\\" + fileName+ ".txt"; + File file = new File(path); + if (!file.exists()) { + return new ArrayList (); + } BufferedReader reader = null; try { - FileInputStream fileInputStream = new FileInputStream(Path); + FileInputStream fileInputStream = new FileInputStream(path); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); reader = new BufferedReader(inputStreamReader); String tempString = ""; Task task = new Task("null"); while ((tempString = reader.readLine()) != null) { - if (tempString.charAt(4) == 'T') { - task = (new Todo(tempString.substring(10))); - } else if (tempString.charAt(4) == 'E') { - String event = tempString.substring(10, + if (tempString.charAt(TYPE_POS) == 'T') { + task = (new Todo(tempString.substring(TASK_POS))); + } else if (tempString.charAt(TYPE_POS) == 'E') { + String event = tempString.substring(TASK_POS, tempString.indexOf("(") - 1); String at = tempString.substring(tempString.indexOf(":") + 2, tempString.indexOf(")")); task = (new Event(event, at)); - } else if (tempString.charAt(4) == 'D') { - String deadline = tempString.substring(10, + } else if (tempString.charAt(TYPE_POS) == 'D') { + String deadline = tempString.substring(TASK_POS, tempString.indexOf("(") - 1); String by = tempString.substring(tempString.indexOf(":") + 2, tempString.indexOf(")")); @@ -252,7 +257,7 @@ public static final ArrayList getDatafromFile(String fileName) { public static final void saveDataToFile(String fileName,ArrayList tasks) { BufferedWriter writer = null; File file = new File("C:\\Users\\XUEY0013\\Documents\\ip\\src\\main\\"+ fileName + ".txt"); - if(!file.exists()){ + if(!file.exists()) { try { file.createNewFile(); } catch (IOException e) { diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java index e3c50c477..3e1e3c056 100644 --- a/src/main/java/DukeException.java +++ b/src/main/java/DukeException.java @@ -7,5 +7,5 @@ public DukeException() { public DukeException(String message) { super(message); } - + } From b8d0935c9d9dcc84bcda58e9385d15f5611afd3e Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Fri, 17 Sep 2021 22:38:51 +0800 Subject: [PATCH 18/26] change --- 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 5352fdb89..0eb8775bb 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -216,6 +216,7 @@ public static final ArrayList getDatafromFile(String fileName) { reader = new BufferedReader(inputStreamReader); String tempString = ""; Task task = new Task("null"); + while ((tempString = reader.readLine()) != null) { if (tempString.charAt(TYPE_POS) == 'T') { task = (new Todo(tempString.substring(TASK_POS))); From d69ddd39c7fad35f997ff6a9c1bd6e93db23c2cb Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Wed, 22 Sep 2021 23:18:06 +0800 Subject: [PATCH 19/26] Level 9 --- src/main/java/Duke/Duke.java | 338 ++++++++++++++++++ .../DukeException/IndexMissingException.java | 12 + .../InvalidCommandException.java | 12 + src/main/java/Duke/Tasks/Deadline.java | 16 + src/main/java/Duke/Tasks/Event.java | 16 + src/main/java/Duke/Tasks/Task.java | 24 ++ src/main/java/Duke/Tasks/Todo.java | 15 + 7 files changed, 433 insertions(+) create mode 100644 src/main/java/Duke/Duke.java create mode 100644 src/main/java/Duke/DukeException/IndexMissingException.java create mode 100644 src/main/java/Duke/DukeException/InvalidCommandException.java create mode 100644 src/main/java/Duke/Tasks/Deadline.java create mode 100644 src/main/java/Duke/Tasks/Event.java create mode 100644 src/main/java/Duke/Tasks/Task.java create mode 100644 src/main/java/Duke/Tasks/Todo.java diff --git a/src/main/java/Duke/Duke.java b/src/main/java/Duke/Duke.java new file mode 100644 index 000000000..dfdccbf45 --- /dev/null +++ b/src/main/java/Duke/Duke.java @@ -0,0 +1,338 @@ +package Duke; + +import Duke.Tasks.Deadline; +import Duke.Tasks.Event; +import Duke.Tasks.Task; +import Duke.Tasks.Todo; +import Duke.DukeException.InvalidCommandException; +import Duke.DukeException.IndexMissingException; + +import java.time.LocalDate; +import java.io.*; +import java.util.ArrayList; +import java.util.Scanner; + +public class Duke { + + public static final String line = "____________________________________________________________\n"; + public static final String path = "..\\tasks.txt"; + public static final int MAX_NUM_OF_TASKS = 100; + public static final int TODO_POS = 5; + public static final int BY_POS = 4; + public static final int DEADLINE_POS = 9; + public static final int AT_POS = 4; + public static final int EVENT_POS = 6; + public static final int TYPE_POS = 4; + public static final int TASK_POS = 10; + + public static void main(String[] args) { + + greeting(); + ArrayList tasks = new ArrayList(); + + try { + tasks = getDatafromFile(); + } catch (FileNotFoundException f) { + System.out.println("No tasks can be loaded.\n"); + } + + Scanner input = new Scanner(System.in); + while (true) { + String inputString = input.nextLine(); + String findCommand = inputString.split(" ")[0]; + + if (inputString.trim().equals("bye")) { + saveDataToFile("tasks", tasks); + exit(); + break; + } else if (inputString.trim().equals("list")) { + try { + if (tasks.size() > 0) { + System.out.println(line + + "Here are the tasks in your list: "); + } + printList(tasks); + System.out.println(line); + } catch (IndexOutOfBoundsException i) { + System.out.print(line + + "The list is empty.\n" + + line); + } + } else if (findCommand.contains("done") == true) { + try { + setDone(inputString, tasks); + } catch (IndexOutOfBoundsException i) { + System.out.println(line + + "OOPS!!! The index is out of range.\n" + + line); + } catch (NumberFormatException n) { + System.out.println(line + + "OOPS!!! The index of done indstruction should be a number.\n" + + line); + } catch (IndexMissingException m) { + m.printMessage(); + } + } else if (findCommand.contains("delete") == true) { + try { + deleteTask(inputString, tasks); + } catch (IndexOutOfBoundsException i) { + System.out.println(line + + "OOPS!!! The index is out of range.\n" + + line); + } catch (NumberFormatException n) { + System.out.println(line + + "OOPS!!! The index of delete indstruction should be a number.\n" + + line); + } + } else if (inputString.trim().equals("clear") == true) { + clearList(tasks); + } else if (findCommand.contains("find") == true) { + try { + findTask(inputString, tasks); + } catch (IndexOutOfBoundsException i) { + System.out.println(line + + "Sorry, please tell me which task you want to find?\n" + + line); + } + } else { + try { + addTask(inputString, tasks); + } catch (InvalidCommandException c) { + c.printMessage(); + } catch(IndexOutOfBoundsException i) { + String type = ""; + if (inputString.contains("todo")) { + type = "todo"; + } else if (inputString.contains("deadline")) { + type = "deadline"; + } else if (inputString.contains("event")) { + type = "event"; + } + System.out.println(line + + "OOPS!!! The description of a " + type + " cannot be empty.\n" + + line); + } + } + } + } + + public static final void greeting() { + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + System.out.println("Hello from\n" + logo); + + System.out.println(line + + "Hello! I'm Duke\n" + + "What can I do for you?\n" + + line); + } + + public static final void exit() { + System.out.println(line + + "Bye. Hope to see you again soon!\n" + + line); + } + + public static final void printList(ArrayList tasks) { + if (tasks.size() == 0) { + Task temp = tasks.get(0); + } else { + for (int index = 0; index < tasks.size(); index++) { + System.out.println((index + 1) + ". " + + tasks.get(index).toString()); + } + } + } + + public static final void setDone(String input, ArrayList tasks) throws IndexMissingException { + String num = ""; + for (int i = 0; i < input.length(); i++) { + char c = input.charAt(i); + if (Character.isDigit(c) == true) { + num += c; + } + } + if (input.trim().equals("done")) { + throw new IndexMissingException(); + } + + int index = Integer.parseInt(num); + tasks.get(index - 1).markedAsDone(); + System.out.println(line + + "Nice! I've marked this task as done: \n" + + tasks.get(index - 1) + "\n" + + line); + } + + public static final void addTask(String input, ArrayList tasks) throws InvalidCommandException { + if (input.contains("todo") == true) { + tasks.add(new Todo(input.substring(TODO_POS))); + } else if (input.contains("deadline") == true) { + String by = input.substring(input.indexOf("/") + BY_POS); + tasks.add(new Deadline(input.substring(DEADLINE_POS, + input.indexOf("/")), by)); + } else if (input.contains("event") == true) { + String at = input.substring(input.indexOf("/") + AT_POS); + tasks.add(new Event(input.substring(EVENT_POS, + input.indexOf("/")), at)); + } else { + try { + System.out.print(tasks.get(tasks.size() + 1).toString()); + } catch (IndexOutOfBoundsException i) { + throw new InvalidCommandException(); + } + } + + System.out.println(line + + "Got it. I've added this task: \n" + + tasks.get(tasks.size() - 1) + "\n" + + "Now you have " + tasks.size() + + " tasks in the list\n" + + line); + } + + public static final void deleteTask(String input, ArrayList tasks) { + String num = ""; + for (int i = 0; i < input.length(); i++) { + char c = input.charAt(i); + if (Character.isDigit(c) == true) { + num += c; + } + + } + + int index = Integer.parseInt(num); + Task removedTask = tasks.get(index - 1); + tasks.remove(index - 1); + System.out.println(line + + "Noted. I've removed this task: \n" + + removedTask.toString() + + "\nNow you have " + tasks.size() + + " tasks in the list.\n" + line); + } + + public static final void clearList(ArrayList tasks) { + while (tasks.size() > 0) { + tasks.remove(0); + } + + System.out.println(line + + "The list has been cleared. Now the list is empty.\n" + + line); + } + + public static final void findTask(String input, ArrayList tasks) { + boolean found = false; + ArrayList foundTasks = new ArrayList(); + for (Task task : tasks) { + String target = input.substring(5); + if (task.getDescription().contains(target) == true) { + foundTasks.add(task); + found = true; + } + } + + if (!found) { + System.out.println(line + + "Sorry, I cannot find any matching task in your list.\n" + + line); + } else { + System.out.println(line + + "Here are the matching tasks in your list:"); + printList(foundTasks); + System.out.println(line); + } + } + + public static final ArrayList getDatafromFile() throws FileNotFoundException { + ArrayList tasks = new ArrayList(); + File file = new File(path); + if (!file.exists()) { + throw new FileNotFoundException(); + } + BufferedReader reader = null; + try { + FileInputStream fileInputStream = new FileInputStream(path); + InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); + reader = new BufferedReader(inputStreamReader); + String tempString = ""; + Task task = new Task("null"); + + while ((tempString = reader.readLine()) != null) { + if (tempString.charAt(TYPE_POS) == 'T') { + task = (new Todo(tempString.substring(TASK_POS))); + } else if (tempString.charAt(TYPE_POS) == 'E') { + String event = tempString.substring(TASK_POS, + tempString.indexOf("(") - 1); + String at = tempString.substring(tempString.indexOf(":") + 2, + tempString.indexOf(")")); + task = (new Event(event, at)); + } else if (tempString.charAt(TYPE_POS) == 'D') { + String deadline = tempString.substring(TASK_POS, + tempString.indexOf("(") - 1); + String by = tempString.substring(tempString.indexOf(":") + 2, + tempString.indexOf(")")); + task = (new Deadline(deadline, by)); + } + + if (tempString.charAt(7) == 'X') { + task.markedAsDone(); + } + + tasks.add(task); + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + if (tasks.size() > 0) { + System.out.println("Tasks have been loaded.\n" + line); + } else { + System.out.println("The current list is empty.\n" + line); + } + return tasks; + } + + public static final void saveDataToFile(String fileName, ArrayList tasks) { + BufferedWriter writer = null; + File file = new File("..\\"+ fileName + ".txt"); + if(!file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { + writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file,false), "UTF-8")); + for (Task task : tasks) { + int i = 0; + writer.write(i + 1 + ". " + task.toString()); + i++; + writer.write("\n"); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if(writer != null){ + writer.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + System.out.println("The list of tasks have been saved!"); + } +} \ No newline at end of file diff --git a/src/main/java/Duke/DukeException/IndexMissingException.java b/src/main/java/Duke/DukeException/IndexMissingException.java new file mode 100644 index 000000000..03c971b97 --- /dev/null +++ b/src/main/java/Duke/DukeException/IndexMissingException.java @@ -0,0 +1,12 @@ +package Duke.DukeException; + +public class IndexMissingException extends Exception { + public static final String line = "____________________________________________________________\n"; + public static final String message = line + + "Please tell me the index for the operation.:-(\n" + + line; + + public final void printMessage() { + System.out.println(this.message); + } +} diff --git a/src/main/java/Duke/DukeException/InvalidCommandException.java b/src/main/java/Duke/DukeException/InvalidCommandException.java new file mode 100644 index 000000000..8b5a2802d --- /dev/null +++ b/src/main/java/Duke/DukeException/InvalidCommandException.java @@ -0,0 +1,12 @@ +package Duke.DukeException; + +public class InvalidCommandException extends Exception { + public static final String line = "____________________________________________________________\n"; + public static final String message = line + + "OOPS!!! I'm sorry, but I don't know what that means :-(\n" + + "Please give me a valid command.\n" + line; + + public final void printMessage() { + System.out.println(this.message); + } +} diff --git a/src/main/java/Duke/Tasks/Deadline.java b/src/main/java/Duke/Tasks/Deadline.java new file mode 100644 index 000000000..b214a7709 --- /dev/null +++ b/src/main/java/Duke/Tasks/Deadline.java @@ -0,0 +1,16 @@ +package Duke.Tasks; + +public class Deadline extends Task { + public String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + @Override + public String toString() { + return "[D]" + super.toString() + " (by: " + this.by + + ")"; + } +} diff --git a/src/main/java/Duke/Tasks/Event.java b/src/main/java/Duke/Tasks/Event.java new file mode 100644 index 000000000..2949e16d4 --- /dev/null +++ b/src/main/java/Duke/Tasks/Event.java @@ -0,0 +1,16 @@ +package Duke.Tasks; + +public class Event extends Task { + public String at; + + public Event(String description, String at) { + super(description); + this.at = at; + } + + @Override + public String toString() { + return "[E]" + super.toString() + " (at: " + this.at + + ")"; + } +} diff --git a/src/main/java/Duke/Tasks/Task.java b/src/main/java/Duke/Tasks/Task.java new file mode 100644 index 000000000..c986f653d --- /dev/null +++ b/src/main/java/Duke/Tasks/Task.java @@ -0,0 +1,24 @@ +package Duke.Tasks; + +public class Task { + protected String description; + protected String isDone; + + public Task(String description) { + this.description = description; + this.isDone = " "; + } + + public final String getDescription() { + return this.description; + } + public final void markedAsDone() { + this.isDone = "X"; + } + + @Override + public String toString() { + String status; + return "[" + isDone + "] " + this.description; + } +} diff --git a/src/main/java/Duke/Tasks/Todo.java b/src/main/java/Duke/Tasks/Todo.java new file mode 100644 index 000000000..9bd0934df --- /dev/null +++ b/src/main/java/Duke/Tasks/Todo.java @@ -0,0 +1,15 @@ +package Duke.Tasks; + +import Duke.Tasks.Task; + +public class Todo extends Task { + + public Todo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} From 97a99f5b7e17c638865006db1a6800eca47cd6f2 Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Wed, 22 Sep 2021 23:22:19 +0800 Subject: [PATCH 20/26] Find --- src/main/java/Duke/Duke.java | 1 + src/main/java/Duke/Tasks/Task.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/Duke/Duke.java b/src/main/java/Duke/Duke.java index dfdccbf45..b8b261345 100644 --- a/src/main/java/Duke/Duke.java +++ b/src/main/java/Duke/Duke.java @@ -227,6 +227,7 @@ public static final void clearList(ArrayList tasks) { public static final void findTask(String input, ArrayList tasks) { boolean found = false; ArrayList foundTasks = new ArrayList(); + for (Task task : tasks) { String target = input.substring(5); if (task.getDescription().contains(target) == true) { diff --git a/src/main/java/Duke/Tasks/Task.java b/src/main/java/Duke/Tasks/Task.java index c986f653d..bd056750a 100644 --- a/src/main/java/Duke/Tasks/Task.java +++ b/src/main/java/Duke/Tasks/Task.java @@ -12,6 +12,7 @@ public Task(String description) { public final String getDescription() { return this.description; } + public final void markedAsDone() { this.isDone = "X"; } From 3516ed4933b3b1eedf0ed6d3f67dd81ee30353f7 Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Tue, 28 Sep 2021 14:41:24 +0800 Subject: [PATCH 21/26] More OOP --- .../java/Duke/Command/AddDeadlineCommand.java | 30 ++ .../java/Duke/Command/AddEventCommand.java | 30 ++ .../java/Duke/Command/AddTodoCommand.java | 28 ++ src/main/java/Duke/Command/ClearCommand.java | 19 + src/main/java/Duke/Command/Command.java | 14 + src/main/java/Duke/Command/DeleteCommand.java | 29 ++ src/main/java/Duke/Command/DoneCommand.java | 25 ++ src/main/java/Duke/Command/ExitCommand.java | 22 ++ src/main/java/Duke/Command/FindCommand.java | 33 ++ src/main/java/Duke/Duke.java | 354 ++---------------- 10 files changed, 261 insertions(+), 323 deletions(-) create mode 100644 src/main/java/Duke/Command/AddDeadlineCommand.java create mode 100644 src/main/java/Duke/Command/AddEventCommand.java create mode 100644 src/main/java/Duke/Command/AddTodoCommand.java create mode 100644 src/main/java/Duke/Command/ClearCommand.java create mode 100644 src/main/java/Duke/Command/Command.java create mode 100644 src/main/java/Duke/Command/DeleteCommand.java create mode 100644 src/main/java/Duke/Command/DoneCommand.java create mode 100644 src/main/java/Duke/Command/ExitCommand.java create mode 100644 src/main/java/Duke/Command/FindCommand.java diff --git a/src/main/java/Duke/Command/AddDeadlineCommand.java b/src/main/java/Duke/Command/AddDeadlineCommand.java new file mode 100644 index 000000000..0ddbac531 --- /dev/null +++ b/src/main/java/Duke/Command/AddDeadlineCommand.java @@ -0,0 +1,30 @@ +package Duke.Command; + +import Duke.Ui.Ui; +import Duke.Storage.Storage; +import Duke.Tasks.TaskList; +import Duke.Tasks.Deadline; + +public class AddDeadlineCommand extends Command { + private final String description; + private final String by; + + public static final String COMMAND_WORD = "deadline"; + public static final String COMMAND_DESCRIPTION = COMMAND_WORD + + ": add a deadline task to the current list.\n" + + " Parameters: DESCRIPTION, BY_TIME\n" + + " Example: " + COMMAND_WORD + " take the quiz /by Tuesday"; + + public AddDeadlineCommand(String description, String by) { + this.description = description; + this.by = by; + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + ui.printAddTaskMessage(new Deadline(this.description, this.by)); + tasks.addDeadline(this.description, this.by); + ui.printNumOfTasks(tasks); + storage.save(tasks.getTasks()); + } +} diff --git a/src/main/java/Duke/Command/AddEventCommand.java b/src/main/java/Duke/Command/AddEventCommand.java new file mode 100644 index 000000000..33c30e749 --- /dev/null +++ b/src/main/java/Duke/Command/AddEventCommand.java @@ -0,0 +1,30 @@ +package Duke.Command; + +import Duke.Ui.Ui; +import Duke.Storage.Storage; +import Duke.Tasks.TaskList; +import Duke.Tasks.Event; + +public class AddEventCommand extends Command { + private final String description; + private final String at; + + public static final String COMMAND_WORD = "event"; + public static final String COMMAND_DESCRIPTION = COMMAND_WORD + + ": add an event task to the current list.\n" + + " Parameters: DESCRIPTION, AT_TIME\n" + + " Example: " + COMMAND_WORD + "attend CS2113 lecture /at Dec 4"; + + public AddEventCommand(String description, String at) { + this.description = description; + this.at = at; + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + ui.printAddTaskMessage(new Event(this.description, this.at)); + tasks.addEvent(this.description, this.at); + ui.printNumOfTasks(tasks); + storage.save(tasks.getTasks()); + } +} diff --git a/src/main/java/Duke/Command/AddTodoCommand.java b/src/main/java/Duke/Command/AddTodoCommand.java new file mode 100644 index 000000000..d3388f411 --- /dev/null +++ b/src/main/java/Duke/Command/AddTodoCommand.java @@ -0,0 +1,28 @@ +package Duke.Command; + +import Duke.Ui.Ui; +import Duke.Storage.Storage; +import Duke.Tasks.TaskList; +import Duke.Tasks.Todo; + +public class AddTodoCommand extends Command { + private final String description; + + public static final String COMMAND_WORD = "todo"; + public static final String COMMAND_DESCRIPTION = COMMAND_WORD + + ": add a todo task to the current list.\n" + + " Parameters: DESCRIPTION\n" + + " Example: " + COMMAND_WORD + " complete the assessment"; + + public AddTodoCommand(String description) { + this.description = description; + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + ui.printAddTaskMessage(new Todo(this.description)); + tasks.addTodo(this.description); + ui.printNumOfTasks(tasks); + storage.save(tasks.getTasks()); + } +} diff --git a/src/main/java/Duke/Command/ClearCommand.java b/src/main/java/Duke/Command/ClearCommand.java new file mode 100644 index 000000000..1d8897477 --- /dev/null +++ b/src/main/java/Duke/Command/ClearCommand.java @@ -0,0 +1,19 @@ +package Duke.Command; + +import Duke.Ui.Ui; +import Duke.Storage.Storage; +import Duke.Tasks.TaskList; + +public class ClearCommand extends Command { + public static final String COMMAND_WORD = "clear"; + public static final String COMMAND_DESCRIPTION = COMMAND_WORD + + ": clear all tasks in the current list.\n" + + " Example: " + COMMAND_WORD; + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + ui.printClearMessage(); + tasks.clearTasks(); + storage.save(tasks.getTasks()); + } +} diff --git a/src/main/java/Duke/Command/Command.java b/src/main/java/Duke/Command/Command.java new file mode 100644 index 000000000..1fb86a45e --- /dev/null +++ b/src/main/java/Duke/Command/Command.java @@ -0,0 +1,14 @@ +package Duke.Command; + +import Duke.Storage.Storage; +import Duke.Tasks.TaskList; +import Duke.Ui.Ui; +import Duke.DukeException.DukeException; + +public abstract class Command { + public abstract void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException; + + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/Duke/Command/DeleteCommand.java b/src/main/java/Duke/Command/DeleteCommand.java new file mode 100644 index 000000000..881b2fd62 --- /dev/null +++ b/src/main/java/Duke/Command/DeleteCommand.java @@ -0,0 +1,29 @@ +package Duke.Command; + +import Duke.Storage.Storage; +import Duke.Ui.Ui; +import Duke.Tasks.TaskList; +import Duke.DukeException.DukeException; + +public class DeleteCommand extends Command { + public static final String COMMAND_WORD = "delete"; + + public static final String COMMAND_DESCRIPTION = COMMAND_WORD + + ": Delete the task identified by the index number used in the current list.\n" + + " Parameters: INDEX\n" + + " Example: " + COMMAND_WORD + " 1"; + + private final int index; + + public DeleteCommand(int index) { + this.index = index; + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException { + tasks.deleteTask(this.index); + ui.printDeleteMessage(); + ui.printNumOfTasks(tasks); + storage.save(tasks.getTasks()); + } +} diff --git a/src/main/java/Duke/Command/DoneCommand.java b/src/main/java/Duke/Command/DoneCommand.java new file mode 100644 index 000000000..d19cf4dd4 --- /dev/null +++ b/src/main/java/Duke/Command/DoneCommand.java @@ -0,0 +1,25 @@ +package Duke.Command; + +import Duke.Storage.Storage; +import Duke.Ui.Ui; +import Duke.Tasks.TaskList; +import Duke.DukeException.DukeException; + +public class DoneCommand extends Command { + private final int index; + public static final String COMMAND_WORD = "done"; + public static final String COMMAND_DESCRIPTION = COMMAND_WORD + + ": mark a task in the list as done.\n" + + " Parameters: INDEX\n" + + " Example: " + COMMAND_WORD + " 1"; + + public DoneCommand(int index) { + this.index = index; + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException { + ui.printDoneMessage(tasks.setDone(this.index)); + storage.save(tasks.getTasks()); + } +} diff --git a/src/main/java/Duke/Command/ExitCommand.java b/src/main/java/Duke/Command/ExitCommand.java new file mode 100644 index 000000000..afd864c21 --- /dev/null +++ b/src/main/java/Duke/Command/ExitCommand.java @@ -0,0 +1,22 @@ +package Duke.Command; + +import Duke.Storage.Storage; +import Duke.Ui.Ui; +import Duke.Tasks.TaskList; + +public class ExitCommand extends Command { + public static final String COMMAND_WORD = "bye"; + public static final String COMMAND_DESCRIPTION = COMMAND_WORD + + ": exit the programme.\n" + + " Example: " + COMMAND_WORD; + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + ui.showByeMessage(); + } + + @Override + public boolean isExit() { + return true; + } +} diff --git a/src/main/java/Duke/Command/FindCommand.java b/src/main/java/Duke/Command/FindCommand.java new file mode 100644 index 000000000..837292dc9 --- /dev/null +++ b/src/main/java/Duke/Command/FindCommand.java @@ -0,0 +1,33 @@ +package Duke.Command; + +import Duke.Storage.Storage; +import Duke.Ui.Ui; +import Duke.Tasks.Task; +import Duke.Tasks.TaskList; + +public class FindCommand extends Command { + public static final String COMMAND_WORD = "find"; + + public static final String COMMAND_DESCRIPTION = COMMAND_WORD + + ": find a task in the list by key word.\n" + + " Parameters: DESCRIPTION\n" + + " Example: " + COMMAND_WORD + " read"; + + private final String target; + + public FindCommand(String target) { + this.target = target; + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + if (tasks.find(this.target).size() == 0) { + ui.printNoMatchingTaskMessage(); + } else { + ui.printFindMessage(); + for (Task task : tasks.find(this.target)) { + System.out.println(task.toString()); + } + } + } +} diff --git a/src/main/java/Duke/Duke.java b/src/main/java/Duke/Duke.java index b8b261345..d29b52605 100644 --- a/src/main/java/Duke/Duke.java +++ b/src/main/java/Duke/Duke.java @@ -1,339 +1,47 @@ package Duke; -import Duke.Tasks.Deadline; -import Duke.Tasks.Event; -import Duke.Tasks.Task; -import Duke.Tasks.Todo; -import Duke.DukeException.InvalidCommandException; -import Duke.DukeException.IndexMissingException; - -import java.time.LocalDate; -import java.io.*; -import java.util.ArrayList; -import java.util.Scanner; +import Duke.Parser.Parser; +import Duke.DukeException.DukeException; +import Duke.Command.*; +import Duke.Storage.Storage; +import Duke.Tasks.TaskList; +import Duke.Ui.Ui; public class Duke { + private Storage storage; + private TaskList tasks; + private Ui ui; - public static final String line = "____________________________________________________________\n"; - public static final String path = "..\\tasks.txt"; - public static final int MAX_NUM_OF_TASKS = 100; - public static final int TODO_POS = 5; - public static final int BY_POS = 4; - public static final int DEADLINE_POS = 9; - public static final int AT_POS = 4; - public static final int EVENT_POS = 6; - public static final int TYPE_POS = 4; - public static final int TASK_POS = 10; - - public static void main(String[] args) { - - greeting(); - ArrayList tasks = new ArrayList(); - + public Duke(String filePath) { + ui = new Ui(); + storage = new Storage(filePath); try { - tasks = getDatafromFile(); - } catch (FileNotFoundException f) { - System.out.println("No tasks can be loaded.\n"); - } - - Scanner input = new Scanner(System.in); - while (true) { - String inputString = input.nextLine(); - String findCommand = inputString.split(" ")[0]; - - if (inputString.trim().equals("bye")) { - saveDataToFile("tasks", tasks); - exit(); - break; - } else if (inputString.trim().equals("list")) { - try { - if (tasks.size() > 0) { - System.out.println(line - + "Here are the tasks in your list: "); - } - printList(tasks); - System.out.println(line); - } catch (IndexOutOfBoundsException i) { - System.out.print(line - + "The list is empty.\n" - + line); - } - } else if (findCommand.contains("done") == true) { - try { - setDone(inputString, tasks); - } catch (IndexOutOfBoundsException i) { - System.out.println(line - + "OOPS!!! The index is out of range.\n" - + line); - } catch (NumberFormatException n) { - System.out.println(line - + "OOPS!!! The index of done indstruction should be a number.\n" - + line); - } catch (IndexMissingException m) { - m.printMessage(); - } - } else if (findCommand.contains("delete") == true) { - try { - deleteTask(inputString, tasks); - } catch (IndexOutOfBoundsException i) { - System.out.println(line - + "OOPS!!! The index is out of range.\n" - + line); - } catch (NumberFormatException n) { - System.out.println(line - + "OOPS!!! The index of delete indstruction should be a number.\n" - + line); - } - } else if (inputString.trim().equals("clear") == true) { - clearList(tasks); - } else if (findCommand.contains("find") == true) { - try { - findTask(inputString, tasks); - } catch (IndexOutOfBoundsException i) { - System.out.println(line - + "Sorry, please tell me which task you want to find?\n" - + line); - } - } else { - try { - addTask(inputString, tasks); - } catch (InvalidCommandException c) { - c.printMessage(); - } catch(IndexOutOfBoundsException i) { - String type = ""; - if (inputString.contains("todo")) { - type = "todo"; - } else if (inputString.contains("deadline")) { - type = "deadline"; - } else if (inputString.contains("event")) { - type = "event"; - } - System.out.println(line - + "OOPS!!! The description of a " + type + " cannot be empty.\n" - + line); - } - } - } - } - - public static final void greeting() { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - - System.out.println(line - + "Hello! I'm Duke\n" - + "What can I do for you?\n" - + line); - } - - public static final void exit() { - System.out.println(line - + "Bye. Hope to see you again soon!\n" - + line); - } - - public static final void printList(ArrayList tasks) { - if (tasks.size() == 0) { - Task temp = tasks.get(0); - } else { - for (int index = 0; index < tasks.size(); index++) { - System.out.println((index + 1) + ". " - + tasks.get(index).toString()); - } - } - } - - public static final void setDone(String input, ArrayList tasks) throws IndexMissingException { - String num = ""; - for (int i = 0; i < input.length(); i++) { - char c = input.charAt(i); - if (Character.isDigit(c) == true) { - num += c; - } + tasks = new TaskList(storage.load()); + } catch (DukeException e) { + ui.showLoadingError(); + tasks = new TaskList(); } - if (input.trim().equals("done")) { - throw new IndexMissingException(); - } - - int index = Integer.parseInt(num); - tasks.get(index - 1).markedAsDone(); - System.out.println(line - + "Nice! I've marked this task as done: \n" - + tasks.get(index - 1) + "\n" - + line); } - public static final void addTask(String input, ArrayList tasks) throws InvalidCommandException { - if (input.contains("todo") == true) { - tasks.add(new Todo(input.substring(TODO_POS))); - } else if (input.contains("deadline") == true) { - String by = input.substring(input.indexOf("/") + BY_POS); - tasks.add(new Deadline(input.substring(DEADLINE_POS, - input.indexOf("/")), by)); - } else if (input.contains("event") == true) { - String at = input.substring(input.indexOf("/") + AT_POS); - tasks.add(new Event(input.substring(EVENT_POS, - input.indexOf("/")), at)); - } else { + public void run() { + ui.showWelcome(); + boolean isExit = false; + while (!isExit) { try { - System.out.print(tasks.get(tasks.size() + 1).toString()); - } catch (IndexOutOfBoundsException i) { - throw new InvalidCommandException(); - } - } - - System.out.println(line - + "Got it. I've added this task: \n" - + tasks.get(tasks.size() - 1) + "\n" - + "Now you have " + tasks.size() - + " tasks in the list\n" - + line); - } - - public static final void deleteTask(String input, ArrayList tasks) { - String num = ""; - for (int i = 0; i < input.length(); i++) { - char c = input.charAt(i); - if (Character.isDigit(c) == true) { - num += c; - } - - } - - int index = Integer.parseInt(num); - Task removedTask = tasks.get(index - 1); - tasks.remove(index - 1); - System.out.println(line - + "Noted. I've removed this task: \n" - + removedTask.toString() - + "\nNow you have " + tasks.size() - + " tasks in the list.\n" + line); - } - - public static final void clearList(ArrayList tasks) { - while (tasks.size() > 0) { - tasks.remove(0); - } - - System.out.println(line - + "The list has been cleared. Now the list is empty.\n" - + line); - } - - public static final void findTask(String input, ArrayList tasks) { - boolean found = false; - ArrayList foundTasks = new ArrayList(); - - for (Task task : tasks) { - String target = input.substring(5); - if (task.getDescription().contains(target) == true) { - foundTasks.add(task); - found = true; - } - } - - if (!found) { - System.out.println(line - + "Sorry, I cannot find any matching task in your list.\n" - + line); - } else { - System.out.println(line - + "Here are the matching tasks in your list:"); - printList(foundTasks); - System.out.println(line); - } - } - - public static final ArrayList getDatafromFile() throws FileNotFoundException { - ArrayList tasks = new ArrayList(); - File file = new File(path); - if (!file.exists()) { - throw new FileNotFoundException(); - } - BufferedReader reader = null; - try { - FileInputStream fileInputStream = new FileInputStream(path); - InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); - reader = new BufferedReader(inputStreamReader); - String tempString = ""; - Task task = new Task("null"); - - while ((tempString = reader.readLine()) != null) { - if (tempString.charAt(TYPE_POS) == 'T') { - task = (new Todo(tempString.substring(TASK_POS))); - } else if (tempString.charAt(TYPE_POS) == 'E') { - String event = tempString.substring(TASK_POS, - tempString.indexOf("(") - 1); - String at = tempString.substring(tempString.indexOf(":") + 2, - tempString.indexOf(")")); - task = (new Event(event, at)); - } else if (tempString.charAt(TYPE_POS) == 'D') { - String deadline = tempString.substring(TASK_POS, - tempString.indexOf("(") - 1); - String by = tempString.substring(tempString.indexOf(":") + 2, - tempString.indexOf(")")); - task = (new Deadline(deadline, by)); - } - - if (tempString.charAt(7) == 'X') { - task.markedAsDone(); - } - - tasks.add(task); + String fullCommand = ui.readCommand(); + ui.showLine(); + Command c = Parser.parse(fullCommand); + c.execute(tasks, ui, storage); + isExit = c.isExit(); + } catch (DukeException e) { + ui.showError(e.getMessage()); + } finally { + ui.showLine(); } - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - if (tasks.size() > 0) { - System.out.println("Tasks have been loaded.\n" + line); - } else { - System.out.println("The current list is empty.\n" + line); } - return tasks; } - public static final void saveDataToFile(String fileName, ArrayList tasks) { - BufferedWriter writer = null; - File file = new File("..\\"+ fileName + ".txt"); - if(!file.exists()) { - try { - file.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } - } - try { - writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file,false), "UTF-8")); - for (Task task : tasks) { - int i = 0; - writer.write(i + 1 + ". " + task.toString()); - i++; - writer.write("\n"); - } - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - if(writer != null){ - writer.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - System.out.println("The list of tasks have been saved!"); + public static void main(String[] args) { + new Duke(".\\tasks.txt").run(); } } \ No newline at end of file From 0d92829728249a480654c2080823ad89eb5e614b Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Wed, 29 Sep 2021 14:46:50 +0800 Subject: [PATCH 22/26] More OOP final version --- src/main/java/Duke.java | 312 ++---------------- src/main/java/Duke/Command/HelpCommand.java | 17 + .../java/Duke/Command/InvalidCommand.java | 16 + src/main/java/Duke/Command/ListCommand.java | 22 ++ .../Duke/DukeException/DukeException.java | 14 + src/main/java/Duke/Parser/Parser.java | 135 ++++++++ src/main/java/Duke/Storage/Storage.java | 112 +++++++ src/main/java/Duke/Tasks/TaskList.java | 84 +++++ src/main/java/Duke/Ui/Ui.java | 110 ++++++ src/main/tasks.txt | 1 + 10 files changed, 546 insertions(+), 277 deletions(-) create mode 100644 src/main/java/Duke/Command/HelpCommand.java create mode 100644 src/main/java/Duke/Command/InvalidCommand.java create mode 100644 src/main/java/Duke/Command/ListCommand.java create mode 100644 src/main/java/Duke/DukeException/DukeException.java create mode 100644 src/main/java/Duke/Parser/Parser.java create mode 100644 src/main/java/Duke/Storage/Storage.java create mode 100644 src/main/java/Duke/Tasks/TaskList.java create mode 100644 src/main/java/Duke/Ui/Ui.java create mode 100644 src/main/tasks.txt diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 0eb8775bb..d29b52605 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,289 +1,47 @@ -import java.util.Scanner; -import java.lang.String; -import java.util.ArrayList; -import java.io.*; +package Duke; -public class Duke { - - public static final String line = "____________________________________________________________\n"; - public static final int MAX_NUM_OF_TASKS = 100; - public static final int TODO_POS = 5; - public static final int BY_POS = 4; - public static final int DEADLINE_POS = 9; - public static final int AT_POS = 4; - public static final int EVENT_POS = 6; - public static final int TYPE_POS = 4; - public static final int TASK_POS = 10; - - public static void main(String[] args) { - - greeting(); - ArrayList tasks = getDatafromFile("tasks"); - - if (tasks.size() == 0) { - System.out.println("No tasks can be loaded."); - } else { - System.out.println("Tasks have been loaded."); - } - - - Scanner input = new Scanner(System.in); - while (true) { - String inputString = input.nextLine(); - if (inputString.equals("bye")) { - saveDataToFile("tasks", tasks); - exit(); - break; - } else if (inputString.equals("list")) { - try { - printList(tasks); - } catch (DukeException d) { - System.out.println(line - + d.getMessage() + "\n" + line); - } - } else if (inputString.contains("done") == true) { - try { - setDone(inputString, tasks); - } catch (IndexOutOfBoundsException i) { - System.out.println(line - + "☹ OOPS!!! The index is out of range.\n" - + line); - } catch (NumberFormatException n) { - System.out.println(line - + "☹ OOPS!!! The index of done indstruction should be a number.\n" - + line); - } catch (NullPointerException p) { - System.out.println(line - + "☹ OOPS!!! The index of done indstruction cannot be empty.\n" - + line); - } - } else if (inputString.contains("delete") == true) { - try { - deleteTask(inputString, tasks); - } catch (IndexOutOfBoundsException i) { - System.out.println(line - + "☹ OOPS!!! The index is out of range.\n" - + line); - } catch (NumberFormatException n) { - System.out.println(line - + "☹ OOPS!!! The index of delete indstruction should be a number.\n" - + line); - } - } else if (inputString.contains("clear") == true) { - clearList(tasks); - } else { - try { - addTask(inputString, tasks); - } - catch(IndexOutOfBoundsException i) { - String type = ""; - if (inputString.contains("todo")) { - type = "todo"; - } else if (inputString.contains("deadline")) { - type = "deadline"; - } else if (inputString.contains("event")) { - type = "event"; - } - if (type == "") { - System.out.println(line - + "☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n" - + line); - } else { - System.out.println(line - + "☹ OOPS!!! The description of a " + type + " cannot be empty.\n" - + line); - } - } - } - } - } - - public static final void greeting() { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - - System.out.println(line - + "Hello! I'm Duke\n" - + "What can I do for you?\n" - + line); - } - - public static final void exit() { - System.out.println(line - + "Bye. Hope to see you again soon!\n" - + line); - } - - public static final void printList(ArrayList tasks) throws DukeException{ - if (tasks.size() == 0) { - throw new DukeException("The list is empty!"); - } else { - System.out.println(line - + "Here are the tasks in your list: "); - - for (int index = 0; index < tasks.size(); index++) { - System.out.println((index + 1) + ". " - + tasks.get(index).toString()); - } - System.out.println(line); - } - } - - public static final void setDone(String input, ArrayList tasks) { - String num = ""; - for (int i = 0; i < input.length(); i++) { - char c = input.charAt(i); - if (Character.isDigit(c) == true) { - num += c; - } - } - - int index = Integer.parseInt(num); - tasks.get(index - 1).markedAsDone(); - System.out.println(line - + "Nice! I've marked this task as done: \n" - + tasks.get(index - 1) + "\n" - + line); - } +import Duke.Parser.Parser; +import Duke.DukeException.DukeException; +import Duke.Command.*; +import Duke.Storage.Storage; +import Duke.Tasks.TaskList; +import Duke.Ui.Ui; - public static final void addTask(String input, ArrayList tasks) throws NullPointerException { - if (input.contains("todo") == true) { - tasks.add(new Todo(input.substring(TODO_POS))); - } else if (input.contains("deadline") == true) { - String by = input.substring(input.indexOf("/") + BY_POS); - tasks.add(new Deadline(input.substring(DEADLINE_POS, - input.indexOf("/")), by)); - } else if (input.contains("event") == true) { - String at = input.substring(input.indexOf("/") + AT_POS); - tasks.add(new Event(input.substring(EVENT_POS, - input.indexOf("/")), at)); - } else { - System.out.print(tasks.get(tasks.size() + 1).toString()); - } - - System.out.println(line - + "Got it. I've added this task: \n" - + tasks.get(tasks.size() - 1) + "\n" - + "Now you have " + tasks.size() - + " tasks in the list\n" - + line); - } - - public static final void deleteTask(String input, ArrayList tasks) { - String num = ""; - for (int i = 0; i < input.length(); i++) { - char c = input.charAt(i); - if (Character.isDigit(c) == true) { - num += c; - } - } - - int index = Integer.parseInt(num); - Task removedTask = tasks.get(index - 1); - tasks.remove(index - 1); - System.out.println(line - + "Noted. I've removed this task: \n" - + removedTask.toString() - + "\nNow you have " + tasks.size() - + " tasks in the list.\n" + line); - } - - public static final void clearList(ArrayList tasks) { - while (tasks.size() > 0) { - tasks.remove(0); - } - - System.out.println(line - + "The list has been cleared. Now the list is empty.\n" - + line); - } +public class Duke { + private Storage storage; + private TaskList tasks; + private Ui ui; - public static final ArrayList getDatafromFile(String fileName) { - ArrayList tasks = new ArrayList(); - String path = "C:\\Users\\XUEY0013\\Documents\\ip\\src\\main\\" + fileName+ ".txt"; - File file = new File(path); - if (!file.exists()) { - return new ArrayList (); - } - BufferedReader reader = null; + public Duke(String filePath) { + ui = new Ui(); + storage = new Storage(filePath); try { - FileInputStream fileInputStream = new FileInputStream(path); - InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); - reader = new BufferedReader(inputStreamReader); - String tempString = ""; - Task task = new Task("null"); - - while ((tempString = reader.readLine()) != null) { - if (tempString.charAt(TYPE_POS) == 'T') { - task = (new Todo(tempString.substring(TASK_POS))); - } else if (tempString.charAt(TYPE_POS) == 'E') { - String event = tempString.substring(TASK_POS, - tempString.indexOf("(") - 1); - String at = tempString.substring(tempString.indexOf(":") + 2, - tempString.indexOf(")")); - task = (new Event(event, at)); - } else if (tempString.charAt(TYPE_POS) == 'D') { - String deadline = tempString.substring(TASK_POS, - tempString.indexOf("(") - 1); - String by = tempString.substring(tempString.indexOf(":") + 2, - tempString.indexOf(")")); - task = (new Deadline(deadline, by)); - } - - if (tempString.charAt(7) == 'X') { - task.markedAsDone(); - } - - tasks.add(task); - } - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } + tasks = new TaskList(storage.load()); + } catch (DukeException e) { + ui.showLoadingError(); + tasks = new TaskList(); } - return tasks; } - public static final void saveDataToFile(String fileName,ArrayList tasks) { - BufferedWriter writer = null; - File file = new File("C:\\Users\\XUEY0013\\Documents\\ip\\src\\main\\"+ fileName + ".txt"); - if(!file.exists()) { + public void run() { + ui.showWelcome(); + boolean isExit = false; + while (!isExit) { try { - file.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); + String fullCommand = ui.readCommand(); + ui.showLine(); + Command c = Parser.parse(fullCommand); + c.execute(tasks, ui, storage); + isExit = c.isExit(); + } catch (DukeException e) { + ui.showError(e.getMessage()); + } finally { + ui.showLine(); } } - try { - writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file,false), "UTF-8")); - for (Task task : tasks) { - int i = 0; - writer.write(i + 1 + ". " + task.toString()); - i++; - writer.write("\n"); - } - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - if(writer != null){ - writer.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - System.out.println("The list of tasks have been saved!"); + } + + public static void main(String[] args) { + new Duke(".\\tasks.txt").run(); } } \ No newline at end of file diff --git a/src/main/java/Duke/Command/HelpCommand.java b/src/main/java/Duke/Command/HelpCommand.java new file mode 100644 index 000000000..066ed2fdf --- /dev/null +++ b/src/main/java/Duke/Command/HelpCommand.java @@ -0,0 +1,17 @@ +package Duke.Command; + +import Duke.Storage.Storage; +import Duke.Tasks.TaskList; +import Duke.Ui.Ui; + +public class HelpCommand extends Command { + public static final String COMMAND_WORD = "help"; + public static final String COMMAND_DESCRIPTION = COMMAND_WORD + + ": show help message for the programme.\n" + + " Example: " + COMMAND_WORD; + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + ui.showHelpMessage(); + } +} diff --git a/src/main/java/Duke/Command/InvalidCommand.java b/src/main/java/Duke/Command/InvalidCommand.java new file mode 100644 index 000000000..265f99f44 --- /dev/null +++ b/src/main/java/Duke/Command/InvalidCommand.java @@ -0,0 +1,16 @@ +package Duke.Command; + +import Duke.Storage.Storage; +import Duke.Tasks.TaskList; +import Duke.Ui.Ui; + +public class InvalidCommand extends Command { + public InvalidCommand() { + + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + ui.printInvalidCommandMessage(); + } +} diff --git a/src/main/java/Duke/Command/ListCommand.java b/src/main/java/Duke/Command/ListCommand.java new file mode 100644 index 000000000..568871fa3 --- /dev/null +++ b/src/main/java/Duke/Command/ListCommand.java @@ -0,0 +1,22 @@ +package Duke.Command; + +import Duke.Ui.Ui; +import Duke.Storage.Storage; +import Duke.Tasks.TaskList; + +public class ListCommand extends Command { + public static final String COMMAND_WORD = "list"; + public static final String COMMAND_DESCRIPTION = COMMAND_WORD + + ": display all tasks in the current list.\n" + + " Example: " + COMMAND_WORD; + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + if (!tasks.isEmpty()) { + ui.printListMessage(); + tasks.printTasks(); + } else { + ui.printListEmptyMessage(); + } + } +} diff --git a/src/main/java/Duke/DukeException/DukeException.java b/src/main/java/Duke/DukeException/DukeException.java new file mode 100644 index 000000000..fb231e2e8 --- /dev/null +++ b/src/main/java/Duke/DukeException/DukeException.java @@ -0,0 +1,14 @@ +package Duke.DukeException; + +public class DukeException extends Exception { + private final String message; + + public DukeException(String message) { + super(message); + this.message = message; + } + + public String getMessage() { + return this.message; + } +} diff --git a/src/main/java/Duke/Parser/Parser.java b/src/main/java/Duke/Parser/Parser.java new file mode 100644 index 000000000..0ae225ad1 --- /dev/null +++ b/src/main/java/Duke/Parser/Parser.java @@ -0,0 +1,135 @@ +package Duke.Parser; + +import Duke.Command.*; +import Duke.DukeException.DukeException; + +public class Parser { + public static final int TODO_POS = 5; + public static final int BY_POS = 4; + public static final int DEADLINE_POS = 9; + public static final int AT_POS = 4; + public static final int EVENT_POS = 6; + public static final int FIND_POS = 5; + + public Parser() { + } + + public static Command parse(String input) throws DukeException { + String findCommand = input.split(" ")[0]; + if (input.trim().equals("bye")) { + return new ExitCommand(); + } else if (input.trim().equals("list")) { + return new ListCommand(); + } else if (input.trim().equals("clear")) { + return new ClearCommand(); + } else if (input.trim().equals("help")) { + return new HelpCommand(); + } else if (findCommand.equals("done")) { + return prepareDone(input); + } else if (findCommand.equals("delete")) { + return prepareDelete(input); + } else if (findCommand.equals("find")) { + return prepareFind(input); + } else if (findCommand.equals("todo")) { + return prepareTodo(input); + } else if (findCommand.equals("deadline")) { + return prepareDeadline(input); + } else if (findCommand.equals("event")) { + return prepareEvent(input); + } else { + return new InvalidCommand(); + } + } + + public static DoneCommand prepareDone(String input) throws DukeException { + int index; + try { + index = Integer.parseInt(input.split(" ")[1]) - 1; + } catch (NumberFormatException n) { + throw new DukeException("Please give a numerical index for 'done' command :-("); + } + + return new DoneCommand(index); + } + + public static DeleteCommand prepareDelete(String input) throws DukeException { + int index; + try { + index = Integer.parseInt(input.split(" ")[1]) - 1; + } catch (NumberFormatException n) { + throw new DukeException("Please give a numerical index for 'delete' command :-("); + } + + return new DeleteCommand(index); + } + + public static FindCommand prepareFind(String input) throws DukeException { + String description; + try { + description = input.substring(FIND_POS); + } catch (NumberFormatException n) { + throw new DukeException("Please give a numerical index for 'done' command :-("); + } + + return new FindCommand(description); + } + + public static AddTodoCommand prepareTodo(String input) throws DukeException { + String description; + try { + description = input.substring(TODO_POS); + } catch (IndexOutOfBoundsException i) { + throw new DukeException("Please give me a description the task :-("); + } + + return new AddTodoCommand(description); + } + + public static AddDeadlineCommand prepareDeadline(String input) throws DukeException { + int indexOfBy = input.indexOf("/by"); + + if (indexOfBy == -1) { + throw new DukeException("Please tell me when the deadline is by :-("); + } + + String by; + try { + by = input.substring(indexOfBy + BY_POS); + } catch (IndexOutOfBoundsException i){ + throw new DukeException("Please give me a time for the deadline :-("); + } + + String description; + try { + description = input.substring(DEADLINE_POS, indexOfBy - 1); + } catch (IndexOutOfBoundsException i) { + throw new DukeException("Please give me a description for the deadline :-("); + } + + return new AddDeadlineCommand(description, by); + } + + public static AddEventCommand prepareEvent(String input) throws DukeException { + int indexOfAt = input.indexOf("/at"); + + if (indexOfAt == -1) { + throw new DukeException("Please tell me when the event is at :-("); + } + + String at; + try { + at = input.substring(indexOfAt + AT_POS); + } catch (IndexOutOfBoundsException i){ + throw new DukeException("Please give me a time for the event :-("); + } + + String description; + try { + description = input.substring(EVENT_POS, indexOfAt - 1); + } catch (IndexOutOfBoundsException i) { + throw new DukeException("Please give me a description for the event :-("); + } + + return new AddEventCommand(description, at); + } +} diff --git a/src/main/java/Duke/Storage/Storage.java b/src/main/java/Duke/Storage/Storage.java new file mode 100644 index 000000000..db2ce9579 --- /dev/null +++ b/src/main/java/Duke/Storage/Storage.java @@ -0,0 +1,112 @@ +package Duke.Storage; + +import Duke.Tasks.Deadline; +import Duke.Tasks.Event; +import Duke.Tasks.Task; +import Duke.Tasks.Todo; +import Duke.DukeException.DukeException; +import Duke.Ui.Ui; + +import java.io.*; +import java.util.ArrayList; + +public class Storage { + private final String path; + private static final int TYPE_POS = 4; + private static final int TASK_POS = 10; + private final Ui ui = new Ui(); + + public Storage(String path) { + this.path = path; + } + + public ArrayList load() throws DukeException { + ArrayList tasks = new ArrayList(); + File file = new File(path); + if (!file.exists()) { + throw new DukeException("No file can be loaded."); + } + BufferedReader reader = null; + try { + FileInputStream fileInputStream = new FileInputStream(path); + InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); + reader = new BufferedReader(inputStreamReader); + String tempString = ""; + Task task = new Task("null"); + + while ((tempString = reader.readLine()) != null) { + if (tempString.charAt(TYPE_POS) == 'T') { + task = (new Todo(tempString.substring(TASK_POS))); + } else if (tempString.charAt(TYPE_POS) == 'E') { + String event = tempString.substring(TASK_POS, + tempString.indexOf("(") - 1); + String at = tempString.substring(tempString.indexOf(":") + 2, + tempString.indexOf(")")); + task = (new Event(event, at)); + } else if (tempString.charAt(TYPE_POS) == 'D') { + String deadline = tempString.substring(TASK_POS, + tempString.indexOf("(") - 1); + String by = tempString.substring(tempString.indexOf(":") + 2, + tempString.indexOf(")")); + task = (new Deadline(deadline, by)); + } + + if (tempString.charAt(7) == 'X') { + task.markedAsDone(); + } + + tasks.add(task); + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + if (tasks.size() > 0) { + ui.printSuccessfulLoading(); + ui.showLine(); + } else { + ui.printListEmptyMessage(); + ui.showLine(); + } + return tasks; + } + + public final void save(ArrayList tasks) { + BufferedWriter writer = null; + File file = new File(this.path); + if(!file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { + writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file,false), "UTF-8")); + for (Task task : tasks) { + int i = 0; + writer.write(i + 1 + ". " + task.toString()); + i++; + writer.write("\n"); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if(writer != null){ + writer.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/main/java/Duke/Tasks/TaskList.java b/src/main/java/Duke/Tasks/TaskList.java new file mode 100644 index 000000000..3c487f4d1 --- /dev/null +++ b/src/main/java/Duke/Tasks/TaskList.java @@ -0,0 +1,84 @@ +package Duke.Tasks; + +import Duke.Tasks.*; +import Duke.DukeException.DukeException; + +import java.util.ArrayList; + +public class TaskList { + private static ArrayList tasks; + + public TaskList(ArrayList tasks) { + this.tasks = tasks; + } + + public TaskList() { + this.tasks = new ArrayList(); + } + + public final ArrayList getTasks() { + return this.tasks; + } + + public final boolean isEmpty() { + return this.tasks.size() == 0; + } + + public final int getNumOfSize() { + return this.tasks.size(); + } + + public final void printTasks() { + if (this.tasks.size() == 0) { + System.out.println("The current list is empty!\n"); + } else { + int index = 1; + for (Task task : this.tasks) { + System.out.println(index++ + ". " + task.toString()); + } + } + } + + public final void clearTasks() { + this.tasks = new ArrayList (); + } + + public final void deleteTask(int index) throws DukeException { + if (index >= this.tasks.size()) { + throw new DukeException("The index is out of range :-(\n"); + } else { + this.tasks.remove(index); + } + } + + public final Task setDone(int index) throws DukeException { + if (index >= this.tasks.size()) { + throw new DukeException("The index is out of range :-(\n"); + } else { + this.tasks.get(index).markedAsDone(); + return this.tasks.get(index); + } + } + + public final ArrayList find(String target) { + ArrayList foundTasks = new ArrayList(); + for (Task task : this.tasks) { + if (task.getDescription().contains(target)) { + foundTasks.add(task); + } + } + return foundTasks; + } + + public final void addTodo(String description) { + this.tasks.add(new Todo(description)); + } + + public final void addDeadline(String description, String by) { + this.tasks.add(new Deadline(description, by)); + } + + public final void addEvent(String description, String at) { + this.tasks.add(new Event(description, at)); + } +} diff --git a/src/main/java/Duke/Ui/Ui.java b/src/main/java/Duke/Ui/Ui.java new file mode 100644 index 000000000..13d7eaa4d --- /dev/null +++ b/src/main/java/Duke/Ui/Ui.java @@ -0,0 +1,110 @@ +package Duke.Ui; + +import Duke.Tasks.TaskList; +import Duke.Tasks.Task; +import Duke.Command.*; + +import java.util.Scanner; + +public class Ui { + public Ui() { + + } + + public static final String readCommand() { + Scanner input = new Scanner(System.in); + return input.nextLine(); + } + + public static final void showWelcome() { + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + System.out.println("Hello from\n" + logo); + + showLine(); + System.out.println("Hello! I'm Duke\n" + + "What can I do for you?\n"); + showLine(); + } + + public static final void showLine() { + System.out.println("____________________________________________________________"); + } + + public static final void printSuccessfulLoading() { + System.out.println("Tasks have been loaded."); + } + + public static final void printListEmptyMessage() { + System.out.println("The current list is empty~"); + } + + public static final void printListMessage() { + System.out.println("Here are the tasks in your list: "); + } + + public static final void printClearMessage() { + System.out.println("The tasks in your list have been cleared. "); + } + + public static final void printDoneMessage(Task taskDone) { + System.out.println("Nice, I have marked this task as done: \n" + + taskDone.toString()); + } + + public static final void printFindMessage() { + System.out.println("Here are the matching tasks in your list: "); + } + + public static final void printNoMatchingTaskMessage() { + System.out.println("There is no matching task in your list :-("); + } + + public static final void printDeleteMessage() { + System.out.println("Got it. I have deleted the task in your list! "); + } + + public static final void printInvalidCommandMessage() { + System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-(\n" + + "Please give me a valid command."); + } + + public static final void printAddTaskMessage(Task task) { + System.out.println("Got it. I have added the task to your list.\n" + + task.toString()); + } + + public static final void printNumOfTasks(TaskList tasks) { + System.out.println("Now you have " + tasks.getNumOfSize() + " tasks in your list."); + } + + public static final void showHelpMessage() { + System.out.println(AddDeadlineCommand.COMMAND_DESCRIPTION + + "\n\n" + AddEventCommand.COMMAND_DESCRIPTION + + "\n\n" + AddTodoCommand.COMMAND_DESCRIPTION + + "\n\n" + ClearCommand.COMMAND_DESCRIPTION + + "\n\n" + DeleteCommand.COMMAND_DESCRIPTION + + "\n\n" + DoneCommand.COMMAND_DESCRIPTION + + "\n\n" + ExitCommand.COMMAND_DESCRIPTION + + "\n\n" + FindCommand.COMMAND_DESCRIPTION + + "\n\n" + HelpCommand.COMMAND_DESCRIPTION + + "\n\n" + ListCommand.COMMAND_DESCRIPTION); + } + + public static final void showLoadingError() { + showLine(); + System.out.println("No task list can be loaded."); + showLine(); + } + + public static final void showError(String message) { + System.out.println(message); + } + + public static final void showByeMessage() { + System.out.println("Bye. Hope to see you soon~"); + } +} diff --git a/src/main/tasks.txt b/src/main/tasks.txt new file mode 100644 index 000000000..cdba8cd05 --- /dev/null +++ b/src/main/tasks.txt @@ -0,0 +1 @@ +1. [D][X] have lunch (by: tomorrow) From 6c1b940cdfc5c7099998b48593d4d760eec52aba Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Wed, 29 Sep 2021 19:19:29 +0800 Subject: [PATCH 23/26] A-JavaDoc --- src/main/java/Duke.java | 4 +- .../java/Duke/Command/AddDeadlineCommand.java | 7 +++ .../java/Duke/Command/AddEventCommand.java | 7 +++ .../java/Duke/Command/AddTodoCommand.java | 7 +++ src/main/java/Duke/Command/ClearCommand.java | 7 +++ src/main/java/Duke/Command/DeleteCommand.java | 7 +++ src/main/java/Duke/Command/DoneCommand.java | 7 +++ src/main/java/Duke/Command/ExitCommand.java | 12 +++++ src/main/java/Duke/Command/FindCommand.java | 7 +++ src/main/java/Duke/Command/HelpCommand.java | 7 +++ .../java/Duke/Command/InvalidCommand.java | 7 +++ src/main/java/Duke/Command/ListCommand.java | 7 +++ src/main/java/Duke/Parser/Parser.java | 47 +++++++++++++++++++ src/main/java/Duke/Storage/Storage.java | 10 ++++ src/main/java/Duke/Tasks/Deadline.java | 11 +++++ src/main/java/Duke/Tasks/Event.java | 11 +++++ src/main/java/Duke/Tasks/Task.java | 19 ++++++++ src/main/java/Duke/Tasks/TaskList.java | 38 +++++++++++++++ src/main/java/Duke/Tasks/Todo.java | 10 ++++ 19 files changed, 231 insertions(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index d29b52605..7d4fca2a3 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -22,7 +22,9 @@ public Duke(String filePath) { tasks = new TaskList(); } } - + /** + * Run the program. + */ public void run() { ui.showWelcome(); boolean isExit = false; diff --git a/src/main/java/Duke/Command/AddDeadlineCommand.java b/src/main/java/Duke/Command/AddDeadlineCommand.java index 0ddbac531..20f5e6766 100644 --- a/src/main/java/Duke/Command/AddDeadlineCommand.java +++ b/src/main/java/Duke/Command/AddDeadlineCommand.java @@ -20,6 +20,13 @@ public AddDeadlineCommand(String description, String by) { this.by = by; } + /** + * Execute the add deadline command by adding a new deadline task to TaskList + * + * @param tasks TaskList the command to be executed on + * @param ui Ui used for execution + * @param storage Storage which the command may make change on + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { ui.printAddTaskMessage(new Deadline(this.description, this.by)); diff --git a/src/main/java/Duke/Command/AddEventCommand.java b/src/main/java/Duke/Command/AddEventCommand.java index 33c30e749..09dac8960 100644 --- a/src/main/java/Duke/Command/AddEventCommand.java +++ b/src/main/java/Duke/Command/AddEventCommand.java @@ -15,6 +15,13 @@ public class AddEventCommand extends Command { + " Parameters: DESCRIPTION, AT_TIME\n" + " Example: " + COMMAND_WORD + "attend CS2113 lecture /at Dec 4"; + /** + * Execute the add event command by adding a new event task to TaskList + * + * @param tasks TaskList the command to be executed on + * @param ui Ui used for execution + * @param storage Storage which the command may make change on + */ public AddEventCommand(String description, String at) { this.description = description; this.at = at; diff --git a/src/main/java/Duke/Command/AddTodoCommand.java b/src/main/java/Duke/Command/AddTodoCommand.java index d3388f411..4f0e2e48d 100644 --- a/src/main/java/Duke/Command/AddTodoCommand.java +++ b/src/main/java/Duke/Command/AddTodoCommand.java @@ -18,6 +18,13 @@ public AddTodoCommand(String description) { this.description = description; } + /** + * Execute the add todo command by adding a new todo task to TaskList + * + * @param tasks TaskList the command to be executed on + * @param ui Ui used for execution + * @param storage Storage which the command may make change on + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { ui.printAddTaskMessage(new Todo(this.description)); diff --git a/src/main/java/Duke/Command/ClearCommand.java b/src/main/java/Duke/Command/ClearCommand.java index 1d8897477..b6e915607 100644 --- a/src/main/java/Duke/Command/ClearCommand.java +++ b/src/main/java/Duke/Command/ClearCommand.java @@ -10,6 +10,13 @@ public class ClearCommand extends Command { + ": clear all tasks in the current list.\n" + " Example: " + COMMAND_WORD; + /** + * Execute the clear command by clearing the tasks in TaskList + * + * @param tasks TaskList the command to be executed on + * @param ui Ui used for execution + * @param storage Storage which the command may make change on + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { ui.printClearMessage(); diff --git a/src/main/java/Duke/Command/DeleteCommand.java b/src/main/java/Duke/Command/DeleteCommand.java index 881b2fd62..a554b01d1 100644 --- a/src/main/java/Duke/Command/DeleteCommand.java +++ b/src/main/java/Duke/Command/DeleteCommand.java @@ -19,6 +19,13 @@ public DeleteCommand(int index) { this.index = index; } + /** + * Execute the delete command by deleting a task from TaskList + * + * @param tasks TaskList the command to be executed on + * @param ui Ui used for execution + * @param storage Storage which the command may make change on + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException { tasks.deleteTask(this.index); diff --git a/src/main/java/Duke/Command/DoneCommand.java b/src/main/java/Duke/Command/DoneCommand.java index d19cf4dd4..937b500d5 100644 --- a/src/main/java/Duke/Command/DoneCommand.java +++ b/src/main/java/Duke/Command/DoneCommand.java @@ -17,6 +17,13 @@ public DoneCommand(int index) { this.index = index; } + /** + * Execute the done command by setting a task as done and showing it + * + * @param tasks TaskList the command to be executed on + * @param ui Ui used for execution + * @param storage Storage which the command may make change on + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException { ui.printDoneMessage(tasks.setDone(this.index)); diff --git a/src/main/java/Duke/Command/ExitCommand.java b/src/main/java/Duke/Command/ExitCommand.java index afd864c21..015740fb7 100644 --- a/src/main/java/Duke/Command/ExitCommand.java +++ b/src/main/java/Duke/Command/ExitCommand.java @@ -11,10 +11,22 @@ public class ExitCommand extends Command { + " Example: " + COMMAND_WORD; @Override + /** + * Execute the exit command by showing the closing messagee + * + * @param tasks TaskList the command to be executed on + * @param ui Ui used for execution + * @param storage Storage which the command may make change on + */ public void execute(TaskList tasks, Ui ui, Storage storage) { ui.showByeMessage(); } + /** + * Set the flag isExit to true to terminate the program + * + * @return boolean Flag IsExit set to be true + */ @Override public boolean isExit() { return true; diff --git a/src/main/java/Duke/Command/FindCommand.java b/src/main/java/Duke/Command/FindCommand.java index 837292dc9..6238d417e 100644 --- a/src/main/java/Duke/Command/FindCommand.java +++ b/src/main/java/Duke/Command/FindCommand.java @@ -15,6 +15,13 @@ public class FindCommand extends Command { private final String target; + /** + * Execute the find command by looking for and showing tasks in TaskList that contain the key word + * + * @param tasks TaskList the command to be executed on + * @param ui Ui used for execution + * @param storage Storage which the command may make change on + */ public FindCommand(String target) { this.target = target; } diff --git a/src/main/java/Duke/Command/HelpCommand.java b/src/main/java/Duke/Command/HelpCommand.java index 066ed2fdf..2943cef80 100644 --- a/src/main/java/Duke/Command/HelpCommand.java +++ b/src/main/java/Duke/Command/HelpCommand.java @@ -10,6 +10,13 @@ public class HelpCommand extends Command { + ": show help message for the programme.\n" + " Example: " + COMMAND_WORD; + /** + * Execute the help command by showing the usage of all the commands + * + * @param tasks TaskList the command to be executed on + * @param ui Ui used for execution + * @param storage Storage which the command may make change on + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { ui.showHelpMessage(); diff --git a/src/main/java/Duke/Command/InvalidCommand.java b/src/main/java/Duke/Command/InvalidCommand.java index 265f99f44..3bc4ac263 100644 --- a/src/main/java/Duke/Command/InvalidCommand.java +++ b/src/main/java/Duke/Command/InvalidCommand.java @@ -10,6 +10,13 @@ public InvalidCommand() { } @Override + /** + * Execute the invalid command by showing invalid command message + * + * @param tasks TaskList the command to be executed on + * @param ui Ui used for execution + * @param storage Storage which the command may make change on + */ public void execute(TaskList tasks, Ui ui, Storage storage) { ui.printInvalidCommandMessage(); } diff --git a/src/main/java/Duke/Command/ListCommand.java b/src/main/java/Duke/Command/ListCommand.java index 568871fa3..05fbb6b0e 100644 --- a/src/main/java/Duke/Command/ListCommand.java +++ b/src/main/java/Duke/Command/ListCommand.java @@ -10,6 +10,13 @@ public class ListCommand extends Command { + ": display all tasks in the current list.\n" + " Example: " + COMMAND_WORD; + /** + * Execute the list command by showing the TaskList. + * + * @param tasks TaskList the command to be executed on. + * @param ui Ui used for execution + * @param storage Storage which the command may make change on. + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { if (!tasks.isEmpty()) { diff --git a/src/main/java/Duke/Parser/Parser.java b/src/main/java/Duke/Parser/Parser.java index 0ae225ad1..3f2a10f03 100644 --- a/src/main/java/Duke/Parser/Parser.java +++ b/src/main/java/Duke/Parser/Parser.java @@ -14,6 +14,12 @@ public class Parser { public Parser() { } + /** + * Parse the input and get the command with required variables. + * + * @param input Input string from the user. + * @return Command Command class parsed from the input. + */ public static Command parse(String input) throws DukeException { String findCommand = input.split(" ")[0]; if (input.trim().equals("bye")) { @@ -41,6 +47,13 @@ public static Command parse(String input) throws DukeException { } } + /** + * Prepare the done command by extracting the index. + * + * @param input Input string from the user. + * @return DoneCommand DoneCommand got from the input. + * @throws DukeException if the input is in an incorrect format + */ public static DoneCommand prepareDone(String input) throws DukeException { int index; try { @@ -52,6 +65,12 @@ public static DoneCommand prepareDone(String input) throws DukeException { return new DoneCommand(index); } + /** + * Prepare the delete command by extracting the index. + * + * @param input Input string from the user. + * @return DeleteCommand DeleteCommand got from the input. + */ public static DeleteCommand prepareDelete(String input) throws DukeException { int index; try { @@ -63,6 +82,13 @@ public static DeleteCommand prepareDelete(String input) throws DukeException { return new DeleteCommand(index); } + /** + * Prepare the find command by extracting the description. + * + * @param input Input string from the user. + * @return FindCommand FindCommand got from the input. + * @throws DukeException if the input is in an incorrect format + */ public static FindCommand prepareFind(String input) throws DukeException { String description; try { @@ -74,6 +100,13 @@ public static FindCommand prepareFind(String input) throws DukeException { return new FindCommand(description); } + /** + * Prepare the add todo command by extracting the description. + * + * @param input Input string from the user. + * @return AddTodoCommand AddTodoCommand got from the input. + * @throws DukeException if the input is in an incorrect format + */ public static AddTodoCommand prepareTodo(String input) throws DukeException { String description; try { @@ -85,6 +118,13 @@ public static AddTodoCommand prepareTodo(String input) throws DukeException { return new AddTodoCommand(description); } + /** + * Prepare the add deadline command by extracting the description and by time. + * + * @param input Input string from the user. + * @return AddDeadlineCommand AddDeadlineCommand got from the input. + * @throws DukeException if the input is in an incorrect format + */ public static AddDeadlineCommand prepareDeadline(String input) throws DukeException { int indexOfBy = input.indexOf("/by"); @@ -109,6 +149,13 @@ public static AddDeadlineCommand prepareDeadline(String input) throws DukeExcept return new AddDeadlineCommand(description, by); } + /** + * Prepare the add event command by extracting the description and by time. + * + * @param input Input string from the user. + * @return AddEventCommand AddEventCommand got from the input. + * @throws DukeException if the input is in an incorrect format + */ public static AddEventCommand prepareEvent(String input) throws DukeException { int indexOfAt = input.indexOf("/at"); diff --git a/src/main/java/Duke/Storage/Storage.java b/src/main/java/Duke/Storage/Storage.java index db2ce9579..8dbaa3b1e 100644 --- a/src/main/java/Duke/Storage/Storage.java +++ b/src/main/java/Duke/Storage/Storage.java @@ -20,6 +20,11 @@ public Storage(String path) { this.path = path; } + /** + * Load the task record and copy it into current TaskList. + * + * @throws DukeException If file does not exist. + */ public ArrayList load() throws DukeException { ArrayList tasks = new ArrayList(); File file = new File(path); @@ -79,6 +84,11 @@ public ArrayList load() throws DukeException { return tasks; } + /** + * Save the content of current task list to the txt file. + * + * @param tasks Tasklist to be saved. + */ public final void save(ArrayList tasks) { BufferedWriter writer = null; File file = new File(this.path); diff --git a/src/main/java/Duke/Tasks/Deadline.java b/src/main/java/Duke/Tasks/Deadline.java index b214a7709..eadef12f4 100644 --- a/src/main/java/Duke/Tasks/Deadline.java +++ b/src/main/java/Duke/Tasks/Deadline.java @@ -3,11 +3,22 @@ public class Deadline extends Task { public String by; + /** + * Create a Deadline class with given description and by time. + * + * @param description Description of the deadline task. + * @param by By time of the deadline task. + */ public Deadline(String description, String by) { super(description); this.by = by; } + /** + * Present deadline in string of prescribed format. + * + * @return String presented deadline description format. + */ @Override public String toString() { return "[D]" + super.toString() + " (by: " + this.by diff --git a/src/main/java/Duke/Tasks/Event.java b/src/main/java/Duke/Tasks/Event.java index 2949e16d4..0013f0ecf 100644 --- a/src/main/java/Duke/Tasks/Event.java +++ b/src/main/java/Duke/Tasks/Event.java @@ -3,11 +3,22 @@ public class Event extends Task { public String at; + /** + * Create a Event class with given description and by time. + * + * @param description Description of the event task. + * @param by At time of the event task. + */ public Event(String description, String at) { super(description); this.at = at; } + /** + * Present event in string of prescribed format. + * + * @return String presented event description format. + */ @Override public String toString() { return "[E]" + super.toString() + " (at: " + this.at diff --git a/src/main/java/Duke/Tasks/Task.java b/src/main/java/Duke/Tasks/Task.java index bd056750a..1f25b754d 100644 --- a/src/main/java/Duke/Tasks/Task.java +++ b/src/main/java/Duke/Tasks/Task.java @@ -4,19 +4,38 @@ public class Task { protected String description; protected String isDone; + /** + * Create a Task class with given description. + * + * @param description Description of the task. + */ public Task(String description) { this.description = description; this.isDone = " "; } + /** + * Get the description of the task. + * + * @return description Description of the task + */ public final String getDescription() { return this.description; } + /** + * Mark the task as done. + * + */ public final void markedAsDone() { this.isDone = "X"; } + /** + * Present event in string of prescribed format. + * + * @return String presented event description format. + */ @Override public String toString() { String status; diff --git a/src/main/java/Duke/Tasks/TaskList.java b/src/main/java/Duke/Tasks/TaskList.java index 3c487f4d1..d8ad49bbf 100644 --- a/src/main/java/Duke/Tasks/TaskList.java +++ b/src/main/java/Duke/Tasks/TaskList.java @@ -8,26 +8,54 @@ public class TaskList { private static ArrayList tasks; + /** + * Create a TaskList class with the given list of tasks. + * + * @param tasks List of recorded tasks. + */ public TaskList(ArrayList tasks) { this.tasks = tasks; } + /** + * Create a TaskList class of an empty list. + * + */ public TaskList() { this.tasks = new ArrayList(); } + /** + * Return the tasks in the TaskList. + * + * @return tasks Tasks in the TaskList. + */ public final ArrayList getTasks() { return this.tasks; } + /** + * Tell whether the TaskList is empty. + * + * @return isEmpty Status of whether the TaskList is empty. + */ public final boolean isEmpty() { return this.tasks.size() == 0; } + /** + * Get the number of tasks in the TaskList. + * + * @return size Size of the TaskList. + */ public final int getNumOfSize() { return this.tasks.size(); } + /** + * Print the tasks in the TaskList. + * + */ public final void printTasks() { if (this.tasks.size() == 0) { System.out.println("The current list is empty!\n"); @@ -39,6 +67,10 @@ public final void printTasks() { } } + /** + * Clear the tasks in the Tasklist. + * + */ public final void clearTasks() { this.tasks = new ArrayList (); } @@ -51,6 +83,12 @@ public final void deleteTask(int index) throws DukeException { } } + /** + * Set a task in the TaskList of certain index as done. + * + * @param index Index of the task to be set as done. + * @throws DukeException If the index is out of range. + */ public final Task setDone(int index) throws DukeException { if (index >= this.tasks.size()) { throw new DukeException("The index is out of range :-(\n"); diff --git a/src/main/java/Duke/Tasks/Todo.java b/src/main/java/Duke/Tasks/Todo.java index 9bd0934df..ff1afd68d 100644 --- a/src/main/java/Duke/Tasks/Todo.java +++ b/src/main/java/Duke/Tasks/Todo.java @@ -4,10 +4,20 @@ public class Todo extends Task { + /** + * Create a Todo class with given description. + * + * @param description Description of the todo task. + */ public Todo(String description) { super(description); } + /** + * Present todo in string of prescribed format. + * + * @return String presented todo description format. + */ @Override public String toString() { return "[T]" + super.toString(); From 27ea764c18cf53c5f29b8c7f2bba803aab828efb Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Wed, 29 Sep 2021 19:26:10 +0800 Subject: [PATCH 24/26] commit --- src/main/java/Duke/Parser/Parser.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/Duke/Parser/Parser.java b/src/main/java/Duke/Parser/Parser.java index 3f2a10f03..a4e72c5e2 100644 --- a/src/main/java/Duke/Parser/Parser.java +++ b/src/main/java/Duke/Parser/Parser.java @@ -127,7 +127,6 @@ public static AddTodoCommand prepareTodo(String input) throws DukeException { */ public static AddDeadlineCommand prepareDeadline(String input) throws DukeException { int indexOfBy = input.indexOf("/by"); - if (indexOfBy == -1) { throw new DukeException("Please tell me when the deadline is by :-("); } @@ -158,7 +157,6 @@ public static AddDeadlineCommand prepareDeadline(String input) throws DukeExcept */ public static AddEventCommand prepareEvent(String input) throws DukeException { int indexOfAt = input.indexOf("/at"); - if (indexOfAt == -1) { throw new DukeException("Please tell me when the event is at :-("); } From 329a47eb043b2354f969e7624753ba50880061aa Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Fri, 1 Oct 2021 10:25:48 +0800 Subject: [PATCH 25/26] Update User Guide and correct some minor errors --- docs/README.md | 171 +++++++++++++++++- src/main/java/Duke.java | 2 +- .../java/Duke/Command/AddDeadlineCommand.java | 2 +- .../java/Duke/Command/AddEventCommand.java | 2 +- .../java/Duke/Command/AddTodoCommand.java | 2 +- src/main/java/Duke/Command/Command.java | 2 +- src/main/java/Duke/Command/DeleteCommand.java | 5 +- src/main/java/Duke/Command/DoneCommand.java | 2 +- src/main/java/Duke/Command/FindCommand.java | 4 +- src/main/java/Duke/Command/HelpCommand.java | 2 +- .../java/Duke/Command/InvalidCommand.java | 2 +- src/main/java/Duke/Parser/Parser.java | 54 +++--- src/main/java/Duke/Tasks/TaskList.java | 52 +++--- src/main/java/Duke/Ui/Ui.java | 12 +- 14 files changed, 240 insertions(+), 74 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..5c1c55693 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,28 +2,181 @@ ## Features -### Feature-ABC +### 1. Add tasks -Description of the feature. + Add three types of tasks to the list (todo, deadline,event) -### Feature-XYZ +### 2. List tasks + + Display all the tasks in the list + +### 3. Delete task + Delete a task from the list with a given index + +### 4. Mark task as done + Mark a task as done with a given index + +### 5. Find task + Find a task in the list with a given key word + +### 6. clear all the tasks + Clear all the tasks in the list -Description of the feature. ## Usage -### `Keyword` - Describe action +### 1. `todo` - add a simple task to the list -Describe the action and its outcome. +Format: `todo DESCRIPTION` Example of usage: -`keyword (optional arguments)` +`todo do the online quiz` + +Expected outcome: + +``` +Got it. I have added the task to your list. +[T][ ] do the online quiz +``` + +You have added the task to the list successfully. + +### 2. `deadline` - add a deadline to the list + +Format: `deadline DESCRIPTION /by TIME` + +Example of usage: + +`deadline submit individual project /by 1 Oct 23:59` + +Expected outcome: + +``` +Got it. I have added the task to your list. +[D][ ] submit individual project (by: 1 Oct 23:59) +``` + +You have added the deadline to the list successfully. + +### 3. `event` - add a event to the list + +Format: `event DESCRIPTION /at TIME` + +Example of usage: + +`event online programming workshop /at Tuesday` + +Expected outcome: + +``` +Got it. I have added the task to your list. +[E][ ] online programming workshop (by: Tuesday) +``` + +You have added the event to the list successfully. + +### 4. `list` - list all the tasks + +Format: `list` + +Expected outcome: + +``` +Here are the tasks in your list: +1. [T][ ] read books +2. [E][X] online meeting (at: 30 Sept 22:00) +``` + +### 5. `done` - mark a task as done + +Format: `done TARGET_INDEX` + +Example of usage: + +`done 1` Expected outcome: -Description of the outcome. +``` +Nice, I have marked this task as done: +[T][X] read books +``` +The first task in the list has been marked as done + +### 6. `delete` - delete a task from the list + +Format: `delete TARGET_INDEX` + +Example of usage: + +`delete 2` + +Expected outcome: + +``` +Got it. I have deleted the tasks in your list! +[E][X] online meeting (at: 30 Sept 22:00) +``` +The second task in the list has been deleted + +### 7. `clear` - clear all the tasks + +Format: `clear` + +Expected outcome: + +``` +The tasks in your list have been cleared. +``` +The list is empty now + +### 8. `find` - find a task containing the given key word(s) + +Format: `find TARGET` + +Example of usage: + +`find read` + +Expected outcome: ``` -expected output +Here are the matching tasks in your list: +[T][ ] read books +[D][X] read lab manual (by: today 22:00) ``` +All the tasks containing the key word have been displayed + +### 9. `help` - show help information + +Format: `help` + +Expected outcome: + +``` +Here are the usage of all commands: + +deadline: add a deadline task to the current list. + Parameters: DESCRIPTION, BY_TIME + Example: deadline take the quiz /by Tuesday + +...(omitted) + +list: display all tasks in the current list. + Example: list +``` +The usages of all commands have been displayed + +### 10. `bye` - exit the program + +Format: `bye` + +Expected outcome: + +``` +Bye. Hope to see you soon~ +``` +The program have been terminated, and the changes in each step have been saved, so you can +load the task list record when you start the program next time : ) + diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 7d4fca2a3..eb710bb42 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -4,8 +4,8 @@ import Duke.DukeException.DukeException; import Duke.Command.*; import Duke.Storage.Storage; -import Duke.Tasks.TaskList; import Duke.Ui.Ui; +import Duke.Tasks.TaskList; public class Duke { private Storage storage; diff --git a/src/main/java/Duke/Command/AddDeadlineCommand.java b/src/main/java/Duke/Command/AddDeadlineCommand.java index 20f5e6766..c3b2d4790 100644 --- a/src/main/java/Duke/Command/AddDeadlineCommand.java +++ b/src/main/java/Duke/Command/AddDeadlineCommand.java @@ -2,8 +2,8 @@ import Duke.Ui.Ui; import Duke.Storage.Storage; -import Duke.Tasks.TaskList; import Duke.Tasks.Deadline; +import Duke.Tasks.TaskList; public class AddDeadlineCommand extends Command { private final String description; diff --git a/src/main/java/Duke/Command/AddEventCommand.java b/src/main/java/Duke/Command/AddEventCommand.java index 09dac8960..67f8d1353 100644 --- a/src/main/java/Duke/Command/AddEventCommand.java +++ b/src/main/java/Duke/Command/AddEventCommand.java @@ -2,8 +2,8 @@ import Duke.Ui.Ui; import Duke.Storage.Storage; -import Duke.Tasks.TaskList; import Duke.Tasks.Event; +import Duke.Tasks.TaskList; public class AddEventCommand extends Command { private final String description; diff --git a/src/main/java/Duke/Command/AddTodoCommand.java b/src/main/java/Duke/Command/AddTodoCommand.java index 4f0e2e48d..896c04de6 100644 --- a/src/main/java/Duke/Command/AddTodoCommand.java +++ b/src/main/java/Duke/Command/AddTodoCommand.java @@ -2,8 +2,8 @@ import Duke.Ui.Ui; import Duke.Storage.Storage; -import Duke.Tasks.TaskList; import Duke.Tasks.Todo; +import Duke.Tasks.TaskList; public class AddTodoCommand extends Command { private final String description; diff --git a/src/main/java/Duke/Command/Command.java b/src/main/java/Duke/Command/Command.java index 1fb86a45e..a4ea0c12a 100644 --- a/src/main/java/Duke/Command/Command.java +++ b/src/main/java/Duke/Command/Command.java @@ -1,9 +1,9 @@ package Duke.Command; import Duke.Storage.Storage; -import Duke.Tasks.TaskList; import Duke.Ui.Ui; import Duke.DukeException.DukeException; +import Duke.Tasks.TaskList; public abstract class Command { public abstract void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException; diff --git a/src/main/java/Duke/Command/DeleteCommand.java b/src/main/java/Duke/Command/DeleteCommand.java index a554b01d1..3dec696ea 100644 --- a/src/main/java/Duke/Command/DeleteCommand.java +++ b/src/main/java/Duke/Command/DeleteCommand.java @@ -2,8 +2,8 @@ import Duke.Storage.Storage; import Duke.Ui.Ui; -import Duke.Tasks.TaskList; import Duke.DukeException.DukeException; +import Duke.Tasks.TaskList; public class DeleteCommand extends Command { public static final String COMMAND_WORD = "delete"; @@ -28,8 +28,7 @@ public DeleteCommand(int index) { */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException { - tasks.deleteTask(this.index); - ui.printDeleteMessage(); + ui.printDeleteMessage(tasks.deleteTask(this.index)); ui.printNumOfTasks(tasks); storage.save(tasks.getTasks()); } diff --git a/src/main/java/Duke/Command/DoneCommand.java b/src/main/java/Duke/Command/DoneCommand.java index 937b500d5..967b36ae3 100644 --- a/src/main/java/Duke/Command/DoneCommand.java +++ b/src/main/java/Duke/Command/DoneCommand.java @@ -2,8 +2,8 @@ import Duke.Storage.Storage; import Duke.Ui.Ui; -import Duke.Tasks.TaskList; import Duke.DukeException.DukeException; +import Duke.Tasks.TaskList; public class DoneCommand extends Command { private final int index; diff --git a/src/main/java/Duke/Command/FindCommand.java b/src/main/java/Duke/Command/FindCommand.java index 6238d417e..4d111ec54 100644 --- a/src/main/java/Duke/Command/FindCommand.java +++ b/src/main/java/Duke/Command/FindCommand.java @@ -16,7 +16,7 @@ public class FindCommand extends Command { private final String target; /** - * Execute the find command by looking for and showing tasks in TaskList that contain the key word + * Executes the find command by looking for and showing tasks in TaskList that contain the key word * * @param tasks TaskList the command to be executed on * @param ui Ui used for execution @@ -37,4 +37,4 @@ public void execute(TaskList tasks, Ui ui, Storage storage) { } } } -} +} \ No newline at end of file diff --git a/src/main/java/Duke/Command/HelpCommand.java b/src/main/java/Duke/Command/HelpCommand.java index 2943cef80..b49021c82 100644 --- a/src/main/java/Duke/Command/HelpCommand.java +++ b/src/main/java/Duke/Command/HelpCommand.java @@ -1,8 +1,8 @@ package Duke.Command; import Duke.Storage.Storage; -import Duke.Tasks.TaskList; import Duke.Ui.Ui; +import Duke.Tasks.TaskList; public class HelpCommand extends Command { public static final String COMMAND_WORD = "help"; diff --git a/src/main/java/Duke/Command/InvalidCommand.java b/src/main/java/Duke/Command/InvalidCommand.java index 3bc4ac263..72b6e6fb0 100644 --- a/src/main/java/Duke/Command/InvalidCommand.java +++ b/src/main/java/Duke/Command/InvalidCommand.java @@ -1,8 +1,8 @@ package Duke.Command; import Duke.Storage.Storage; -import Duke.Tasks.TaskList; import Duke.Ui.Ui; +import Duke.Tasks.TaskList; public class InvalidCommand extends Command { public InvalidCommand() { diff --git a/src/main/java/Duke/Parser/Parser.java b/src/main/java/Duke/Parser/Parser.java index 3f2a10f03..d382d6c70 100644 --- a/src/main/java/Duke/Parser/Parser.java +++ b/src/main/java/Duke/Parser/Parser.java @@ -15,10 +15,10 @@ public Parser() { } /** - * Parse the input and get the command with required variables. + * Parses the input and get the command with required variables * - * @param input Input string from the user. - * @return Command Command class parsed from the input. + * @param input Input string from the user + * @return Command Command class parsed from the input */ public static Command parse(String input) throws DukeException { String findCommand = input.split(" ")[0]; @@ -48,10 +48,10 @@ public static Command parse(String input) throws DukeException { } /** - * Prepare the done command by extracting the index. + * Prepares the done command by extracting the index * - * @param input Input string from the user. - * @return DoneCommand DoneCommand got from the input. + * @param input Input string from the user + * @return DoneCommand DoneCommand got from the input * @throws DukeException if the input is in an incorrect format */ public static DoneCommand prepareDone(String input) throws DukeException { @@ -60,16 +60,18 @@ public static DoneCommand prepareDone(String input) throws DukeException { index = Integer.parseInt(input.split(" ")[1]) - 1; } catch (NumberFormatException n) { throw new DukeException("Please give a numerical index for 'done' command :-("); + } catch (IndexOutOfBoundsException i) { + throw new DukeException("Please give an index for 'done' command :-("); } return new DoneCommand(index); } /** - * Prepare the delete command by extracting the index. + * Prepares the delete command by extracting the index * - * @param input Input string from the user. - * @return DeleteCommand DeleteCommand got from the input. + * @param input Input string from the user + * @return DeleteCommand DeleteCommand got from the input */ public static DeleteCommand prepareDelete(String input) throws DukeException { int index; @@ -77,16 +79,18 @@ public static DeleteCommand prepareDelete(String input) throws DukeException { index = Integer.parseInt(input.split(" ")[1]) - 1; } catch (NumberFormatException n) { throw new DukeException("Please give a numerical index for 'delete' command :-("); + } catch (IndexOutOfBoundsException i) { + throw new DukeException("Please give an index for 'delete' command :-("); } return new DeleteCommand(index); } /** - * Prepare the find command by extracting the description. + * Prepares the find command by extracting the description * - * @param input Input string from the user. - * @return FindCommand FindCommand got from the input. + * @param input Input string from the user + * @return FindCommand FindCommand got from the input * @throws DukeException if the input is in an incorrect format */ public static FindCommand prepareFind(String input) throws DukeException { @@ -95,16 +99,18 @@ public static FindCommand prepareFind(String input) throws DukeException { description = input.substring(FIND_POS); } catch (NumberFormatException n) { throw new DukeException("Please give a numerical index for 'done' command :-("); + } catch (IndexOutOfBoundsException i) { + throw new DukeException("Please give a key word for 'find' command :-("); } return new FindCommand(description); } /** - * Prepare the add todo command by extracting the description. + * Prepares the add todo command by extracting the description * - * @param input Input string from the user. - * @return AddTodoCommand AddTodoCommand got from the input. + * @param input Input string from the user + * @return AddTodoCommand AddTodoCommand got from the input * @throws DukeException if the input is in an incorrect format */ public static AddTodoCommand prepareTodo(String input) throws DukeException { @@ -112,22 +118,21 @@ public static AddTodoCommand prepareTodo(String input) throws DukeException { try { description = input.substring(TODO_POS); } catch (IndexOutOfBoundsException i) { - throw new DukeException("Please give me a description the task :-("); + throw new DukeException("Please give me a description for the task :-("); } return new AddTodoCommand(description); } /** - * Prepare the add deadline command by extracting the description and by time. + * Prepares the add deadline command by extracting the description and by time * - * @param input Input string from the user. - * @return AddDeadlineCommand AddDeadlineCommand got from the input. + * @param input Input string from the user + * @return AddDeadlineCommand AddDeadlineCommand got from the input * @throws DukeException if the input is in an incorrect format */ public static AddDeadlineCommand prepareDeadline(String input) throws DukeException { int indexOfBy = input.indexOf("/by"); - if (indexOfBy == -1) { throw new DukeException("Please tell me when the deadline is by :-("); } @@ -150,15 +155,14 @@ public static AddDeadlineCommand prepareDeadline(String input) throws DukeExcept } /** - * Prepare the add event command by extracting the description and by time. + * Prepares the add event command by extracting the description and by time * - * @param input Input string from the user. - * @return AddEventCommand AddEventCommand got from the input. + * @param input Input string from the user + * @return AddEventCommand AddEventCommand got from the input * @throws DukeException if the input is in an incorrect format */ public static AddEventCommand prepareEvent(String input) throws DukeException { int indexOfAt = input.indexOf("/at"); - if (indexOfAt == -1) { throw new DukeException("Please tell me when the event is at :-("); } @@ -179,4 +183,4 @@ public static AddEventCommand prepareEvent(String input) throws DukeException { return new AddEventCommand(description, at); } -} +} \ No newline at end of file diff --git a/src/main/java/Duke/Tasks/TaskList.java b/src/main/java/Duke/Tasks/TaskList.java index d8ad49bbf..5c8e2477a 100644 --- a/src/main/java/Duke/Tasks/TaskList.java +++ b/src/main/java/Duke/Tasks/TaskList.java @@ -9,16 +9,16 @@ public class TaskList { private static ArrayList tasks; /** - * Create a TaskList class with the given list of tasks. + * Create a TaskList class with the given list of tasks * - * @param tasks List of recorded tasks. + * @param tasks List of recorded tasks */ public TaskList(ArrayList tasks) { this.tasks = tasks; } /** - * Create a TaskList class of an empty list. + * Create a TaskList class of an empty list * */ public TaskList() { @@ -26,34 +26,34 @@ public TaskList() { } /** - * Return the tasks in the TaskList. + * Return the tasks in the TaskList * - * @return tasks Tasks in the TaskList. + * @return tasks Tasks in the TaskList */ public final ArrayList getTasks() { return this.tasks; } /** - * Tell whether the TaskList is empty. + * Tell whether the TaskList is empty * - * @return isEmpty Status of whether the TaskList is empty. + * @return isEmpty Status of whether the TaskList is empty */ public final boolean isEmpty() { return this.tasks.size() == 0; } /** - * Get the number of tasks in the TaskList. + * Get the number of tasks in the TaskList * - * @return size Size of the TaskList. + * @return size Size of the TaskList */ public final int getNumOfSize() { return this.tasks.size(); } /** - * Print the tasks in the TaskList. + * Print the tasks in the TaskList * */ public final void printTasks() { @@ -68,36 +68,44 @@ public final void printTasks() { } /** - * Clear the tasks in the Tasklist. + * Clears the tasks in the Tasklist * */ public final void clearTasks() { this.tasks = new ArrayList (); } - public final void deleteTask(int index) throws DukeException { - if (index >= this.tasks.size()) { - throw new DukeException("The index is out of range :-(\n"); - } else { + public final Task deleteTask(int index) throws DukeException { + Task deletedTask; + try { + deletedTask = this.tasks.get(index); this.tasks.remove(index); + } catch (IndexOutOfBoundsException i) { + throw new DukeException("The index is out of range, please enter a valid index :-("); } + return deletedTask; } /** - * Set a task in the TaskList of certain index as done. + * Sets a task in the TaskList of certain index as done * - * @param index Index of the task to be set as done. - * @throws DukeException If the index is out of range. + * @param index Index of the task to be set as done + * @throws DukeException If the index is out of range */ public final Task setDone(int index) throws DukeException { - if (index >= this.tasks.size()) { - throw new DukeException("The index is out of range :-(\n"); - } else { + try { this.tasks.get(index).markedAsDone(); return this.tasks.get(index); + } catch (IndexOutOfBoundsException i) { + throw new DukeException("The index is out of range, please enter a valid index :-("); } } + /** + * Finds a task in the TaskList with key word + * + * @param target Target key word for the matching task + */ public final ArrayList find(String target) { ArrayList foundTasks = new ArrayList(); for (Task task : this.tasks) { @@ -119,4 +127,4 @@ public final void addDeadline(String description, String by) { public final void addEvent(String description, String at) { this.tasks.add(new Event(description, at)); } -} +} \ No newline at end of file diff --git a/src/main/java/Duke/Ui/Ui.java b/src/main/java/Duke/Ui/Ui.java index 13d7eaa4d..52a075977 100644 --- a/src/main/java/Duke/Ui/Ui.java +++ b/src/main/java/Duke/Ui/Ui.java @@ -31,7 +31,7 @@ public static final void showWelcome() { } public static final void showLine() { - System.out.println("____________________________________________________________"); + System.out.println(" * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . *"); } public static final void printSuccessfulLoading() { @@ -63,8 +63,9 @@ public static final void printNoMatchingTaskMessage() { System.out.println("There is no matching task in your list :-("); } - public static final void printDeleteMessage() { - System.out.println("Got it. I have deleted the task in your list! "); + public static final void printDeleteMessage(Task taskDeleted) { + System.out.println("Got it. I have deleted the task in your list! \n" + + taskDeleted.toString()); } public static final void printInvalidCommandMessage() { @@ -78,11 +79,12 @@ public static final void printAddTaskMessage(Task task) { } public static final void printNumOfTasks(TaskList tasks) { - System.out.println("Now you have " + tasks.getNumOfSize() + " tasks in your list."); + System.out.println("Now you have " + tasks.getNumOfSize() + " task(s) in your list."); } public static final void showHelpMessage() { - System.out.println(AddDeadlineCommand.COMMAND_DESCRIPTION + System.out.println("Here are the usages of all commands:" + + "\n\n" + AddDeadlineCommand.COMMAND_DESCRIPTION + "\n\n" + AddEventCommand.COMMAND_DESCRIPTION + "\n\n" + AddTodoCommand.COMMAND_DESCRIPTION + "\n\n" + ClearCommand.COMMAND_DESCRIPTION From 22393ec258dd4a81929e942dca6f0226467d0ce8 Mon Sep 17 00:00:00 2001 From: Mist0919 Date: Fri, 1 Oct 2021 20:16:13 +0800 Subject: [PATCH 26/26] Final correction --- src/main/java/.idea/.gitignore | 8 ++++++++ src/main/java/.idea/artifacts/main_jar.xml | 8 ++++++++ src/main/java/.idea/misc.xml | 6 ++++++ src/main/java/.idea/modules.xml | 8 ++++++++ src/main/java/.idea/runConfigurations.xml | 10 ++++++++++ src/main/java/.idea/vcs.xml | 6 ++++++ src/main/java/Duke/Parser/Parser.java | 3 ++- src/main/java/Duke/Ui/Ui.java | 2 +- .../out/production/main/Duke/.idea/.gitignore | 8 ++++++++ .../main/Duke/.idea/artifacts/main_jar.xml | 8 ++++++++ .../java/out/production/main/Duke/.idea/misc.xml | 6 ++++++ .../out/production/main/Duke/.idea/modules.xml | 8 ++++++++ .../main/Duke/.idea/runConfigurations.xml | 10 ++++++++++ .../java/out/production/main/Duke/.idea/vcs.xml | 6 ++++++ .../production/main/Duke/META-INF/MANIFEST.MF | 3 +++ src/main/out/production/main/.idea/.gitignore | 8 ++++++++ .../production/main/.idea/artifacts/main_jar.xml | 8 ++++++++ src/main/out/production/main/.idea/misc.xml | 6 ++++++ src/main/out/production/main/.idea/modules.xml | 8 ++++++++ .../production/main/.idea/runConfigurations.xml | 10 ++++++++++ src/main/out/production/main/.idea/vcs.xml | 6 ++++++ .../main/Duke/Command/DeleteCommand.class | Bin 0 -> 1254 bytes .../out/production/main/Duke/Parser/Parser.class | Bin 0 -> 4710 bytes .../production/main/Duke/Tasks/TaskList.class | Bin 0 -> 3825 bytes src/main/out/production/main/Duke/Ui/Ui.class | Bin 0 -> 4936 bytes .../out/production/main/Duke/.idea/.gitignore | 8 ++++++++ .../main/Duke/.idea/artifacts/main_jar.xml | 8 ++++++++ .../main/out/production/main/Duke/.idea/misc.xml | 6 ++++++ .../out/production/main/Duke/.idea/modules.xml | 8 ++++++++ .../main/Duke/.idea/runConfigurations.xml | 10 ++++++++++ .../main/out/production/main/Duke/.idea/vcs.xml | 6 ++++++ .../production/main/Duke/META-INF/MANIFEST.MF | 3 +++ 32 files changed, 193 insertions(+), 2 deletions(-) create mode 100644 src/main/java/.idea/.gitignore create mode 100644 src/main/java/.idea/artifacts/main_jar.xml create mode 100644 src/main/java/.idea/misc.xml create mode 100644 src/main/java/.idea/modules.xml create mode 100644 src/main/java/.idea/runConfigurations.xml create mode 100644 src/main/java/.idea/vcs.xml create mode 100644 src/main/java/out/production/main/Duke/.idea/.gitignore create mode 100644 src/main/java/out/production/main/Duke/.idea/artifacts/main_jar.xml create mode 100644 src/main/java/out/production/main/Duke/.idea/misc.xml create mode 100644 src/main/java/out/production/main/Duke/.idea/modules.xml create mode 100644 src/main/java/out/production/main/Duke/.idea/runConfigurations.xml create mode 100644 src/main/java/out/production/main/Duke/.idea/vcs.xml create mode 100644 src/main/java/out/production/main/Duke/META-INF/MANIFEST.MF create mode 100644 src/main/out/production/main/.idea/.gitignore create mode 100644 src/main/out/production/main/.idea/artifacts/main_jar.xml create mode 100644 src/main/out/production/main/.idea/misc.xml create mode 100644 src/main/out/production/main/.idea/modules.xml create mode 100644 src/main/out/production/main/.idea/runConfigurations.xml create mode 100644 src/main/out/production/main/.idea/vcs.xml create mode 100644 src/main/out/production/main/Duke/Command/DeleteCommand.class create mode 100644 src/main/out/production/main/Duke/Parser/Parser.class create mode 100644 src/main/out/production/main/Duke/Tasks/TaskList.class create mode 100644 src/main/out/production/main/Duke/Ui/Ui.class create mode 100644 src/main/out/production/main/out/production/main/Duke/.idea/.gitignore create mode 100644 src/main/out/production/main/out/production/main/Duke/.idea/artifacts/main_jar.xml create mode 100644 src/main/out/production/main/out/production/main/Duke/.idea/misc.xml create mode 100644 src/main/out/production/main/out/production/main/Duke/.idea/modules.xml create mode 100644 src/main/out/production/main/out/production/main/Duke/.idea/runConfigurations.xml create mode 100644 src/main/out/production/main/out/production/main/Duke/.idea/vcs.xml create mode 100644 src/main/out/production/main/out/production/main/Duke/META-INF/MANIFEST.MF diff --git a/src/main/java/.idea/.gitignore b/src/main/java/.idea/.gitignore new file mode 100644 index 000000000..73f69e095 --- /dev/null +++ b/src/main/java/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/src/main/java/.idea/artifacts/main_jar.xml b/src/main/java/.idea/artifacts/main_jar.xml new file mode 100644 index 000000000..161508e49 --- /dev/null +++ b/src/main/java/.idea/artifacts/main_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/out/artifacts/main_jar + + + + + \ No newline at end of file diff --git a/src/main/java/.idea/misc.xml b/src/main/java/.idea/misc.xml new file mode 100644 index 000000000..6dbc0d28c --- /dev/null +++ b/src/main/java/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/.idea/modules.xml b/src/main/java/.idea/modules.xml new file mode 100644 index 000000000..122a9054e --- /dev/null +++ b/src/main/java/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/java/.idea/runConfigurations.xml b/src/main/java/.idea/runConfigurations.xml new file mode 100644 index 000000000..797acea53 --- /dev/null +++ b/src/main/java/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/.idea/vcs.xml b/src/main/java/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/src/main/java/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/Duke/Parser/Parser.java b/src/main/java/Duke/Parser/Parser.java index d382d6c70..254d177e7 100644 --- a/src/main/java/Duke/Parser/Parser.java +++ b/src/main/java/Duke/Parser/Parser.java @@ -20,7 +20,8 @@ public Parser() { * @param input Input string from the user * @return Command Command class parsed from the input */ - public static Command parse(String input) throws DukeException { + public static Command parse(String inputString) throws DukeException { + String input = inputString.trim(); String findCommand = input.split(" ")[0]; if (input.trim().equals("bye")) { return new ExitCommand(); diff --git a/src/main/java/Duke/Ui/Ui.java b/src/main/java/Duke/Ui/Ui.java index 52a075977..314490684 100644 --- a/src/main/java/Duke/Ui/Ui.java +++ b/src/main/java/Duke/Ui/Ui.java @@ -31,7 +31,7 @@ public static final void showWelcome() { } public static final void showLine() { - System.out.println(" * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . *"); + System.out.println(" * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . *\n"); } public static final void printSuccessfulLoading() { diff --git a/src/main/java/out/production/main/Duke/.idea/.gitignore b/src/main/java/out/production/main/Duke/.idea/.gitignore new file mode 100644 index 000000000..73f69e095 --- /dev/null +++ b/src/main/java/out/production/main/Duke/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/src/main/java/out/production/main/Duke/.idea/artifacts/main_jar.xml b/src/main/java/out/production/main/Duke/.idea/artifacts/main_jar.xml new file mode 100644 index 000000000..161508e49 --- /dev/null +++ b/src/main/java/out/production/main/Duke/.idea/artifacts/main_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/out/artifacts/main_jar + + + + + \ No newline at end of file diff --git a/src/main/java/out/production/main/Duke/.idea/misc.xml b/src/main/java/out/production/main/Duke/.idea/misc.xml new file mode 100644 index 000000000..6dbc0d28c --- /dev/null +++ b/src/main/java/out/production/main/Duke/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/out/production/main/Duke/.idea/modules.xml b/src/main/java/out/production/main/Duke/.idea/modules.xml new file mode 100644 index 000000000..122a9054e --- /dev/null +++ b/src/main/java/out/production/main/Duke/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/java/out/production/main/Duke/.idea/runConfigurations.xml b/src/main/java/out/production/main/Duke/.idea/runConfigurations.xml new file mode 100644 index 000000000..797acea53 --- /dev/null +++ b/src/main/java/out/production/main/Duke/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/out/production/main/Duke/.idea/vcs.xml b/src/main/java/out/production/main/Duke/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/src/main/java/out/production/main/Duke/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/out/production/main/Duke/META-INF/MANIFEST.MF b/src/main/java/out/production/main/Duke/META-INF/MANIFEST.MF new file mode 100644 index 000000000..5699c7418 --- /dev/null +++ b/src/main/java/out/production/main/Duke/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Duke.Duke + diff --git a/src/main/out/production/main/.idea/.gitignore b/src/main/out/production/main/.idea/.gitignore new file mode 100644 index 000000000..73f69e095 --- /dev/null +++ b/src/main/out/production/main/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/src/main/out/production/main/.idea/artifacts/main_jar.xml b/src/main/out/production/main/.idea/artifacts/main_jar.xml new file mode 100644 index 000000000..161508e49 --- /dev/null +++ b/src/main/out/production/main/.idea/artifacts/main_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/out/artifacts/main_jar + + + + + \ No newline at end of file diff --git a/src/main/out/production/main/.idea/misc.xml b/src/main/out/production/main/.idea/misc.xml new file mode 100644 index 000000000..6dbc0d28c --- /dev/null +++ b/src/main/out/production/main/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/out/production/main/.idea/modules.xml b/src/main/out/production/main/.idea/modules.xml new file mode 100644 index 000000000..122a9054e --- /dev/null +++ b/src/main/out/production/main/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/out/production/main/.idea/runConfigurations.xml b/src/main/out/production/main/.idea/runConfigurations.xml new file mode 100644 index 000000000..797acea53 --- /dev/null +++ b/src/main/out/production/main/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/src/main/out/production/main/.idea/vcs.xml b/src/main/out/production/main/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/src/main/out/production/main/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/out/production/main/Duke/Command/DeleteCommand.class b/src/main/out/production/main/Duke/Command/DeleteCommand.class new file mode 100644 index 0000000000000000000000000000000000000000..a997d6540cec52fb734f278276ab034a304c2dae GIT binary patch literal 1254 zcmZ`&Yf}+mRmKO9*^QF!`Qi5E?>!R z7q)f^IB#mT=b?B8ft>N>{dB=L{o7VeyjJ+UNF;x!au_g$H7lp52DcBL$3Qp&_$hFt~e09uJ517XW3HSk{#1MhZMq+ zikfHJ1lF5W=w(&kGHtU(-LajtUMS`AA5}fyHCvq~PwRmA@1w3I!k;p)&ByFr$l+;OP&zTq`9-{pwJ(rlIwq+f>V zYd|?wJ~-OoZVxq;NCu1JxuR*T+qQWkVdrhQG8wcAj(JRB5WC#BD`v?m=4f?ew9R4M zhKd^`X(WX(MDp+@d4z_7CPL~cSBw#IoTLrHhUivP-w{g9ena?+#7xjROspVmgwQcU zPm(klpfQDMlE_Z7(jJq)8PfTj9l9fQ#~1e&QeP21MdSadDjtVh-RmHb- zREz1ibsWZbG<;W#uW5K)jBjZ8o*2Kc;Rj;;p@s`$d{f0m9S6j&Z{bHOeyrjr8ZPN* z!ete2Yq+A~r#hN(Rm0CT{9MH^bhP2BigyIAcQyP{#jkX9;j)Hbt9Vbx5i$LZc>BJF z6%8MV>2EdsPQ~wa^x&F?>l!}P@R5d96(8&9#WfY5DA2}+1H;dc438>MLJBJS5oTD1yx}yW)7w1C(Xo|F&U+%CLEtKqT@!w5^`GUv1hHMg4%E( zHD`8?7>T5rNDn;t$;qeg6|bJR{)v6-G0XGwp2e%^>hI@2Q;m0Pie zlArX>7D?vYR%D== zQPU>4u5Eymra5?-=mrRLThR%_yyX!yIhC*^S2?Q2;*q$52k(uhHxd!HIe%5zh>S>- zrKI4YZFvcpj(yHk(d4p%GD$wE4Nz?2_49sweDY*0^0iKh37no3N(TG}^N>Opkiw*oyK|}6bZh8U~_@p24 z$d-DiOHy!jgrO!)-;A|r`V3zzHE$*?b{U^cw{JS0@HLCzntfAFpYR<&>=zmNlY)ae z0HLjpmV!3d4zd5}xRB($^Dp+it>Bo;+ZK3b0$hj{9Cj^q!`RGzuPX;+v&WdCm>2+=i~x56*akN|Jk4)~1a7T_Iw37}(Jpz{{&D?}U= z2RPdis&i*!c=D_{Mc8?&%(vCUFEN`zt-mGjGnM{4vnM1MqLzqvv;O+rW-Cg~7gI)* z9b{Mj5(hv}%d-l06D3VRSh5DEq;72yfWPv*%X%1`CVU!)w) zlg0bNJb8%naGv}GH2UV(htJd8;Rr{CV@c~el#k_>qkQVz8mNQ^RT$&U>loo_j8iJZ zGx!oM=s-Ekv6#ABt!pR>x78G{!BgBl*hZ^bsxrE2>UONQ*VIUb)^-y+Db;4BU6ksw(tVV6XQe%q_GYDeO8c_X{?!c}pznrN zqA!Ms`V8*lb2myzS|#@Kubvn6edxe`9OEs%4-F*WM-Cck+r-b|L4Nw~M+%2<9uMGE zUgTec9~aSrOK8PAyvo0ac3fw2KS8Ht(&w;+2|UZaN^k?uai(y;Yxpu}MfeK!wb1{G zCKYG+f9KAf74jdR=Nk`go0tK9n4JvZHa&_AbhS$IJ>56q^F&UpV9($NnkH%vuH*hY z&h!B>-9Yn1{W|=sTrYCGgVBg_AER)1IKZDmz@yal@$E^};4!{^oGkP*!hnq9D6v=4 zeo_`!4J&2}5qjLunTcuXyGzCft|?2~iP*U6l#0fuR2=#oy5fq87mRI2)sl;fr7NOp z6H&F_E2QyZ4Dja&2rS~MAJ3VwvGp# zXiCYS$WbZl!kwcCbr#>6WPO@%XRwP5HefCrO(}PrlNBa@)jB!am6s!bI!6uk;@F8C zRiikR%Mpvvl_g&H((znK$Fn~ZPo-06-A)ikL=Z<;W%Ce0WWd+4cz`8>e~H>JsnpY_*m1bE=AktlJ5gWsE-K{Vcvt{! ztyf=QItEuzIV81TklO09dQW5xj|{D#>bOU~IPS#NGjX_m9VbL~>ev?=8CW|z#3R`N zyV)_pUZCQ2&fcKa1=_tu%Qty?FVgxF?XPgfW&UJ;n`h{%4E{9R^8s?YAUi=*I#0#4 zb+TAYYv+74rQfxQTDh)S+At5?_QL>Ps&zE*$1TTI;mJCWgn8Vk4V|4q+y+u-5?2T c4EHk^W%hqfSt?7Jv-W?XOu-@(QG|2<1}&6JF#rGn literal 0 HcmV?d00001 diff --git a/src/main/out/production/main/Duke/Tasks/TaskList.class b/src/main/out/production/main/Duke/Tasks/TaskList.class new file mode 100644 index 0000000000000000000000000000000000000000..e564876f484714a5de10687269cf323a66f2add5 GIT binary patch literal 3825 zcma)9YggRX72TQ{j|N#7&tPM0VrLRVc-kZljT;YkZG+ul^GGt-6eoR%nG47a(pb_^ zlO|2l#OWhR-;cz7eC115mz#FMYP?q4&;1AOKWSIfbl)q@AYj~fv5<7H&e><5bN0D{ zzyABD`I$7!l-NEJl)cx zwqpn9HFP$0D)isbkQ#H#L~Wb29Wh;7T@c=^wNT+sZqhATl^d34%XPGw3YKlfb62>C zXU9&T^=jR3uqlCNtR<&ppS)(4M4%GVaHOxlS=LN(p!u6-$QpFpzr0!v)>VX?8d{5i zRa%*{s!?_(BeDiFi$(htR)91nG#FLScIre@vQZkcd&Jcxa*L9YLSdI^hc#vFvWn$EEOJB&2(UStbuI45@OtkaTaChD5cT=7xp2o zu*&6Gx9n2$&4Ac`*26D(wn~yK+K&sXT%k-g^fvL?%UFsivA}L;=zMuiI7}>I@nRI+ znpYB6Y^n2BnUK`)X_>N#9-KDu7#`Qq-eed}tm7FSubB8cUe(YwyDajhn&%NbUm-}| z_VYq&>@h>fYbL&dNfWQ*4HIwTX%pYXTb#9B!(-xY+|_XKlIsS3;91ov5iGl9zb%b- zGWeE>Z{s^AzKeHFyoYx+oZRlsLuH{MucF9HLmtCBRvMm_?3HXKZMPQW-Nn2|xrw2C zmGbpPo_Pr`Z{^plid~Lu&z|a&WnyCQ%UXR8cXfQ<#1HU86F)oN@cG@!ww?s+Gbh|?ni_<1?m z90_5qa*V=u@7(4*sqwEkRFT~X(Xr#ysfQ+pzHIr^;tr#v9CbTXw^XAP@}^xTaKllQ z$3ZlW@nJLY6a17Q+UdN;<8Rek5o4}XvVu7~Smu)-SWduc@9mptqWisD%w5g(VR`oK zt|R%RJ+bPpaT?53%UcoUi+*^99H7^Dd=BGPRc8rvDY;Hy*$(M+#piNt+473wc1<`X zQRwG!o8%bon)j$6{Wo>|OzQlehVE^8wzKB)s}@!&%>Rm2Vw2Z({F0<6U3aBcCFu#r z5#CtE@_j)TAH-Qi7~x1gXF27H@Vi6DLaY*DjQGwD$60>L;x8lfmtqL@RAO5Z#F$m7 z6e*s9j$iRq-;-Z6ZW>PfcRL{V2~?1M({&?HVGE)bTjX4t#`kPTxdk17}jB(SFO+&>vxF z_z)-guwTPpU{2Gp>upUtwTae`*+)p9PyfE%+7r+TJ<9f-V@p4ePF%nUF5(NggsT`= z)bb=Sf_8ik&+@60^*W1!%IR7}SEk;IWXC6ruVeHdY+#mv^$ZG8w_6A1nswUXYorQEfNHs&~0UmTpg&%lkfBor_u&mUR;?)2AX?b@L&V)!Ee1)FwIx zH*w@c7(;T=Ik)lY-&pbboP?Ejkm0{KJ*eU-+@^qh3MWvM2bfAvBr2)ybB+3*qxha< z>KP8v1dpr)#RsOG`~+DYN$Tr~e{wUN->b~$8g&!S?^S}z{Bx?J4{&sTa0|yIIjQ(? z=t8yKq2Ib95*}o^M)(}2RQN2WF%#ilXJusL+9TYq`N5$rJkkvKRrdU~MpNk00B(Nic`Sem(eQKp0w3^9EpeUUy3Akk E9}62txBvhE literal 0 HcmV?d00001 diff --git a/src/main/out/production/main/Duke/Ui/Ui.class b/src/main/out/production/main/Duke/Ui/Ui.class new file mode 100644 index 0000000000000000000000000000000000000000..a04d42b6ba6ddee713a7e701a8434286b2433038 GIT binary patch literal 4936 zcmbtXd3V&-6~Dp;2{FaSK*EwH&n=5_z!O87wqpu`v5BX6D>Fc7Xr}V$*%sF5O(czB zsGIJ4(|t+z^#io|gY?jI`T_c(diuLh8hOSRoSxJ$PttpL`Q7E+ci+GN^Y~vx^l|#D zO=DCwskWDH(k+{I(QO`Hx9ASfe0Bs>Z`xF+&)amG9E+AMYFOl2BrRI8Xw{}Q@WYL#R z`ieIyo4x zd67Ydx#{-0EZ+3+f6AbJp>*7`YBrs~HR#aTnYnw;hEw#NV6|9{LoZkb(QYqjwPS-0 zCX4OZ^NZDn69h735z(5ue_Q$u)r9UrU#%*JkR!)pN=9qYGcCxDtL;WZM$t;!pHq$t zWdsX>m|SzB^{B|>6noE# z@y3J(9oRw8)pyMc+)U6ht#3iiJ8@$TU|CeQIHDJ)r7zGtmBeI zU?vPzXwY7sO5YEU?F=S+&}?>tv!AK2cD4++tEwF~USQ?u+~E^O%RGbb^SP?ImE1q*(Rfs3uGode;dQ zDK2#r7X8empBLyC^h=B0<;ecZpciy$OsioLdvO}Y(MP??3gmO!DP}g{?riz^_T`## zRknJxZ&lZ=Z0%UzT2e-`#UuTTs98@~nt9-Df$8VsO7;XUt_4q6;*!x_8hEEK&~2{E zkx(nb@%^q}qmpgAsnbfraa}mR`>iuV#7d`NZ=z1vV#x`eCMstbmBjQ+wS1$pRI4m5 zoE2B^)N7Ub8C%ReaGEV&mU_jlC+YlF+j}UA%NWX&zToBIme1+!sq$jzDknOE_(iQM43qtzH2O`jIhG<7v zK>f(k&>P9h!t~7RJ%%LO#3b}0hfCQ1;W`q80e7Y8!sSG$oq^nz7dxbZgk>#vAW9m} zwHJ|60nP(kR}|d@;=J2x)fSiUA)EWAs+}m7O@nrM0rwP|)>Fj_w}j{rrPD+Yh;}4z zLHAjKd=Mv1-+0_*QS~7?HjUM_Wk*9iXOGT7%TvfeTPMP!y3$ zAZ~r=b1}Y%uM2n@cxEV!*U8Nr@`{ce3tz=EaPB#5iF&AmZ2P$39uBwGL_FV zoWpV+EEm9Xkv^50e=T+NFnjqC9e51av7@(K%h!K`+XiusDBw8+Pi!T^FkPa{+NH1N z!#J1&V+t@X0>+hmmP0u#m%;KXSgt+=`QcpTWgwph@-mRm^dT>&$fxsRJd*=s7BD^y z7&A|S@oX-PdB9izjCsIV?1OPFh4C8Ara`&XACx1Hp|L+G$*#NsS=ByS6`6REuciTyD;dN_cBq`xyw@K{f71~d$5HJt>l2YJt}Q;$lI;eP>NmEC6m literal 0 HcmV?d00001 diff --git a/src/main/out/production/main/out/production/main/Duke/.idea/.gitignore b/src/main/out/production/main/out/production/main/Duke/.idea/.gitignore new file mode 100644 index 000000000..73f69e095 --- /dev/null +++ b/src/main/out/production/main/out/production/main/Duke/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/src/main/out/production/main/out/production/main/Duke/.idea/artifacts/main_jar.xml b/src/main/out/production/main/out/production/main/Duke/.idea/artifacts/main_jar.xml new file mode 100644 index 000000000..161508e49 --- /dev/null +++ b/src/main/out/production/main/out/production/main/Duke/.idea/artifacts/main_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/out/artifacts/main_jar + + + + + \ No newline at end of file diff --git a/src/main/out/production/main/out/production/main/Duke/.idea/misc.xml b/src/main/out/production/main/out/production/main/Duke/.idea/misc.xml new file mode 100644 index 000000000..6dbc0d28c --- /dev/null +++ b/src/main/out/production/main/out/production/main/Duke/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/out/production/main/out/production/main/Duke/.idea/modules.xml b/src/main/out/production/main/out/production/main/Duke/.idea/modules.xml new file mode 100644 index 000000000..122a9054e --- /dev/null +++ b/src/main/out/production/main/out/production/main/Duke/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/out/production/main/out/production/main/Duke/.idea/runConfigurations.xml b/src/main/out/production/main/out/production/main/Duke/.idea/runConfigurations.xml new file mode 100644 index 000000000..797acea53 --- /dev/null +++ b/src/main/out/production/main/out/production/main/Duke/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/src/main/out/production/main/out/production/main/Duke/.idea/vcs.xml b/src/main/out/production/main/out/production/main/Duke/.idea/vcs.xml new file mode 100644 index 000000000..c2365ab11 --- /dev/null +++ b/src/main/out/production/main/out/production/main/Duke/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/out/production/main/out/production/main/Duke/META-INF/MANIFEST.MF b/src/main/out/production/main/out/production/main/Duke/META-INF/MANIFEST.MF new file mode 100644 index 000000000..5699c7418 --- /dev/null +++ b/src/main/out/production/main/out/production/main/Duke/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Duke.Duke +