From 6eed652eac2aa2e0a5100b68dd95785d15279bcc Mon Sep 17 00:00:00 2001 From: JinYixuan-Au <506317808@qq.com> Date: Tue, 1 Sep 2020 23:09:48 +0800 Subject: [PATCH 01/13] level 0 --- src/main/java/Duke.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334cc..9203b61a2e 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,17 @@ public class Duke { public static void main(String[] args) { + String horizontalLine = "----------------------------------------"; String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + System.out.println(horizontalLine); + System.out.println(logo); + System.out.println("Hello! I'm Duke"); + System.out.println("What can I do for you?"); + System.out.println(horizontalLine); + System.out.println("Bye. Hope to see you again soon!"); + System.out.println(horizontalLine); } } From 77276db018c00d128bac2beb61b513133ee457c6 Mon Sep 17 00:00:00 2001 From: JinYixuan-Au <506317808@qq.com> Date: Thu, 3 Sep 2020 22:58:45 +0800 Subject: [PATCH 02/13] level 1 --- src/main/java/Duke.java | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 9203b61a2e..0fe1ef97a7 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,17 +1,22 @@ +import java.util.Scanner; public class Duke { + static String horizontalLine = "--------------------------------------------------"; + public static void main(String[] args) { - String horizontalLine = "----------------------------------------"; - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println(horizontalLine); - System.out.println(logo); - System.out.println("Hello! I'm Duke"); - System.out.println("What can I do for you?"); - System.out.println(horizontalLine); - System.out.println("Bye. Hope to see you again soon!"); - System.out.println(horizontalLine); + System.out.println(horizontalLine + "\nHello! I'm Duke\n" + "What can I do for you?\n" + horizontalLine); + echoCommand(); + } + + public static void echoCommand(){ + String command; + Scanner in = new Scanner(System.in); + command = in.nextLine(); + while(!command.equals("bye")){ + System.out.println(horizontalLine); + System.out.println(command); + System.out.println(horizontalLine); + command = in.nextLine(); + } + System.out.println(horizontalLine +"\nBye. Hope to see you again soon\n"+ horizontalLine); } } From b1251c08b45db5cf1474fe6fc8cace3e850da8b8 Mon Sep 17 00:00:00 2001 From: JinYixuan-Au <506317808@qq.com> Date: Thu, 3 Sep 2020 23:16:13 +0800 Subject: [PATCH 03/13] level 2 Add, List --- src/main/java/Duke.java | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 0fe1ef97a7..3b50b32d57 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,22 +1,39 @@ import java.util.Scanner; public class Duke { static String horizontalLine = "--------------------------------------------------"; + static String[] thingsToDo = new String[100]; + static int thingsCounted = 0; public static void main(String[] args) { System.out.println(horizontalLine + "\nHello! I'm Duke\n" + "What can I do for you?\n" + horizontalLine); - echoCommand(); + storeTextAndList(); } - public static void echoCommand(){ - String command; + public static void storeTextAndList() { + String text; Scanner in = new Scanner(System.in); - command = in.nextLine(); - while(!command.equals("bye")){ - System.out.println(horizontalLine); - System.out.println(command); - System.out.println(horizontalLine); - command = in.nextLine(); + text = in.nextLine(); + while (!text.equals("bye")) { + if (text.equals("list")) { + System.out.println(horizontalLine); + int count = 0; + for (count = 0; count < thingsCounted; count++) { + System.out.print(String.format("%d. ", count + 1)); + System.out.println(thingsToDo[count]); + } + System.out.println(horizontalLine); + } else { + System.out.println(horizontalLine); + System.out.println("added: " + text); + System.out.println(horizontalLine); + thingsToDo[thingsCounted] = text; + thingsCounted++; + } + text = in.nextLine(); } - System.out.println(horizontalLine +"\nBye. Hope to see you again soon\n"+ horizontalLine); + System.out.println(horizontalLine); + System.out.println("Bye. Hope to see you again soon"); + System.out.println(horizontalLine); } } + From f003111df477443388c24283b3c6e6f6952fb4d4 Mon Sep 17 00:00:00 2001 From: JinYixuan-Au <506317808@qq.com> Date: Fri, 4 Sep 2020 00:03:53 +0800 Subject: [PATCH 04/13] level 3 Mark as Done --- src/main/java/Duke.java | 25 +++++++++++++++++++------ src/main/java/Task.java | 21 +++++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 3b50b32d57..9d72ffb314 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,8 +1,10 @@ +import java.util.Arrays; import java.util.Scanner; public class Duke { static String horizontalLine = "--------------------------------------------------"; static String[] thingsToDo = new String[100]; static int thingsCounted = 0; + static Task [] tasks=new Task[100]; public static void main(String[] args) { System.out.println(horizontalLine + "\nHello! I'm Duke\n" + "What can I do for you?\n" + horizontalLine); @@ -14,26 +16,37 @@ public static void storeTextAndList() { Scanner in = new Scanner(System.in); text = in.nextLine(); while (!text.equals("bye")) { + System.out.println(horizontalLine); if (text.equals("list")) { - System.out.println(horizontalLine); int count = 0; for (count = 0; count < thingsCounted; count++) { - System.out.print(String.format("%d. ", count + 1)); - System.out.println(thingsToDo[count]); + System.out.print(String.format("%d. ",count+1)); + System.out.println(tasks[count].getStatusIcon() + thingsToDo[count]); } System.out.println(horizontalLine); - } else { - System.out.println(horizontalLine); + } + else if(text.contains("done")){ + int index = Integer.parseInt(text.substring(5)); + doneTask(index); + } + else { System.out.println("added: " + text); - System.out.println(horizontalLine); thingsToDo[thingsCounted] = text; + Task task = new Task(text); + tasks[thingsCounted] = task; thingsCounted++; } + System.out.println(horizontalLine); text = in.nextLine(); } System.out.println(horizontalLine); System.out.println("Bye. Hope to see you again soon"); System.out.println(horizontalLine); } + + public static void doneTask(int index){ + tasks[index-1].taskDone(); + System.out.println("Nice! I've marked this task as done:\n" +tasks[index-1].getStatusIcon()+thingsToDo[index-1]); + } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 0000000000..45402aa367 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,21 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getStatusIcon() { + return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols + } + + public void taskDone(){ + this.isDone=true; + } +} From 12431e78b3aa675b4e24a34df04455c8872aab0d Mon Sep 17 00:00:00 2001 From: JinYixuan-Au <506317808@qq.com> Date: Fri, 4 Sep 2020 00:06:14 +0800 Subject: [PATCH 05/13] A-CodingStandard --- 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 9d72ffb314..7fcac0cc4d 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -21,7 +21,7 @@ public static void storeTextAndList() { int count = 0; for (count = 0; count < thingsCounted; count++) { System.out.print(String.format("%d. ",count+1)); - System.out.println(tasks[count].getStatusIcon() + thingsToDo[count]); + System.out.println('[' + tasks[count].getStatusIcon() + ']' + thingsToDo[count]); } System.out.println(horizontalLine); } From e19078da7bd34eb1ea0ebc434c9b9c6f9712ddc7 Mon Sep 17 00:00:00 2001 From: JinYixuan-Au <506317808@qq.com> Date: Fri, 4 Sep 2020 00:56:32 +0800 Subject: [PATCH 06/13] level 4 --- src/main/java/Deadline.java | 17 ++++++++ src/main/java/Duke.java | 80 +++++++++++++++++++++++++++---------- src/main/java/Event.java | 16 ++++++++ src/main/java/Todo.java | 13 ++++++ 4 files changed, 106 insertions(+), 20 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/Todo.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 0000000000..8192784507 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,17 @@ +public class Deadline extends Task { + + protected String byDate; + + public Deadline(String description, String byDate) { + super(description); + this.byDate=byDate; + } + + public String getTypeIcon(){ + return "[D]"; + } + + public String toString(){ + return this.getTypeIcon() + this.getStatusIcon() + description + "(by: " + byDate + ")"; + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 7fcac0cc4d..da90721c7a 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,9 +2,8 @@ import java.util.Scanner; public class Duke { static String horizontalLine = "--------------------------------------------------"; - static String[] thingsToDo = new String[100]; static int thingsCounted = 0; - static Task [] tasks=new Task[100]; + static Task[] tasks = new Task[100]; public static void main(String[] args) { System.out.println(horizontalLine + "\nHello! I'm Duke\n" + "What can I do for you?\n" + horizontalLine); @@ -20,33 +19,74 @@ public static void storeTextAndList() { if (text.equals("list")) { int count = 0; for (count = 0; count < thingsCounted; count++) { - System.out.print(String.format("%d. ",count+1)); - System.out.println('[' + tasks[count].getStatusIcon() + ']' + thingsToDo[count]); + System.out.print(count + 1 + '.'); + System.out.println(tasks[count]); } System.out.println(horizontalLine); - } - else if(text.contains("done")){ + } else if (text.contains("done")) { int index = Integer.parseInt(text.substring(5)); doneTask(index); - } - else { - System.out.println("added: " + text); - thingsToDo[thingsCounted] = text; - Task task = new Task(text); - tasks[thingsCounted] = task; - thingsCounted++; + } else { + if (text.contains("todo")) { + addTodoTask(text); + } else if (text.contains("deadline")) { + addDeadlineTask(text); + } else { + addEventTask(text); + } + System.out.println(horizontalLine); + text = in.nextLine(); } System.out.println(horizontalLine); - text = in.nextLine(); + System.out.println("Bye. Hope to see you again soon"); + System.out.println(horizontalLine); } - System.out.println(horizontalLine); - System.out.println("Bye. Hope to see you again soon"); - System.out.println(horizontalLine); } + public static void addTodoTask(String text){ + String todoDescription; + todoDescription = text.substring(5); + Task task = new Todo(todoDescription); + tasks[thingsCounted] = task; + thingsCounted++; + printTask(task); + } + + public static void addDeadlineTask(String text){ + String deadlineDescription; + String deadlineByDate; + int getIndex; + getIndex = text.indexOf("/"); + deadlineDescription = text.substring(9, getIndex - 1); + deadlineByDate = text.substring(getIndex + 4); + Task task = new Deadline(deadlineDescription, deadlineByDate); + tasks[thingsCounted] = task; + thingsCounted++; + printTask(task); + } + + public static void addEventTask(String text){ + String eventDescription; + String eventAtDate; + int getIndex; + getIndex = text.indexOf("/"); + eventDescription = text.substring(6, getIndex - 1); + eventAtDate = text.substring(getIndex + 4); + Task task = new Event(eventDescription, eventAtDate); + tasks[thingsCounted] = task; + thingsCounted++; + printTask(task); + } + + public static void printTask(Task task){ + System.out.println("Got it. I've added this task: "); + System.out.println(task); + System.out.println("Now you have " + thingsCounted + " tasks in the list."); + } + + public static void doneTask(int index){ - tasks[index-1].taskDone(); - System.out.println("Nice! I've marked this task as done:\n" +tasks[index-1].getStatusIcon()+thingsToDo[index-1]); + tasks[index - 1].taskDone(); + System.out.println("Nice! I've marked this task as done:\n" + tasks[index - 1]); } } - diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 0000000000..6e705c8788 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,16 @@ +public class Event extends Task{ + protected String atDate; + + public Event(String description, String atDate) { + super(description); + this.atDate=atDate; + } + + public String getTypeIcon(){ + return "[D]"; + } + + public String toString(){ + return this.getTypeIcon() + this.getStatusIcon() + description + " (at: " + atDate + ")"; + } +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 0000000000..341048617b --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,13 @@ +public class Todo extends Task{ + public Todo(String description) { + super(description); + } + + public String getTypeIcon(){ + return "[T]"; + } + + public String toString(){ + return this.getTypeIcon() + this.getStatusIcon() + description; + } +} From 93cdea99fef218046e9e12609ddd84c2afa1942c Mon Sep 17 00:00:00 2001 From: JinYixuan-Au <506317808@qq.com> Date: Fri, 2 Oct 2020 01:52:01 +0800 Subject: [PATCH 07/13] Improve Code Quality --- src/main/java/Deadline.java | 2 +- src/main/java/Duke.java | 28 ++++++++++++++++------------ src/main/java/Task.java | 6 +++++- src/main/java/Todo.java | 1 + 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 8192784507..2ae45b1e1e 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -12,6 +12,6 @@ public String getTypeIcon(){ } public String toString(){ - return this.getTypeIcon() + this.getStatusIcon() + description + "(by: " + byDate + ")"; + return this.getTypeIcon() + this.getStatusIcon() + description + " (by: " + byDate + ")"; } } diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index da90721c7a..0b714b322f 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -5,11 +5,6 @@ public class Duke { static int thingsCounted = 0; static Task[] tasks = new Task[100]; - public static void main(String[] args) { - System.out.println(horizontalLine + "\nHello! I'm Duke\n" + "What can I do for you?\n" + horizontalLine); - storeTextAndList(); - } - public static void storeTextAndList() { String text; Scanner in = new Scanner(System.in); @@ -17,12 +12,7 @@ public static void storeTextAndList() { while (!text.equals("bye")) { System.out.println(horizontalLine); if (text.equals("list")) { - int count = 0; - for (count = 0; count < thingsCounted; count++) { - System.out.print(count + 1 + '.'); - System.out.println(tasks[count]); - } - System.out.println(horizontalLine); + listTask(); } else if (text.contains("done")) { int index = Integer.parseInt(text.substring(5)); doneTask(index); @@ -89,4 +79,18 @@ public static void doneTask(int index){ tasks[index - 1].taskDone(); System.out.println("Nice! I've marked this task as done:\n" + tasks[index - 1]); } -} + + public static void listTask(){ + System.out.println(horizontalLine); + System.out.println("Here are the tasks in your list:"); + for (int count = 0; count < thingsCounted; count++) { + System.out.println((count+1)+"."+tasks[count]); + } + System.out.println(horizontalLine); + } + + public static void main(String[] args) { + System.out.println(horizontalLine + "\nHello! I'm Duke\n" + "What can I do for you?\n" + horizontalLine); + storeTextAndList(); + } +} \ No newline at end of file diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 45402aa367..857bae1654 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -12,10 +12,14 @@ public void setDescription(String description) { } public String getStatusIcon() { - return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols + return (isDone ? "[\u2713]" : "[\u2718]"); //return tick or X symbols } public void taskDone(){ this.isDone=true; } + + public String toString(){ + return this.getStatusIcon() + description; + } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 341048617b..0f9375a016 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -1,4 +1,5 @@ public class Todo extends Task{ + public Todo(String description) { super(description); } From 8c3c84ee14a9c679bf3e9c1849808755c0cd54d1 Mon Sep 17 00:00:00 2001 From: JinYixuan-Au <506317808@qq.com> Date: Fri, 2 Oct 2020 02:06:25 +0800 Subject: [PATCH 08/13] add input, add expected output, change runtest.bat, change runtest.sh --- text-ui-test/EXPECTED.TXT | 40 +++++++++++++++++++++++++++++++++------ text-ui-test/input.txt | 7 +++++++ text-ui-test/runtest.bat | 2 +- text-ui-test/runtest.sh | 6 +----- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e7..d59bbf4a29 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,35 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| +____________________________________________________________ + Hello! I'm Duke + What can I do for you? +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[T][✘]borrow book +Now you have 1 tasks in the list. +____________________________________________________________ +____________________________________________________________ +1. [T][✘]borrow book +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[D][✘]return book (by: Sunday) +Now you have 2 tasks in the list. +____________________________________________________________ +____________________________________________________________ +Got it. I've added this task: +[D][✘]project (at: Mon 2-4pm) +Now you have 3 tasks in the list. +____________________________________________________________ +____________________________________________________________ +1. [T][✘]borrow book +2. [D][✘]return book (by: Sunday) +3. [D][✘]project (at: Mon 2-4pm) +____________________________________________________________ +____________________________________________________________ +Nice! I've marked this task as done: +[D][✓]return book (by: Sunday) +____________________________________________________________ +____________________________________________________________ +Bye. Hope to see you again soon +____________________________________________________________ \ No newline at end of file diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb2..55eb8a0066 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,7 @@ +todo borrow book +list +deadline return book /by Sunday +event project /at Mon 2-4pm +list +done 2 +bye \ No newline at end of file diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index d0facc6310..4279957574 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -7,7 +7,7 @@ REM delete output from previous run del ACTUAL.TXT REM compile the code into the bin folder -javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\Duke.java +javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\*.java IF ERRORLEVEL 1 ( echo ********** BUILD FAILURE ********** exit /b 1 diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index e169618a34..511030134f 100644 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -13,7 +13,7 @@ then fi # compile the code into the bin folder, terminates if error occurred -if ! javac -cp ../src -Xlint:none -d ../bin ../src/main/java/Duke.java +if ! javac -cp ../src -Xlint:none -d ../bin ../src/main/java/*.java then echo "********** BUILD FAILURE **********" exit 1 @@ -22,10 +22,6 @@ fi # run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT java -classpath ../bin Duke < input.txt > ACTUAL.TXT -# convert to UNIX format -cp EXPECTED.TXT EXPECTED-UNIX.TXT -dos2unix ACTUAL.TXT EXPECTED-UNIX.TXT - # compare the output to the expected output diff ACTUAL.TXT EXPECTED-UNIX.TXT if [ $? -eq 0 ] From f4159dab70edac368b00e610653e90176b6c2f09 Mon Sep 17 00:00:00 2001 From: JinYixuan-Au <506317808@qq.com> Date: Fri, 2 Oct 2020 02:39:41 +0800 Subject: [PATCH 09/13] add exception --- src/main/java/Duke.java | 64 ++++++++++++++++++++++++-------- src/main/java/DukeException.java | 3 ++ src/main/java/Event.java | 2 +- 3 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 src/main/java/DukeException.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 0b714b322f..8c6e321440 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -5,36 +5,62 @@ public class Duke { static int thingsCounted = 0; static Task[] tasks = new Task[100]; - public static void storeTextAndList() { + public static void storeTextAndList() throws DukeException{ String text; Scanner in = new Scanner(System.in); text = in.nextLine(); while (!text.equals("bye")) { System.out.println(horizontalLine); - if (text.equals("list")) { - listTask(); - } else if (text.contains("done")) { - int index = Integer.parseInt(text.substring(5)); - doneTask(index); - } else { - if (text.contains("todo")) { - addTodoTask(text); - } else if (text.contains("deadline")) { - addDeadlineTask(text); + try { + if (text.equals("list")) { + listTask(); + } else if (text.contains("done")) { + int index = Integer.parseInt(text.substring(5)); + doneTask(index); } else { - addEventTask(text); + if (text.contains("todo")) { + addTodoTask(text); + } else if (text.contains("deadline")) { + addDeadlineTask(text); + } else if (text.contains("event")) { + addEventTask(text); + } else { + throw new DukeException(); + } } + }catch (DukeException e) { + dealWithException(text); + } System.out.println(horizontalLine); text = in.nextLine(); } System.out.println(horizontalLine); System.out.println("Bye. Hope to see you again soon"); System.out.println(horizontalLine); + } + + public static void dealWithException(String text){ + switch (text) { + case "todo": + System.out.println("The description of a todo cannot be empty."); + break; + case "deadline": + System.out.println("The description of a deadline cannot be empty."); + break; + case "event": + System.out.println("The description of a event cannot be empty."); + break; + default: + System.out.println(("Sorry, I don't know what this means.")); + break; } } - public static void addTodoTask(String text){ + public static void addTodoTask(String text) throws DukeException{ String todoDescription; + if(text.equals("todo")){ + throw new DukeException(); + } todoDescription = text.substring(5); Task task = new Todo(todoDescription); tasks[thingsCounted] = task; @@ -42,10 +68,13 @@ public static void addTodoTask(String text){ printTask(task); } - public static void addDeadlineTask(String text){ + public static void addDeadlineTask (String text) throws DukeException{ String deadlineDescription; String deadlineByDate; int getIndex; + if(text.equals("deadline")){ + throw new DukeException(); + } getIndex = text.indexOf("/"); deadlineDescription = text.substring(9, getIndex - 1); deadlineByDate = text.substring(getIndex + 4); @@ -55,10 +84,13 @@ public static void addDeadlineTask(String text){ printTask(task); } - public static void addEventTask(String text){ + public static void addEventTask(String text) throws DukeException{ String eventDescription; String eventAtDate; int getIndex; + if(text.equals("event")){ + throw new DukeException(); + } getIndex = text.indexOf("/"); eventDescription = text.substring(6, getIndex - 1); eventAtDate = text.substring(getIndex + 4); @@ -89,7 +121,7 @@ public static void listTask(){ System.out.println(horizontalLine); } - public static void main(String[] args) { + public static void main(String[] args) throws DukeException{ System.out.println(horizontalLine + "\nHello! I'm Duke\n" + "What can I do for you?\n" + horizontalLine); storeTextAndList(); } diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java new file mode 100644 index 0000000000..5e322ffd47 --- /dev/null +++ b/src/main/java/DukeException.java @@ -0,0 +1,3 @@ +public class DukeException extends Exception { + +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 6e705c8788..53963e1c06 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -7,7 +7,7 @@ public Event(String description, String atDate) { } public String getTypeIcon(){ - return "[D]"; + return "[E]"; } public String toString(){ From 771f5b6229bc6d9c12f3aa5fd7562cd2aa5f13a0 Mon Sep 17 00:00:00 2001 From: JinYixuan-Au <506317808@qq.com> Date: Fri, 2 Oct 2020 02:47:35 +0800 Subject: [PATCH 10/13] level 5 --- src/main/java/Duke.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 8c6e321440..1835546933 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -42,16 +42,16 @@ public static void storeTextAndList() throws DukeException{ public static void dealWithException(String text){ switch (text) { case "todo": - System.out.println("The description of a todo cannot be empty."); + System.out.println("☹ OOPS!!! The description of a todo cannot be empty."); break; case "deadline": - System.out.println("The description of a deadline cannot be empty."); + System.out.println("☹ OOPS!!! The description of a deadline cannot be empty."); break; case "event": - System.out.println("The description of a event cannot be empty."); + System.out.println("☹ OOPS!!! The description of a event cannot be empty."); break; default: - System.out.println(("Sorry, I don't know what this means.")); + System.out.println(("☹ OOPS!!! I'm sorry, but I don't know what that means :-(")); break; } } From d72262932d310a36b480591348725b4932cbb33a Mon Sep 17 00:00:00 2001 From: JinYixuan-Au <506317808@qq.com> Date: Fri, 2 Oct 2020 14:28:06 +0800 Subject: [PATCH 11/13] Add branch A-Package --- README.md | 4 ++-- src/main/java/{ => duke}/Duke.java | 22 ++++++++++++++------- src/main/java/{ => duke}/DukeException.java | 2 ++ src/main/java/{ => duke/task}/Deadline.java | 2 ++ src/main/java/{ => duke/task}/Event.java | 2 ++ src/main/java/{ => duke/task}/Task.java | 2 ++ src/main/java/{ => duke/task}/Todo.java | 2 ++ text-ui-test/EXPECTED.TXT | 2 +- text-ui-test/runtest.bat | 2 +- 9 files changed, 29 insertions(+), 11 deletions(-) rename src/main/java/{ => duke}/Duke.java (91%) rename src/main/java/{ => duke}/DukeException.java (76%) rename src/main/java/{ => duke/task}/Deadline.java (95%) rename src/main/java/{ => duke/task}/Event.java (94%) rename src/main/java/{ => duke/task}/Task.java (96%) rename src/main/java/{ => duke/task}/Todo.java (93%) diff --git a/README.md b/README.md index 9d95025bce..da61b7869f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Duke project template +# duke project template This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. @@ -15,7 +15,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version. 1. Click `Open or Import`. 1. Select the project directory, and click `OK` 1. If there are any further prompts, accept the defaults. -1. After the importing is complete, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()`. If the setup is correct, you should see something like the below: +1. After the importing is complete, locate the `src/main/java/duke.java` file, right-click it, and choose `Run duke.main()`. If the setup is correct, you should see something like the below: ``` Hello from ____ _ diff --git a/src/main/java/Duke.java b/src/main/java/duke/Duke.java similarity index 91% rename from src/main/java/Duke.java rename to src/main/java/duke/Duke.java index 1835546933..62b3890cb2 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,11 +1,18 @@ -import java.util.Arrays; +package duke; + +import duke.task.Deadline; +import duke.task.Event; +import duke.task.Task; +import duke.task.Todo; + import java.util.Scanner; + public class Duke { static String horizontalLine = "--------------------------------------------------"; static int thingsCounted = 0; static Task[] tasks = new Task[100]; - public static void storeTextAndList() throws DukeException{ + public static void storeTextAndList() throws DukeException { String text; Scanner in = new Scanner(System.in); text = in.nextLine(); @@ -56,7 +63,7 @@ public static void dealWithException(String text){ } } - public static void addTodoTask(String text) throws DukeException{ + public static void addTodoTask(String text) throws DukeException { String todoDescription; if(text.equals("todo")){ throw new DukeException(); @@ -68,7 +75,7 @@ public static void addTodoTask(String text) throws DukeException{ printTask(task); } - public static void addDeadlineTask (String text) throws DukeException{ + public static void addDeadlineTask (String text) throws DukeException { String deadlineDescription; String deadlineByDate; int getIndex; @@ -84,7 +91,7 @@ public static void addDeadlineTask (String text) throws DukeException{ printTask(task); } - public static void addEventTask(String text) throws DukeException{ + public static void addEventTask(String text) throws DukeException { String eventDescription; String eventAtDate; int getIndex; @@ -121,8 +128,9 @@ public static void listTask(){ System.out.println(horizontalLine); } - public static void main(String[] args) throws DukeException{ - System.out.println(horizontalLine + "\nHello! I'm Duke\n" + "What can I do for you?\n" + horizontalLine); + public static void main(String[] args) throws DukeException { + System.out.println(horizontalLine + "\nHello! I'm Duke.Duke\n" + "What can I do for you?\n" + horizontalLine); storeTextAndList(); } + } \ No newline at end of file diff --git a/src/main/java/DukeException.java b/src/main/java/duke/DukeException.java similarity index 76% rename from src/main/java/DukeException.java rename to src/main/java/duke/DukeException.java index 5e322ffd47..e7ae283939 100644 --- a/src/main/java/DukeException.java +++ b/src/main/java/duke/DukeException.java @@ -1,3 +1,5 @@ +package duke; + public class DukeException extends Exception { } diff --git a/src/main/java/Deadline.java b/src/main/java/duke/task/Deadline.java similarity index 95% rename from src/main/java/Deadline.java rename to src/main/java/duke/task/Deadline.java index 2ae45b1e1e..d5a7c84ed4 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,3 +1,5 @@ +package duke.task; + public class Deadline extends Task { protected String byDate; diff --git a/src/main/java/Event.java b/src/main/java/duke/task/Event.java similarity index 94% rename from src/main/java/Event.java rename to src/main/java/duke/task/Event.java index 53963e1c06..882bffa9a5 100644 --- a/src/main/java/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,3 +1,5 @@ +package duke.task; + public class Event extends Task{ protected String atDate; diff --git a/src/main/java/Task.java b/src/main/java/duke/task/Task.java similarity index 96% rename from src/main/java/Task.java rename to src/main/java/duke/task/Task.java index 857bae1654..96f37f5916 100644 --- a/src/main/java/Task.java +++ b/src/main/java/duke/task/Task.java @@ -1,3 +1,5 @@ +package duke.task; + public class Task { protected String description; protected boolean isDone; diff --git a/src/main/java/Todo.java b/src/main/java/duke/task/Todo.java similarity index 93% rename from src/main/java/Todo.java rename to src/main/java/duke/task/Todo.java index 0f9375a016..0176ab6def 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/duke/task/Todo.java @@ -1,3 +1,5 @@ +package duke.task; + public class Todo extends Task{ public Todo(String description) { diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index d59bbf4a29..eeef2799e6 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,5 +1,5 @@ ____________________________________________________________ - Hello! I'm Duke + Hello! I'm duke What can I do for you? ____________________________________________________________ diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 4279957574..7e25983237 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -classpath ..\bin duke < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT From 1b5ae0ad6b3eebd69d24ee7728f47a0f364b5deb Mon Sep 17 00:00:00 2001 From: JinYixuan-Au <506317808@qq.com> Date: Fri, 2 Oct 2020 14:53:12 +0800 Subject: [PATCH 12/13] code quality --- src/main/java/duke/Duke.java | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 62b3890cb2..356a9f0d14 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -13,33 +13,34 @@ public class Duke { static Task[] tasks = new Task[100]; public static void storeTextAndList() throws DukeException { - String text; + String command; Scanner in = new Scanner(System.in); - text = in.nextLine(); - while (!text.equals("bye")) { + command = in.nextLine(); + while (!command.equals("bye")) { System.out.println(horizontalLine); try { - if (text.equals("list")) { + if (command.equals("list")) { listTask(); - } else if (text.contains("done")) { - int index = Integer.parseInt(text.substring(5)); - doneTask(index); - } else { - if (text.contains("todo")) { - addTodoTask(text); - } else if (text.contains("deadline")) { - addDeadlineTask(text); - } else if (text.contains("event")) { - addEventTask(text); - } else { + } else if (command.contains("done")) { + int index = Integer.parseInt(command.substring(5)); + if(index > thingsCounted){ throw new DukeException(); } + doneTask(index); + } else if (command.contains("todo")) { + addTodoTask(command); + } else if (command.contains("deadline")) { + addDeadlineTask(command); + } else if (command.contains("event")) { + addEventTask(command); + } else { + throw new DukeException(); } }catch (DukeException e) { - dealWithException(text); + dealWithException(command); } System.out.println(horizontalLine); - text = in.nextLine(); + command = in.nextLine(); } System.out.println(horizontalLine); System.out.println("Bye. Hope to see you again soon"); @@ -129,8 +130,7 @@ public static void listTask(){ } public static void main(String[] args) throws DukeException { - System.out.println(horizontalLine + "\nHello! I'm Duke.Duke\n" + "What can I do for you?\n" + horizontalLine); + System.out.println(horizontalLine + "\nHello! I'm Duke\n" + "What can I do for you?\n" + horizontalLine); storeTextAndList(); } - } \ No newline at end of file From a1ad436eb75d6425d0627fdb59963ec210dd3639 Mon Sep 17 00:00:00 2001 From: JinYixuan-Au <506317808@qq.com> Date: Fri, 2 Oct 2020 15:08:33 +0800 Subject: [PATCH 13/13] level 6 --- src/main/java/duke/Duke.java | 42 +++++++++++++++++++++++++++--------- text-ui-test/runtest.bat | 2 +- text-ui-test/runtest.sh | 6 +++--- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 356a9f0d14..b6a9712220 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -6,11 +6,13 @@ import duke.task.Todo; import java.util.Scanner; +import java.util.ArrayList; public class Duke { static String horizontalLine = "--------------------------------------------------"; static int thingsCounted = 0; - static Task[] tasks = new Task[100]; + //static Task[] tasks = new Task[100]; + public static ArrayList taskArray = new ArrayList<>(); public static void storeTextAndList() throws DukeException { String command; @@ -26,13 +28,19 @@ public static void storeTextAndList() throws DukeException { if(index > thingsCounted){ throw new DukeException(); } - doneTask(index); + markTaskAsDone(index); } else if (command.contains("todo")) { addTodoTask(command); } else if (command.contains("deadline")) { addDeadlineTask(command); } else if (command.contains("event")) { addEventTask(command); + } else if (command.contains("delete")){ + int index = Integer.parseInt(command.substring(7)); + if(index > thingsCounted){ + throw new DukeException(); + } + deleteItem(index); } else { throw new DukeException(); } @@ -71,8 +79,9 @@ public static void addTodoTask(String text) throws DukeException { } todoDescription = text.substring(5); Task task = new Todo(todoDescription); - tasks[thingsCounted] = task; + //tasks[thingsCounted] = task; thingsCounted++; + taskArray.add(task); printTask(task); } @@ -87,8 +96,9 @@ public static void addDeadlineTask (String text) throws DukeException { deadlineDescription = text.substring(9, getIndex - 1); deadlineByDate = text.substring(getIndex + 4); Task task = new Deadline(deadlineDescription, deadlineByDate); - tasks[thingsCounted] = task; + //tasks[thingsCounted] = task; thingsCounted++; + taskArray.add(task); printTask(task); } @@ -103,8 +113,9 @@ public static void addEventTask(String text) throws DukeException { eventDescription = text.substring(6, getIndex - 1); eventAtDate = text.substring(getIndex + 4); Task task = new Event(eventDescription, eventAtDate); - tasks[thingsCounted] = task; + //tasks[thingsCounted] = task; thingsCounted++; + taskArray.add(task); printTask(task); } @@ -115,16 +126,27 @@ public static void printTask(Task task){ } - public static void doneTask(int index){ - tasks[index - 1].taskDone(); - System.out.println("Nice! I've marked this task as done:\n" + tasks[index - 1]); + public static void markTaskAsDone(int index){ + taskArray.get(index-1).taskDone(); + System.out.println("Nice! I've marked this task as done:\n" +taskArray.get(index-1)); + } + + private static void deleteItem(int index) { + Task task = taskArray.remove(index - 1); + System.out.println("Noted. I've removed this task: "); + System.out.println(task); + thingsCounted--; + System.out.println("Now you have " + thingsCounted + " tasks in the list."); } public static void listTask(){ System.out.println(horizontalLine); System.out.println("Here are the tasks in your list:"); - for (int count = 0; count < thingsCounted; count++) { - System.out.println((count+1)+"."+tasks[count]); + int count = 1; + for(Task task : taskArray){ + System.out.print(count + ". "); + System.out.println(task); + count++; } System.out.println(horizontalLine); } diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 7e25983237..1f3b5a5233 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin duke < input.txt > ACTUAL.TXT +java -classpath ..\bin duke.Duke < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index 511030134f..d3aaadd290 100644 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -13,17 +13,17 @@ then fi # compile the code into the bin folder, terminates if error occurred -if ! javac -cp ../src -Xlint:none -d ../bin ../src/main/java/*.java +if ! javac -cp ../src -Xlint:none -d ../bin ../src/main/java/duke/*.java then echo "********** BUILD FAILURE **********" exit 1 fi # run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ../bin Duke < input.txt > ACTUAL.TXT +java -classpath ../bin duke/Duke < input.txt > ACTUAL.TXT # compare the output to the expected output -diff ACTUAL.TXT EXPECTED-UNIX.TXT +diff ACTUAL.TXT EXPECTED.TXT if [ $? -eq 0 ] then echo "Test result: PASSED"