From 81177c6dc209a64543d033fea08bd8dc4339ed51 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Wed, 15 Sep 2021 14:36:06 +0800 Subject: [PATCH 01/24] Add Increment: Level 0. Greet --- src/main/java/Duke.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..61a0a2760 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -6,5 +6,10 @@ public static void main(String[] args) { + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); + System.out.println("..................................................."); + System.out.println("Hello! I'm Duke\n" + "What can I do for you?"); + System.out.println("..................................................."); + System.out.println("Bye. Hope to see you again soon!"); + System.out.println("..................................................."); } } From a2179d660800c97c372320997703cf85abdd20bb Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Thu, 16 Sep 2021 05:52:07 +0800 Subject: [PATCH 02/24] Add Increment: Level 1. Greet, Echo, Exit --- src/main/java/Duke.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 61a0a2760..6c15551dc 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" @@ -9,6 +10,14 @@ public static void main(String[] args) { System.out.println("..................................................."); System.out.println("Hello! I'm Duke\n" + "What can I do for you?"); System.out.println("..................................................."); + Scanner in = new Scanner(System.in); + String lineIn = ""; + do{ + lineIn = in.nextLine(); + System.out.println("..................................................."); + System.out.println(lineIn); + System.out.println("..................................................."); + } while(!lineIn.equals("bye")); System.out.println("Bye. Hope to see you again soon!"); System.out.println("..................................................."); } From 7bd305c08a151a863609ea83f01c0e8c11b631de Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Thu, 16 Sep 2021 06:08:13 +0800 Subject: [PATCH 03/24] Add Increment: Level 2. Add, List --- src/main/java/Duke.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 6c15551dc..0a677a5f9 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -12,12 +12,23 @@ public static void main(String[] args) { System.out.println("..................................................."); Scanner in = new Scanner(System.in); String lineIn = ""; - do{ + String[] listIn = new String[100]; + int listCounter = 0; + while(!lineIn.equals("bye")){ lineIn = in.nextLine(); System.out.println("..................................................."); - System.out.println(lineIn); - System.out.println("..................................................."); - } while(!lineIn.equals("bye")); + if(lineIn.equals("list")){ + for(int i = 0; i < listCounter; i++){ + System.out.println((i+1) + ". " + listIn[i]); + } + System.out.println("..................................................."); + } else { + listIn[listCounter] = lineIn; + System.out.println("added: "+ lineIn); + listCounter++; + System.out.println("..................................................."); + } + } System.out.println("Bye. Hope to see you again soon!"); System.out.println("..................................................."); } From 68a97b0ac254e65c79ede073f3d2c6352aba0ca3 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Thu, 16 Sep 2021 06:52:25 +0800 Subject: [PATCH 04/24] Add Increment: Level 3. Mark as Done --- src/main/java/Duke.java | 30 +++++++++++++++++++++--------- src/main/java/Task.java | 17 +++++++++++++++++ 2 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 0a677a5f9..6691d1f9d 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -12,20 +12,32 @@ public static void main(String[] args) { System.out.println("..................................................."); Scanner in = new Scanner(System.in); String lineIn = ""; - String[] listIn = new String[100]; - int listCounter = 0; - while(!lineIn.equals("bye")){ + Task[] listIn = new Task[100]; + int inputIndex = 0; + int currentIndex = 0; + while(!lineIn.equals("bye")) { lineIn = in.nextLine(); + String[] lineInput = lineIn.split(" "); System.out.println("..................................................."); - if(lineIn.equals("list")){ - for(int i = 0; i < listCounter; i++){ - System.out.println((i+1) + ". " + listIn[i]); + if (lineInput[0].equals("bye")) { + break; + } + if (lineInput[0].equals("list")) { + System.out.println("Here are the tasks in your list: "); + for (int i = 0; i < currentIndex; i++) { + System.out.println((i + 1) + ".[" + listIn[i].getStatus() + "] " + listIn[i].getName()); } System.out.println("..................................................."); + } else if (lineInput[0].equals("done")) { + inputIndex = Integer.parseInt(lineInput[1]) - 1; + listIn[inputIndex].markAsDone(); + System.out.println("Nice! I've marked this task as done: "); + System.out.println("[" + listIn[inputIndex].getStatus() + "] " + listIn[inputIndex].getName()); + System.out.println("..................................................."); } else { - listIn[listCounter] = lineIn; - System.out.println("added: "+ lineIn); - listCounter++; + listIn[currentIndex] = new Task(lineIn); + System.out.println("Added: " + lineIn); + currentIndex++; System.out.println("..................................................."); } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..6fd3f9d2f --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,17 @@ +public class Task { + public String name; + public boolean isDone; + public Task(String name) { + this.name = name; + this.isDone = false; + } + public String getStatus() { + return (isDone ? "X" : " "); + } + public void markAsDone() { + this.isDone = true; + } + public String getName() { + return this.name; + } +} From 4335f3bf44461363c9c26036283b18e2ea904455 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Thu, 16 Sep 2021 06:59:37 +0800 Subject: [PATCH 05/24] Modify the code: Coding standard and personalisation --- src/main/java/Duke.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 6691d1f9d..37a8a8f9b 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -8,7 +8,7 @@ public static void main(String[] args) { + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); System.out.println("..................................................."); - System.out.println("Hello! I'm Duke\n" + "What can I do for you?"); + System.out.println("Hi! I'm Duke\n" + "How can I help make your life easier?"); System.out.println("..................................................."); Scanner in = new Scanner(System.in); String lineIn = ""; @@ -31,7 +31,7 @@ public static void main(String[] args) { } else if (lineInput[0].equals("done")) { inputIndex = Integer.parseInt(lineInput[1]) - 1; listIn[inputIndex].markAsDone(); - System.out.println("Nice! I've marked this task as done: "); + System.out.println("Wonderful! This task is now marked as done: "); System.out.println("[" + listIn[inputIndex].getStatus() + "] " + listIn[inputIndex].getName()); System.out.println("..................................................."); } else { @@ -41,7 +41,7 @@ public static void main(String[] args) { System.out.println("..................................................."); } } - System.out.println("Bye. Hope to see you again soon!"); + System.out.println("Byebye! Have a wonderful day!"); System.out.println("..................................................."); } } From e594f38312a776d6596a414983dfee325acbd1e8 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Thu, 16 Sep 2021 08:13:14 +0800 Subject: [PATCH 06/24] Add Increment: Level 4. ToDos, Events, Deadlines --- src/main/java/Deadline.java | 11 ++++++++ src/main/java/Duke.java | 52 ++++++++++++++++++++++++------------- src/main/java/Event.java | 11 ++++++++ src/main/java/Task.java | 8 +++--- src/main/java/ToDo.java | 9 +++++++ 5 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/ToDo.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..fd12d5f27 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,11 @@ +public class Deadline extends Task{ + protected String dueDate; + public Deadline(String name, String dueDate) { + super(name); + this.dueDate = dueDate; + } + @Override + public String toString(){ + return "[D]" + super.toString() + " (by:" + dueDate + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 37a8a8f9b..319ae21bd 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -13,8 +13,7 @@ public static void main(String[] args) { Scanner in = new Scanner(System.in); String lineIn = ""; Task[] listIn = new Task[100]; - int inputIndex = 0; - int currentIndex = 0; + int totalNumber = 0; while(!lineIn.equals("bye")) { lineIn = in.nextLine(); String[] lineInput = lineIn.split(" "); @@ -23,25 +22,42 @@ public static void main(String[] args) { break; } if (lineInput[0].equals("list")) { - System.out.println("Here are the tasks in your list: "); - for (int i = 0; i < currentIndex; i++) { - System.out.println((i + 1) + ".[" + listIn[i].getStatus() + "] " + listIn[i].getName()); - } - System.out.println("..................................................."); - } else if (lineInput[0].equals("done")) { - inputIndex = Integer.parseInt(lineInput[1]) - 1; - listIn[inputIndex].markAsDone(); - System.out.println("Wonderful! This task is now marked as done: "); - System.out.println("[" + listIn[inputIndex].getStatus() + "] " + listIn[inputIndex].getName()); - System.out.println("..................................................."); - } else { - listIn[currentIndex] = new Task(lineIn); - System.out.println("Added: " + lineIn); - currentIndex++; - System.out.println("..................................................."); + showTask(listIn,totalNumber); + } else if (lineInput[0].equals("done")){ + doneTask(listIn,lineInput); + } else if (lineInput[0].equals("event") || lineInput[0].equals("deadline") || lineInput[0].equals("todo")) { + recordTask(listIn,lineIn,totalNumber,lineInput[0]); + totalNumber++; } } System.out.println("Byebye! Have a wonderful day!"); System.out.println("..................................................."); } + private static void showTask(Task[] listIn, int totalNumber) { + System.out.println("Here are the tasks in your list: "); + for (int i = 0; i < totalNumber; i++) { + System.out.println((i + 1) + "." + listIn[i].toString()); + } + } + + private static void doneTask(Task[] listIn, String[] lineInput) { + int inputIndex = Integer.parseInt(lineInput[1]) - 1; + listIn[inputIndex].markAsDone(); + System.out.println("Wonderful! This task is now marked as done: "); + System.out.println(listIn[inputIndex].toString()); + } + + private static void recordTask(Task[] listIn, String lineInput, int totalNumber, String firstInput) { + System.out.println("Got it. I've added this task:"); + if (firstInput.equals("event")) { + listIn[totalNumber] = new Event(lineInput.substring(6, lineInput.indexOf("/")), lineInput.substring(lineInput.indexOf("/") + 3)); + } else if (firstInput.equals("deadline")) { + listIn[totalNumber] = new Deadline(lineInput.substring(9, lineInput.indexOf("/")), lineInput.substring(lineInput.indexOf("/") + 3)); + } else { + listIn[totalNumber] = new ToDo(lineInput.substring(5)); + } + System.out.println(listIn[totalNumber].toString()); + System.out.println("Now you have " + (totalNumber + 1) + " tasks in your list"); + System.out.println("..................................................."); + } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..99b10dd55 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,11 @@ +public class Event extends Task { + public String eventDate; + public Event(String name, String eventDate) { + super(name); + this.eventDate = eventDate; + } + @Override + public String toString() { + return "[E]" + super.toString() + " (at:" + eventDate + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 6fd3f9d2f..7b31f7baa 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -6,12 +6,12 @@ public Task(String name) { this.isDone = false; } public String getStatus() { - return (isDone ? "X" : " "); + return (isDone ? "[X]" : "[ ]"); } public void markAsDone() { this.isDone = true; } - public String getName() { - return this.name; + public String toString() { + return getStatus() + this.name; } -} +} \ No newline at end of file diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java new file mode 100644 index 000000000..bc81b0656 --- /dev/null +++ b/src/main/java/ToDo.java @@ -0,0 +1,9 @@ +public class ToDo extends Task{ + public ToDo(String name) { + super(name); + } + @Override + public String toString(){ + return "[T]" + super.toString(); + } +} \ No newline at end of file From 7606c59c0f8d5385e5b9ea015a08f1a3750325eb Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Thu, 30 Sep 2021 02:45:27 +0800 Subject: [PATCH 07/24] Add files: Automated Text UI Testing --- src/main/java/Duke.java | 15 +++++------ src/main/java/META-INF/MANIFEST.MF | 3 +++ src/main/java/Task.java | 2 +- text-ui-test/EXPECTED.TXT | 41 ++++++++++++++++++++++++++++-- text-ui-test/input.txt | 9 +++++++ text-ui-test/runtest.bat | 21 --------------- text-ui-test/runtest.sh | 8 ++---- 7 files changed, 61 insertions(+), 38 deletions(-) create mode 100644 src/main/java/META-INF/MANIFEST.MF delete mode 100644 text-ui-test/runtest.bat diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 319ae21bd..df499da8e 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,15 +1,15 @@ import java.util.Scanner; + public class Duke { public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" + String logo = " ____ _\n" + + "| _ \\ _ _| | _____\n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); System.out.println("..................................................."); - System.out.println("Hi! I'm Duke\n" + "How can I help make your life easier?"); - System.out.println("..................................................."); + System.out.println("Hi! I'm Duke.\n" + "How can I help make your life easier?"); Scanner in = new Scanner(System.in); String lineIn = ""; Task[] listIn = new Task[100]; @@ -34,7 +34,7 @@ public static void main(String[] args) { System.out.println("..................................................."); } private static void showTask(Task[] listIn, int totalNumber) { - System.out.println("Here are the tasks in your list: "); + System.out.println("Here are the tasks in your list:"); for (int i = 0; i < totalNumber; i++) { System.out.println((i + 1) + "." + listIn[i].toString()); } @@ -43,7 +43,7 @@ private static void showTask(Task[] listIn, int totalNumber) { private static void doneTask(Task[] listIn, String[] lineInput) { int inputIndex = Integer.parseInt(lineInput[1]) - 1; listIn[inputIndex].markAsDone(); - System.out.println("Wonderful! This task is now marked as done: "); + System.out.println("Wonderful! This task is now marked as done:"); System.out.println(listIn[inputIndex].toString()); } @@ -58,6 +58,5 @@ private static void recordTask(Task[] listIn, String lineInput, int totalNumber, } System.out.println(listIn[totalNumber].toString()); System.out.println("Now you have " + (totalNumber + 1) + " tasks in your list"); - System.out.println("..................................................."); } -} +} \ No newline at end of file diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..d2ffd5b4d --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Duke + diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 7b31f7baa..31f7f7e5b 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -6,7 +6,7 @@ public Task(String name) { this.isDone = false; } public String getStatus() { - return (isDone ? "[X]" : "[ ]"); + return (isDone ? "[X] " : "[ ] "); } public void markAsDone() { this.isDone = true; diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..9f9b416b7 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,44 @@ Hello from - ____ _ -| _ \ _ _| | _____ + ____ _ +| _ \ _ _| | _____ | | | | | | | |/ / _ \ | |_| | |_| | < __/ |____/ \__,_|_|\_\___| +................................................... +Hi! I'm Duke. +How can I help make your life easier? +................................................... +Got it. I've added this task: +[T][ ] study something +Now you have 1 tasks in your list +................................................... +Got it. I've added this task: +[E][ ] CS2113T project group meeting (at: Mon 10-11pm) +Now you have 2 tasks in your list +................................................... +Got it. I've added this task: +[D][ ] CG2027 assignment (by: Sunday) +Now you have 3 tasks in your list +................................................... +Here are the tasks in your list: +1.[T][ ] study something +2.[E][ ] CS2113T project group meeting (at: Mon 10-11pm) +3.[D][ ] CG2027 assignment (by: Sunday) +................................................... +Wonderful! This task is now marked as done: +[T][X] study something +................................................... +Wonderful! This task is now marked as done: +[E][X] CS2113T project group meeting (at: Mon 10-11pm) +................................................... +Wonderful! This task is now marked as done: +[D][X] CG2027 assignment (by: Sunday) +................................................... +Here are the tasks in your list: +1.[T][X] study something +2.[E][X] CS2113T project group meeting (at: Mon 10-11pm) +3.[D][X] CG2027 assignment (by: Sunday) +................................................... +Byebye! Have a wonderful day! +................................................... diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..f16d06b5b 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,9 @@ +todo study something +event CS2113T project group meeting /at Mon 10-11pm +deadline CG2027 assignment /by Sunday +list +done 1 +done 2 +done 3 +list +bye \ No newline at end of file diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat deleted file mode 100644 index 087374464..000000000 --- a/text-ui-test/runtest.bat +++ /dev/null @@ -1,21 +0,0 @@ -@ECHO OFF - -REM create bin directory if it doesn't exist -if not exist ..\bin mkdir ..\bin - -REM delete output from previous run -if exist ACTUAL.TXT del ACTUAL.TXT - -REM compile the code into the bin folder -javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java -IF ERRORLEVEL 1 ( - echo ********** BUILD FAILURE ********** - exit /b 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 - -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 c9ec87003..1cc809ed2 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/main/java -Xlint:none -d ../bin ../src/main/java/*.java +if ! javac -cp ../src/main/java -Xlint:none -d ../bin ~/ip/src/main/java/Duke.java then echo "********** BUILD FAILURE **********" exit 1 @@ -22,12 +22,8 @@ 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 +diff ACTUAL.TXT EXPECTED.TXT if [ $? -eq 0 ] then echo "Test result: PASSED" From 93666c065f3242f7b06d15e8d3c00c5813cc6715 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Thu, 30 Sep 2021 02:51:55 +0800 Subject: [PATCH 08/24] Modify the code: Improve code quality --- src/main/java/Deadline.java | 6 ++++-- src/main/java/Duke.java | 3 ++- src/main/java/Event.java | 2 ++ src/main/java/Task.java | 4 ++++ src/main/java/ToDo.java | 3 ++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index fd12d5f27..c02ee3d6b 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,11 +1,13 @@ -public class Deadline extends Task{ +public class Deadline extends Task { protected String dueDate; + public Deadline(String name, String dueDate) { super(name); this.dueDate = dueDate; } + @Override - public String toString(){ + public String toString() { return "[D]" + super.toString() + " (by:" + dueDate + ")"; } } \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index df499da8e..65c77ed37 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -23,7 +23,7 @@ public static void main(String[] args) { } if (lineInput[0].equals("list")) { showTask(listIn,totalNumber); - } else if (lineInput[0].equals("done")){ + } else if (lineInput[0].equals("done")) { doneTask(listIn,lineInput); } else if (lineInput[0].equals("event") || lineInput[0].equals("deadline") || lineInput[0].equals("todo")) { recordTask(listIn,lineIn,totalNumber,lineInput[0]); @@ -33,6 +33,7 @@ public static void main(String[] args) { System.out.println("Byebye! Have a wonderful day!"); System.out.println("..................................................."); } + private static void showTask(Task[] listIn, int totalNumber) { System.out.println("Here are the tasks in your list:"); for (int i = 0; i < totalNumber; i++) { diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 99b10dd55..dad0b2c10 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,9 +1,11 @@ public class Event extends Task { public String eventDate; + public Event(String name, String eventDate) { super(name); this.eventDate = eventDate; } + @Override public String toString() { return "[E]" + super.toString() + " (at:" + eventDate + ")"; diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 31f7f7e5b..81086c1c1 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,16 +1,20 @@ public class Task { public String name; public boolean isDone; + public Task(String name) { this.name = name; this.isDone = false; } + public String getStatus() { return (isDone ? "[X] " : "[ ] "); } + public void markAsDone() { this.isDone = true; } + public String toString() { return getStatus() + this.name; } diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java index bc81b0656..1895e4427 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/ToDo.java @@ -2,8 +2,9 @@ public class ToDo extends Task{ public ToDo(String name) { super(name); } + @Override - public String toString(){ + public String toString() { return "[T]" + super.toString(); } } \ No newline at end of file From fffc6811db1fc3d346627a1f35311d03cd5cd81f Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Thu, 30 Sep 2021 20:18:38 +0800 Subject: [PATCH 09/24] Add Increment: Level 5. Handle Errors --- src/main/java/Duke.java | 73 +++++++++++++++++++++++--------- src/main/java/DukeException.java | 5 +++ 2 files changed, 57 insertions(+), 21 deletions(-) create mode 100644 src/main/java/DukeException.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 65c77ed37..60b1ab1ce 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -10,24 +10,38 @@ public static void main(String[] args) { System.out.println("Hello from\n" + logo); System.out.println("..................................................."); System.out.println("Hi! I'm Duke.\n" + "How can I help make your life easier?"); + System.out.println("..................................................."); Scanner in = new Scanner(System.in); String lineIn = ""; Task[] listIn = new Task[100]; int totalNumber = 0; - while(!lineIn.equals("bye")) { - lineIn = in.nextLine(); - String[] lineInput = lineIn.split(" "); - System.out.println("..................................................."); - if (lineInput[0].equals("bye")) { - break; - } - if (lineInput[0].equals("list")) { - showTask(listIn,totalNumber); - } else if (lineInput[0].equals("done")) { - doneTask(listIn,lineInput); - } else if (lineInput[0].equals("event") || lineInput[0].equals("deadline") || lineInput[0].equals("todo")) { - recordTask(listIn,lineIn,totalNumber,lineInput[0]); - totalNumber++; + while(!lineIn.equals("bye")){ + try{ + lineIn=in.nextLine(); + String[]lineInput=lineIn.split(" "); + if(lineInput[0].equals("bye")){ + break; + } + if(lineInput[0].equals("list")){ + showTask(listIn,totalNumber); + }else if(lineInput[0].equals("done")) { + try{ + doneTask(listIn,lineInput); + }catch(ArrayIndexOutOfBoundsException | NullPointerException e) { + System.out.println("OOPS!!! The index of the task that you entered does not exist:(\n..................................................."); + } + }else if(lineInput[0].equals("event")||lineInput[0].equals("deadline")||lineInput[0].equals("todo")){ + try{ + recordTask(listIn,lineIn,totalNumber,lineInput[0]); + totalNumber++; + }catch(StringIndexOutOfBoundsException e){ + System.out.println("OOPS!!! The name of the task that you entered is empty:(\n..................................................."); + } + }else { + throw new DukeException("OOPS!!! Sorry, but I do not understand:(\n..................................................."); + } + }catch(DukeException e){ + System.out.println(e.getMessage()); } } System.out.println("Byebye! Have a wonderful day!"); @@ -39,6 +53,7 @@ private static void showTask(Task[] listIn, int totalNumber) { for (int i = 0; i < totalNumber; i++) { System.out.println((i + 1) + "." + listIn[i].toString()); } + System.out.println("..................................................."); } private static void doneTask(Task[] listIn, String[] lineInput) { @@ -46,18 +61,34 @@ private static void doneTask(Task[] listIn, String[] lineInput) { listIn[inputIndex].markAsDone(); System.out.println("Wonderful! This task is now marked as done:"); System.out.println(listIn[inputIndex].toString()); + System.out.println("..................................................."); } - private static void recordTask(Task[] listIn, String lineInput, int totalNumber, String firstInput) { - System.out.println("Got it. I've added this task:"); + private static void recordTask(Task[] listIn, String lineInput, int totalNumber, String firstInput) throws DukeException { if (firstInput.equals("event")) { - listIn[totalNumber] = new Event(lineInput.substring(6, lineInput.indexOf("/")), lineInput.substring(lineInput.indexOf("/") + 3)); + int breakPoint = lineInput.indexOf("/"); + if (lineInput.length() < 9) { + throw new DukeException("The description of the event is too short! Please enter again.\n..................................................."); + } + System.out.println("Got it. I've added this task:"); + String eventName = lineInput.substring(6, breakPoint); + String eventTime = lineInput.substring(breakPoint + 3); + listIn[totalNumber] = new Event(eventName, eventTime); } else if (firstInput.equals("deadline")) { - listIn[totalNumber] = new Deadline(lineInput.substring(9, lineInput.indexOf("/")), lineInput.substring(lineInput.indexOf("/") + 3)); + int breakPoint = lineInput.indexOf("/"); + if (lineInput.length() < 12) { + throw new DukeException("The description of the deadline is too short! Please enter again.\n..................................................."); + } + System.out.println("Got it. I've added this task:"); + String deadlineName = lineInput.substring(9, breakPoint); + String deadlineTime = lineInput.substring(breakPoint + 3); + listIn[totalNumber] = new Deadline(deadlineName, deadlineTime); } else { - listIn[totalNumber] = new ToDo(lineInput.substring(5)); + String todoName = lineInput.substring(5); + System.out.println("Got it. I've added this task:"); + listIn[totalNumber] = new ToDo(todoName); } System.out.println(listIn[totalNumber].toString()); System.out.println("Now you have " + (totalNumber + 1) + " tasks in your list"); - } -} \ No newline at end of file + System.out.println("..................................................."); + } \ No newline at end of file diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java new file mode 100644 index 000000000..069714ad6 --- /dev/null +++ b/src/main/java/DukeException.java @@ -0,0 +1,5 @@ +public class DukeException extends Exception{ + public DukeException(String errorMessage) { + super(errorMessage); + } +} \ No newline at end of file From c2663e10d951c1875ad3ae9452658b6f1bca53b8 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Thu, 30 Sep 2021 20:35:21 +0800 Subject: [PATCH 10/24] Modify the code: Coding standard and format --- src/main/java/Duke.java | 64 +++++++++++++++++--------------- src/main/java/DukeException.java | 2 +- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 60b1ab1ce..edb3253aa 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -7,68 +7,73 @@ public static void main(String[] args) { + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; + String dotsBreaker = "......................................................................"; System.out.println("Hello from\n" + logo); - System.out.println("..................................................."); + System.out.println(dotsBreaker); System.out.println("Hi! I'm Duke.\n" + "How can I help make your life easier?"); - System.out.println("..................................................."); + System.out.println(dotsBreaker); Scanner in = new Scanner(System.in); String lineIn = ""; Task[] listIn = new Task[100]; int totalNumber = 0; - while(!lineIn.equals("bye")){ - try{ - lineIn=in.nextLine(); - String[]lineInput=lineIn.split(" "); - if(lineInput[0].equals("bye")){ + + while (!lineIn.equals("bye")) { + try { + lineIn = in.nextLine(); + String[] lineInput = lineIn.split(" "); + if (lineInput[0].equals("bye")) { break; } - if(lineInput[0].equals("list")){ - showTask(listIn,totalNumber); - }else if(lineInput[0].equals("done")) { - try{ - doneTask(listIn,lineInput); - }catch(ArrayIndexOutOfBoundsException | NullPointerException e) { - System.out.println("OOPS!!! The index of the task that you entered does not exist:(\n..................................................."); + if (lineInput[0].equals("list")) { + showTask(listIn, totalNumber); + } else if (lineInput[0].equals("done")) { + try { + doneTask(listIn, lineInput); + } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { + System.out.println("OOPS!!! The index of the task that you entered does not exist:(" + dotsBreaker); } - }else if(lineInput[0].equals("event")||lineInput[0].equals("deadline")||lineInput[0].equals("todo")){ - try{ - recordTask(listIn,lineIn,totalNumber,lineInput[0]); + } else if (lineInput[0].equals("event") || lineInput[0].equals("deadline") || lineInput[0].equals("todo")) { + try { + recordTask(listIn, lineIn, totalNumber, lineInput[0]); totalNumber++; - }catch(StringIndexOutOfBoundsException e){ - System.out.println("OOPS!!! The name of the task that you entered is empty:(\n..................................................."); + } catch (StringIndexOutOfBoundsException e) { + System.out.println("OOPS!!! The name of the task that you entered is empty:(" + dotsBreaker); } - }else { - throw new DukeException("OOPS!!! Sorry, but I do not understand:(\n..................................................."); + } else { + throw new DukeException("OOPS!!! Sorry, but I do not understand:(\n" + dotsBreaker); } - }catch(DukeException e){ + } catch (DukeException e) { System.out.println(e.getMessage()); } } System.out.println("Byebye! Have a wonderful day!"); - System.out.println("..................................................."); + System.out.println(dotsBreaker); } private static void showTask(Task[] listIn, int totalNumber) { + String dotsBreaker = "......................................................................"; System.out.println("Here are the tasks in your list:"); for (int i = 0; i < totalNumber; i++) { System.out.println((i + 1) + "." + listIn[i].toString()); } - System.out.println("..................................................."); + System.out.println(dotsBreaker); } private static void doneTask(Task[] listIn, String[] lineInput) { + String dotsBreaker = "......................................................................"; int inputIndex = Integer.parseInt(lineInput[1]) - 1; listIn[inputIndex].markAsDone(); System.out.println("Wonderful! This task is now marked as done:"); System.out.println(listIn[inputIndex].toString()); - System.out.println("..................................................."); + System.out.println(dotsBreaker); } private static void recordTask(Task[] listIn, String lineInput, int totalNumber, String firstInput) throws DukeException { + String dotsBreaker = "......................................................................"; if (firstInput.equals("event")) { int breakPoint = lineInput.indexOf("/"); if (lineInput.length() < 9) { - throw new DukeException("The description of the event is too short! Please enter again.\n..................................................."); + throw new DukeException("The description of the event is too short! Please enter again.\n" + dotsBreaker); } System.out.println("Got it. I've added this task:"); String eventName = lineInput.substring(6, breakPoint); @@ -77,7 +82,7 @@ private static void recordTask(Task[] listIn, String lineInput, int totalNumber, } else if (firstInput.equals("deadline")) { int breakPoint = lineInput.indexOf("/"); if (lineInput.length() < 12) { - throw new DukeException("The description of the deadline is too short! Please enter again.\n..................................................."); + throw new DukeException("The description of the deadline is too short! Please enter again.\n" + dotsBreaker); } System.out.println("Got it. I've added this task:"); String deadlineName = lineInput.substring(9, breakPoint); @@ -90,5 +95,6 @@ private static void recordTask(Task[] listIn, String lineInput, int totalNumber, } System.out.println(listIn[totalNumber].toString()); System.out.println("Now you have " + (totalNumber + 1) + " tasks in your list"); - System.out.println("..................................................."); - } \ No newline at end of file + System.out.println(dotsBreaker); + } +} \ No newline at end of file diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java index 069714ad6..f3aaf61ca 100644 --- a/src/main/java/DukeException.java +++ b/src/main/java/DukeException.java @@ -1,4 +1,4 @@ -public class DukeException extends Exception{ +public class DukeException extends Exception { public DukeException(String errorMessage) { super(errorMessage); } From 58104bb0ed796ca0c1156987fd504f3aaee35384 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Thu, 30 Sep 2021 21:23:13 +0800 Subject: [PATCH 11/24] A-Packages: Organize into Packages --- README.md | 4 ++-- src/main/java/META-INF/MANIFEST.MF | 2 +- src/main/java/{ => duke}/Deadline.java | 2 ++ src/main/java/{ => duke}/Duke.java | 16 +++++++++------- src/main/java/{ => duke}/DukeException.java | 1 + src/main/java/{ => duke}/Event.java | 2 ++ src/main/java/{ => duke}/Task.java | 2 ++ src/main/java/{ => duke}/ToDo.java | 2 ++ text-ui-test/EXPECTED.TXT | 14 +++++++------- 9 files changed, 28 insertions(+), 17 deletions(-) rename src/main/java/{ => duke}/Deadline.java (95%) rename src/main/java/{ => duke}/Duke.java (89%) rename src/main/java/{ => duke}/DukeException.java (90%) rename src/main/java/{ => duke}/Event.java (95%) rename src/main/java/{ => duke}/Task.java (96%) rename src/main/java/{ => duke}/ToDo.java (92%) diff --git a/README.md b/README.md index 8715d4d91..0f2208ab6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Duke project template +# duke.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. @@ -13,7 +13,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version. 1. If there are any further prompts, accept the defaults. 1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: +3. After that, locate the `src/main/java/duke.Duke.java` file, right-click it, and choose `Run duke.Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: ``` Hello from ____ _ diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF index d2ffd5b4d..6e864153e 100644 --- a/src/main/java/META-INF/MANIFEST.MF +++ b/src/main/java/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ Manifest-Version: 1.0 -Main-Class: Duke +Main-Class: duke.Duke diff --git a/src/main/java/Deadline.java b/src/main/java/duke/Deadline.java similarity index 95% rename from src/main/java/Deadline.java rename to src/main/java/duke/Deadline.java index c02ee3d6b..e4be7fe1b 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/duke/Deadline.java @@ -1,3 +1,5 @@ +package duke; + public class Deadline extends Task { protected String dueDate; diff --git a/src/main/java/Duke.java b/src/main/java/duke/Duke.java similarity index 89% rename from src/main/java/Duke.java rename to src/main/java/duke/Duke.java index edb3253aa..1e5f8830f 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,3 +1,5 @@ +package duke; + import java.util.Scanner; public class Duke { @@ -10,7 +12,7 @@ public static void main(String[] args) { String dotsBreaker = "......................................................................"; System.out.println("Hello from\n" + logo); System.out.println(dotsBreaker); - System.out.println("Hi! I'm Duke.\n" + "How can I help make your life easier?"); + System.out.println("Hi! I'm duke.Duke.\n" + "How can I help make your life easier?"); System.out.println(dotsBreaker); Scanner in = new Scanner(System.in); String lineIn = ""; @@ -30,14 +32,14 @@ public static void main(String[] args) { try { doneTask(listIn, lineInput); } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { - System.out.println("OOPS!!! The index of the task that you entered does not exist:(" + dotsBreaker); + System.out.println("OOPS!!! The index of the duke.task that you entered does not exist:(" + dotsBreaker); } } else if (lineInput[0].equals("event") || lineInput[0].equals("deadline") || lineInput[0].equals("todo")) { try { recordTask(listIn, lineIn, totalNumber, lineInput[0]); totalNumber++; } catch (StringIndexOutOfBoundsException e) { - System.out.println("OOPS!!! The name of the task that you entered is empty:(" + dotsBreaker); + System.out.println("OOPS!!! The name of the duke.task that you entered is empty:(" + dotsBreaker); } } else { throw new DukeException("OOPS!!! Sorry, but I do not understand:(\n" + dotsBreaker); @@ -63,7 +65,7 @@ private static void doneTask(Task[] listIn, String[] lineInput) { String dotsBreaker = "......................................................................"; int inputIndex = Integer.parseInt(lineInput[1]) - 1; listIn[inputIndex].markAsDone(); - System.out.println("Wonderful! This task is now marked as done:"); + System.out.println("Wonderful! This duke.task is now marked as done:"); System.out.println(listIn[inputIndex].toString()); System.out.println(dotsBreaker); } @@ -75,7 +77,7 @@ private static void recordTask(Task[] listIn, String lineInput, int totalNumber, if (lineInput.length() < 9) { throw new DukeException("The description of the event is too short! Please enter again.\n" + dotsBreaker); } - System.out.println("Got it. I've added this task:"); + System.out.println("Got it. I've added this duke.task:"); String eventName = lineInput.substring(6, breakPoint); String eventTime = lineInput.substring(breakPoint + 3); listIn[totalNumber] = new Event(eventName, eventTime); @@ -84,13 +86,13 @@ private static void recordTask(Task[] listIn, String lineInput, int totalNumber, if (lineInput.length() < 12) { throw new DukeException("The description of the deadline is too short! Please enter again.\n" + dotsBreaker); } - System.out.println("Got it. I've added this task:"); + System.out.println("Got it. I've added this duke.task:"); String deadlineName = lineInput.substring(9, breakPoint); String deadlineTime = lineInput.substring(breakPoint + 3); listIn[totalNumber] = new Deadline(deadlineName, deadlineTime); } else { String todoName = lineInput.substring(5); - System.out.println("Got it. I've added this task:"); + System.out.println("Got it. I've added this duke.task:"); listIn[totalNumber] = new ToDo(todoName); } System.out.println(listIn[totalNumber].toString()); diff --git a/src/main/java/DukeException.java b/src/main/java/duke/DukeException.java similarity index 90% rename from src/main/java/DukeException.java rename to src/main/java/duke/DukeException.java index f3aaf61ca..5ea167092 100644 --- a/src/main/java/DukeException.java +++ b/src/main/java/duke/DukeException.java @@ -1,3 +1,4 @@ +package duke; public class DukeException extends Exception { public DukeException(String errorMessage) { super(errorMessage); diff --git a/src/main/java/Event.java b/src/main/java/duke/Event.java similarity index 95% rename from src/main/java/Event.java rename to src/main/java/duke/Event.java index dad0b2c10..b0824d674 100644 --- a/src/main/java/Event.java +++ b/src/main/java/duke/Event.java @@ -1,3 +1,5 @@ +package duke; + public class Event extends Task { public String eventDate; diff --git a/src/main/java/Task.java b/src/main/java/duke/Task.java similarity index 96% rename from src/main/java/Task.java rename to src/main/java/duke/Task.java index 81086c1c1..6c0371dee 100644 --- a/src/main/java/Task.java +++ b/src/main/java/duke/Task.java @@ -1,3 +1,5 @@ +package duke; + public class Task { public String name; public boolean isDone; diff --git a/src/main/java/ToDo.java b/src/main/java/duke/ToDo.java similarity index 92% rename from src/main/java/ToDo.java rename to src/main/java/duke/ToDo.java index 1895e4427..99d275204 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/duke/ToDo.java @@ -1,3 +1,5 @@ +package duke; + public class ToDo extends Task{ public ToDo(String name) { super(name); diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 9f9b416b7..465cc8ab7 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -6,18 +6,18 @@ Hello from |____/ \__,_|_|\_\___| ................................................... -Hi! I'm Duke. +Hi! I'm duke.Duke. How can I help make your life easier? ................................................... -Got it. I've added this task: +Got it. I've added this duke.task: [T][ ] study something Now you have 1 tasks in your list ................................................... -Got it. I've added this task: +Got it. I've added this duke.task: [E][ ] CS2113T project group meeting (at: Mon 10-11pm) Now you have 2 tasks in your list ................................................... -Got it. I've added this task: +Got it. I've added this duke.task: [D][ ] CG2027 assignment (by: Sunday) Now you have 3 tasks in your list ................................................... @@ -26,13 +26,13 @@ Here are the tasks in your list: 2.[E][ ] CS2113T project group meeting (at: Mon 10-11pm) 3.[D][ ] CG2027 assignment (by: Sunday) ................................................... -Wonderful! This task is now marked as done: +Wonderful! This duke.task is now marked as done: [T][X] study something ................................................... -Wonderful! This task is now marked as done: +Wonderful! This duke.task is now marked as done: [E][X] CS2113T project group meeting (at: Mon 10-11pm) ................................................... -Wonderful! This task is now marked as done: +Wonderful! This duke.task is now marked as done: [D][X] CG2027 assignment (by: Sunday) ................................................... Here are the tasks in your list: From 461d957cbc44ddbfe87e477607be5c805003dc5d Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Thu, 30 Sep 2021 21:30:46 +0800 Subject: [PATCH 12/24] Further divide classes into packages --- src/main/java/duke/Duke.java | 6 ++++-- 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 +- 5 files changed, 8 insertions(+), 6 deletions(-) rename src/main/java/duke/{ => task}/Deadline.java (94%) rename src/main/java/duke/{ => task}/Event.java (94%) rename src/main/java/duke/{ => task}/Task.java (95%) rename src/main/java/duke/{ => task}/ToDo.java (90%) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 1e5f8830f..80f177782 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,5 +1,7 @@ package duke; +import duke.task.*; + import java.util.Scanner; public class Duke { @@ -32,14 +34,14 @@ public static void main(String[] args) { try { doneTask(listIn, lineInput); } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { - System.out.println("OOPS!!! The index of the duke.task that you entered does not exist:(" + dotsBreaker); + System.out.println("OOPS!!! The index of the duke.task that you entered does not exist:(\n" + dotsBreaker); } } else if (lineInput[0].equals("event") || lineInput[0].equals("deadline") || lineInput[0].equals("todo")) { try { recordTask(listIn, lineIn, totalNumber, lineInput[0]); totalNumber++; } catch (StringIndexOutOfBoundsException e) { - System.out.println("OOPS!!! The name of the duke.task that you entered is empty:(" + dotsBreaker); + System.out.println("OOPS!!! The name of the duke.task that you entered is empty:(\n" + dotsBreaker); } } else { throw new DukeException("OOPS!!! Sorry, but I do not understand:(\n" + dotsBreaker); diff --git a/src/main/java/duke/Deadline.java b/src/main/java/duke/task/Deadline.java similarity index 94% rename from src/main/java/duke/Deadline.java rename to src/main/java/duke/task/Deadline.java index e4be7fe1b..d62f1193d 100644 --- a/src/main/java/duke/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,4 +1,4 @@ -package duke; +package duke.task; public class Deadline extends Task { protected String dueDate; diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/task/Event.java similarity index 94% rename from src/main/java/duke/Event.java rename to src/main/java/duke/task/Event.java index b0824d674..c56010c02 100644 --- a/src/main/java/duke/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,4 +1,4 @@ -package duke; +package duke.task; public class Event extends Task { public String eventDate; diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/task/Task.java similarity index 95% rename from src/main/java/duke/Task.java rename to src/main/java/duke/task/Task.java index 6c0371dee..e1fbd9a70 100644 --- a/src/main/java/duke/Task.java +++ b/src/main/java/duke/task/Task.java @@ -1,4 +1,4 @@ -package duke; +package duke.task; public class Task { public String name; diff --git a/src/main/java/duke/ToDo.java b/src/main/java/duke/task/ToDo.java similarity index 90% rename from src/main/java/duke/ToDo.java rename to src/main/java/duke/task/ToDo.java index 99d275204..0af19640c 100644 --- a/src/main/java/duke/ToDo.java +++ b/src/main/java/duke/task/ToDo.java @@ -1,4 +1,4 @@ -package duke; +package duke.task; public class ToDo extends Task{ public ToDo(String name) { From 3b551ae5cff942e5816972ea26284f3a85718748 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Fri, 1 Oct 2021 02:16:14 +0800 Subject: [PATCH 13/24] Add Increment: Level 6. Delete --- src/main/java/duke/Duke.java | 54 ++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 80f177782..ae2e8f3ba 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -3,6 +3,7 @@ import duke.task.*; import java.util.Scanner; +import java.util.ArrayList; public class Duke { public static void main(String[] args) { @@ -14,11 +15,11 @@ public static void main(String[] args) { String dotsBreaker = "......................................................................"; System.out.println("Hello from\n" + logo); System.out.println(dotsBreaker); - System.out.println("Hi! I'm duke.Duke.\n" + "How can I help make your life easier?"); + System.out.println("Hi! I'm Duke.\n" + "How can I help make your life easier?"); System.out.println(dotsBreaker); Scanner in = new Scanner(System.in); String lineIn = ""; - Task[] listIn = new Task[100]; + ArrayList listIn = new ArrayList<>(); int totalNumber = 0; while (!lineIn.equals("bye")) { @@ -34,14 +35,21 @@ public static void main(String[] args) { try { doneTask(listIn, lineInput); } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { - System.out.println("OOPS!!! The index of the duke.task that you entered does not exist:(\n" + dotsBreaker); + System.out.println("OOPS!!! The index of the task that you entered does not exist:(\n" + dotsBreaker); } } else if (lineInput[0].equals("event") || lineInput[0].equals("deadline") || lineInput[0].equals("todo")) { try { recordTask(listIn, lineIn, totalNumber, lineInput[0]); totalNumber++; } catch (StringIndexOutOfBoundsException e) { - System.out.println("OOPS!!! The name of the duke.task that you entered is empty:(\n" + dotsBreaker); + System.out.println("OOPS!!! The name of the task that you entered is empty:(\n" + dotsBreaker); + } + } else if (lineInput[0].equals("delete")) { + try { + deleteTask(listIn, lineInput, totalNumber); + totalNumber--; + } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { + System.out.println("OOPS!!! The index of the task that you entered does not exist:(" + dotsBreaker); } } else { throw new DukeException("OOPS!!! Sorry, but I do not understand:(\n" + dotsBreaker); @@ -54,51 +62,61 @@ public static void main(String[] args) { System.out.println(dotsBreaker); } - private static void showTask(Task[] listIn, int totalNumber) { + private static void showTask(ArrayList listIn, int totalNumber) { String dotsBreaker = "......................................................................"; System.out.println("Here are the tasks in your list:"); for (int i = 0; i < totalNumber; i++) { - System.out.println((i + 1) + "." + listIn[i].toString()); + System.out.println((i + 1) + "." + listIn.get(i).toString()); } System.out.println(dotsBreaker); } - private static void doneTask(Task[] listIn, String[] lineInput) { + private static void doneTask(ArrayList listIn, String[] lineInput) { String dotsBreaker = "......................................................................"; int inputIndex = Integer.parseInt(lineInput[1]) - 1; - listIn[inputIndex].markAsDone(); - System.out.println("Wonderful! This duke.task is now marked as done:"); - System.out.println(listIn[inputIndex].toString()); + ((Task)listIn.get(inputIndex)).markAsDone(); + System.out.println("Wonderful! This task is now marked as done:"); + System.out.println(listIn.get(inputIndex).toString()); System.out.println(dotsBreaker); } - private static void recordTask(Task[] listIn, String lineInput, int totalNumber, String firstInput) throws DukeException { + private static void recordTask(ArrayList listIn, String lineInput, int totalNumber, String firstInput) throws DukeException { String dotsBreaker = "......................................................................"; if (firstInput.equals("event")) { int breakPoint = lineInput.indexOf("/"); if (lineInput.length() < 9) { throw new DukeException("The description of the event is too short! Please enter again.\n" + dotsBreaker); } - System.out.println("Got it. I've added this duke.task:"); + System.out.println("Got it. I've added this task:"); String eventName = lineInput.substring(6, breakPoint); String eventTime = lineInput.substring(breakPoint + 3); - listIn[totalNumber] = new Event(eventName, eventTime); + listIn.add(totalNumber, new Event(eventName, eventTime)); } else if (firstInput.equals("deadline")) { int breakPoint = lineInput.indexOf("/"); if (lineInput.length() < 12) { throw new DukeException("The description of the deadline is too short! Please enter again.\n" + dotsBreaker); } - System.out.println("Got it. I've added this duke.task:"); + System.out.println("Got it. I've added this task:"); String deadlineName = lineInput.substring(9, breakPoint); String deadlineTime = lineInput.substring(breakPoint + 3); - listIn[totalNumber] = new Deadline(deadlineName, deadlineTime); + listIn.add(totalNumber, new Deadline(deadlineName, deadlineTime)); } else { String todoName = lineInput.substring(5); - System.out.println("Got it. I've added this duke.task:"); - listIn[totalNumber] = new ToDo(todoName); + System.out.println("Got it. I've added this task:"); + listIn.add(totalNumber, new ToDo(todoName)); } - System.out.println(listIn[totalNumber].toString()); + System.out.println(listIn.get(totalNumber).toString()); System.out.println("Now you have " + (totalNumber + 1) + " tasks in your list"); System.out.println(dotsBreaker); } + + private static void deleteTask(ArrayList listIn, String[] lineInput, int totalNumber) { + String dotsBreaker = "......................................................................"; + int inputIndex = Integer.parseInt(lineInput[1]) - 1; + System.out.println("Noted. I've removed this task:"); + System.out.println(listIn.get(inputIndex).toString()); + System.out.println("Now you have " + (totalNumber - 1) + " tasks in the list."); + System.out.println(dotsBreaker); + listIn.remove(inputIndex); + } } \ No newline at end of file From 3a5cd9402b6c0297e39725f0e8c4b6e989a8d7f0 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Fri, 1 Oct 2021 16:26:57 +0800 Subject: [PATCH 14/24] Add Increment: Level 7. Save --- src/main/java/duke/Duke.java | 241 ++++++++++++++++++-------- src/main/java/duke/DukeException.java | 1 + src/main/java/duke/data/task.txt | 1 + src/main/java/duke/task/Deadline.java | 8 +- src/main/java/duke/task/Event.java | 6 + src/main/java/duke/task/Task.java | 9 + src/main/java/duke/task/ToDo.java | 1 + task.txt | 2 + 8 files changed, 197 insertions(+), 72 deletions(-) create mode 100644 src/main/java/duke/data/task.txt create mode 100644 task.txt diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 80f177782..0b04e0871 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -4,101 +4,200 @@ import java.util.Scanner; +import java.io.File; +import java.io.FileWriter; + +import java.io.IOException; +import java.util.ArrayList; + public class Duke { + public static final ArrayList listInput = new ArrayList<>(); + public static final String BREAKER = "......................................................................"; + public static void main(String[] args) { - String logo = " ____ _\n" - + "| _ \\ _ _| | _____\n" + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - String dotsBreaker = "......................................................................"; - System.out.println("Hello from\n" + logo); - System.out.println(dotsBreaker); - System.out.println("Hi! I'm duke.Duke.\n" + "How can I help make your life easier?"); - System.out.println(dotsBreaker); - Scanner in = new Scanner(System.in); - String lineIn = ""; - Task[] listIn = new Task[100]; - int totalNumber = 0; - - while (!lineIn.equals("bye")) { + System.out.println("Hello from\n" + logo + "\n" + BREAKER + "\n" + "Hi! I'm Duke.\n" + "How can I make your life easier?\n" + BREAKER); + int taskNumber = 0; + taskNumber = getFromFile(listInput, taskNumber); + Scanner input = new Scanner(System.in); + String lineInput = ""; + while (!lineInput.equals("bye")) { + lineInput = input.nextLine(); + String[] arrayInput = lineInput.split(" "); + String commandInput = arrayInput[0]; + System.out.println(BREAKER); + if (commandInput.equals(("bye"))) { + break; + } try { - lineIn = in.nextLine(); - String[] lineInput = lineIn.split(" "); - if (lineInput[0].equals("bye")) { + switch (commandInput) { + case "list": + try { + showTask(listInput, taskNumber); + } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { + System.out.println("OOPS!!! The index of the task that you entered does not exist:(\n" + BREAKER); + } break; - } - if (lineInput[0].equals("list")) { - showTask(listIn, totalNumber); - } else if (lineInput[0].equals("done")) { + case "done": try { - doneTask(listIn, lineInput); + doneTask(listInput, arrayInput[1]); } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { - System.out.println("OOPS!!! The index of the duke.task that you entered does not exist:(\n" + dotsBreaker); + System.out.println("OOPS!!! The index of the task that you entered does not exist:(\n" + BREAKER); } - } else if (lineInput[0].equals("event") || lineInput[0].equals("deadline") || lineInput[0].equals("todo")) { + break; + case "deadline": + case "event": + case "todo": try { - recordTask(listIn, lineIn, totalNumber, lineInput[0]); - totalNumber++; + recordTask(listInput, lineInput, taskNumber, commandInput); + taskNumber++; } catch (StringIndexOutOfBoundsException e) { - System.out.println("OOPS!!! The name of the duke.task that you entered is empty:(\n" + dotsBreaker); + System.out.println("OOPS!!! The name of the task that you entered is invalid:(\n" + BREAKER); } - } else { - throw new DukeException("OOPS!!! Sorry, but I do not understand:(\n" + dotsBreaker); + break; + case "delete": + try { + deleteTask(listInput, arrayInput, taskNumber); + taskNumber--; + } catch (NullPointerException | ArrayIndexOutOfBoundsException e) { + System.out.println("OOPS!!! The index of the task that you entered does not exist:(\n" + BREAKER); + } + break; + default: + throw new DukeException("OOPS!!! Sorry, but I do not understand:(\n" + BREAKER); } - } catch (DukeException e) { + saveToFile(listInput, taskNumber); + } catch (IOException | DukeException e) { System.out.println(e.getMessage()); } + System.out.println(BREAKER); } - System.out.println("Byebye! Have a wonderful day!"); - System.out.println(dotsBreaker); + + System.out.println("Byebye! Have a wonderful day!\n" + BREAKER); } - private static void showTask(Task[] listIn, int totalNumber) { - String dotsBreaker = "......................................................................"; - System.out.println("Here are the tasks in your list:"); - for (int i = 0; i < totalNumber; i++) { - System.out.println((i + 1) + "." + listIn[i].toString()); + private static void showTask(ArrayList listInput, int taskNumber) { + if (taskNumber == 0) { + System.out.println("The list is empty! Add something to it:)"); + } else { + System.out.println("Here are the tasks in your list:"); + for (int i = 0; i < taskNumber; i++) { + System.out.println((i + 1) + "." + listInput.get(i).toString()); + } } - System.out.println(dotsBreaker); } - private static void doneTask(Task[] listIn, String[] lineInput) { - String dotsBreaker = "......................................................................"; - int inputIndex = Integer.parseInt(lineInput[1]) - 1; - listIn[inputIndex].markAsDone(); - System.out.println("Wonderful! This duke.task is now marked as done:"); - System.out.println(listIn[inputIndex].toString()); - System.out.println(dotsBreaker); + private static void doneTask(ArrayList listInput, String arrayInput) { + int inputIndex = Integer.parseInt(arrayInput) - 1; + ((Task) listInput.get(inputIndex)).markAsDone(); + System.out.println("Wonderful! This task is now marked as done:\n" + listInput.get(inputIndex).toString()); } - private static void recordTask(Task[] listIn, String lineInput, int totalNumber, String firstInput) throws DukeException { - String dotsBreaker = "......................................................................"; - if (firstInput.equals("event")) { - int breakPoint = lineInput.indexOf("/"); - if (lineInput.length() < 9) { - throw new DukeException("The description of the event is too short! Please enter again.\n" + dotsBreaker); - } - System.out.println("Got it. I've added this duke.task:"); - String eventName = lineInput.substring(6, breakPoint); - String eventTime = lineInput.substring(breakPoint + 3); - listIn[totalNumber] = new Event(eventName, eventTime); - } else if (firstInput.equals("deadline")) { - int breakPoint = lineInput.indexOf("/"); - if (lineInput.length() < 12) { - throw new DukeException("The description of the deadline is too short! Please enter again.\n" + dotsBreaker); - } - System.out.println("Got it. I've added this duke.task:"); - String deadlineName = lineInput.substring(9, breakPoint); - String deadlineTime = lineInput.substring(breakPoint + 3); - listIn[totalNumber] = new Deadline(deadlineName, deadlineTime); + private static void deleteTask(ArrayList listInput, String[] arrayInput, int taskNumber) { + int inputIndex = Integer.parseInt(arrayInput[1]) - 1; + System.out.println("Alright, the following task has been removed\n" + listInput.get(inputIndex).toString() + "\n" + "Now you have " + (taskNumber - 1) + " tasks left"); + listInput.remove(inputIndex); + } + + private static void recordTask(ArrayList listInput, String lineInput, int taskNumber, String commandInput) throws DukeException { + switch (commandInput) { + case "event": + recordEvent(listInput, lineInput, taskNumber); + break; + case "deadline": + recordDeadline(listInput, lineInput, taskNumber); + break; + case "todo": + recordToDo(listInput, lineInput, taskNumber); + break; + } + System.out.println("Got it. I've added this task:\n" + listInput.get(taskNumber).toString() + "\n" + "Now you have " + (taskNumber + 1) + " tasks in your list"); + } + + private static void recordDeadline(ArrayList listInput, String lineInput, int taskNumber) throws DukeException { + int breakIndex = lineInput.indexOf("/"); + if (lineInput.length() < 12) { + throw new DukeException("The description of the deadline is too short! Please enter again.\n"); + } + String deadlineName = lineInput.substring(9, breakIndex); + String deadlineDate = lineInput.substring(breakIndex + 3); + listInput.add(taskNumber, new Deadline(deadlineName, deadlineDate)); + } + + private static void recordEvent(ArrayList listInput, String lineInput, int taskNumber) throws DukeException { + int breakIndex = lineInput.indexOf("/"); + if (lineInput.length() < 9) { + throw new DukeException("The description of the event is too short! Please enter again.\n"; + } + String eventName = lineInput.substring(6, breakIndex); + String eventDate = lineInput.substring(breakIndex + 3); + listInput.add(taskNumber, new Event(eventName, eventDate)); + } + + private static void recordToDo(ArrayList listInput, String lineInput, int taskNumber) { + String todoName = lineInput.substring(5); + listInput.add(taskNumber, new ToDo(todoName)); + } + + public static void saveToFile(ArrayList listInput, int numTask) throws IOException { + FileWriter file = new FileWriter("src/main/java/duke/data/task.txt"); + for (int i = 0; i < numTask; i++) { + String saveInput = ((Task) listInput.get(i)).getType() + " | " + getNumberStatus(listInput, i) + " | " + ((Task) listInput.get(i)).getName() + "\n"; + file.write(saveInput); + } + file.close(); + } + + private static String getNumberStatus(ArrayList listInput, int taskNumber) { + if (((Task) listInput.get(taskNumber)).getStatus().equals("[X]")) { + return "1"; } else { - String todoName = lineInput.substring(5); - System.out.println("Got it. I've added this duke.task:"); - listIn[totalNumber] = new ToDo(todoName); + return "0"; + } + } + + private static int getFromFile(ArrayList listInput, int taskNumber) { + try { + File file = new File("src/main/java/duke/data/task.txt"); + Scanner updateInput = new Scanner(file); + while (updateInput.hasNext()) { + String[] lineInput = updateInput.nextLine().split("\\|"); + String taskType = lineInput[0]; + switch (taskType) { + case "D ": + recordDeadline(listInput, "deadline" + lineInput[2], taskNumber); + break; + case "E ": + recordEvent(listInput, "event" + lineInput[2], taskNumber); + break; + case "T ": + recordToDo(listInput, "todo" + lineInput[2], taskNumber); + break; + } + if (lineInput[1].equals("1")) { + ((Task) listInput.get(taskNumber)).markAsDone(); + } + taskNumber++; + } + } catch (IOException e) { + System.out.println("There is no saved file:( but I will create a new one for you:)\n" + BREAKER); + } catch (DukeException e) { + System.out.println(e.getMessage()); } - System.out.println(listIn[totalNumber].toString()); - System.out.println("Now you have " + (totalNumber + 1) + " tasks in your list"); - System.out.println(dotsBreaker); + return taskNumber; } -} \ No newline at end of file +} + + + + + + + + + + diff --git a/src/main/java/duke/DukeException.java b/src/main/java/duke/DukeException.java index 5ea167092..20c3a7d93 100644 --- a/src/main/java/duke/DukeException.java +++ b/src/main/java/duke/DukeException.java @@ -1,4 +1,5 @@ package duke; + public class DukeException extends Exception { public DukeException(String errorMessage) { super(errorMessage); diff --git a/src/main/java/duke/data/task.txt b/src/main/java/duke/data/task.txt new file mode 100644 index 000000000..1a683f0c5 --- /dev/null +++ b/src/main/java/duke/data/task.txt @@ -0,0 +1 @@ +T | 0 | 1 diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index d62f1193d..edd3ebbda 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -6,10 +6,16 @@ public class Deadline extends Task { public Deadline(String name, String dueDate) { super(name); this.dueDate = dueDate; + this.taskType = "D"; } @Override public String toString() { - return "[D]" + super.toString() + " (by:" + dueDate + ")"; + return "[D]" + super.toString() + "(by:" + dueDate + ")"; + } + + @Override + public String getName() { + return this.name + " /by " + this.dueDate; } } \ No newline at end of file diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index c56010c02..c3b36dda6 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -6,10 +6,16 @@ public class Event extends Task { public Event(String name, String eventDate) { super(name); this.eventDate = eventDate; + this.taskType = "E"; } @Override public String toString() { return "[E]" + super.toString() + " (at:" + eventDate + ")"; } + + @Override + public String getName() { + return this.name + " /at " + this.eventDate; + } } \ No newline at end of file diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index e1fbd9a70..0f4f72958 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -3,6 +3,7 @@ public class Task { public String name; public boolean isDone; + public String taskType; public Task(String name) { this.name = name; @@ -20,4 +21,12 @@ public void markAsDone() { public String toString() { return getStatus() + this.name; } + + public String getType(){ + return taskType; + } + + public String getName() { + return this.name; + } } \ No newline at end of file diff --git a/src/main/java/duke/task/ToDo.java b/src/main/java/duke/task/ToDo.java index 0af19640c..a2fb49f26 100644 --- a/src/main/java/duke/task/ToDo.java +++ b/src/main/java/duke/task/ToDo.java @@ -3,6 +3,7 @@ public class ToDo extends Task{ public ToDo(String name) { super(name); + this.taskType = "T"; } @Override diff --git a/task.txt b/task.txt new file mode 100644 index 000000000..8b6a1a684 --- /dev/null +++ b/task.txt @@ -0,0 +1,2 @@ +T | 0 | 1 +T | 0 | 123 From 19771821095e9de6a40cec0119bf9d714a70f049 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Fri, 1 Oct 2021 23:20:54 +0800 Subject: [PATCH 15/24] Modified the code before making the OOP increment --- src/main/java/duke/Parser.java | 2 ++ src/main/java/duke/Storage.java | 2 ++ src/main/java/duke/TaskList.java | 2 ++ src/main/java/duke/UI.java | 2 ++ 4 files changed, 8 insertions(+) create mode 100644 src/main/java/duke/Parser.java create mode 100644 src/main/java/duke/Storage.java create mode 100644 src/main/java/duke/TaskList.java create mode 100644 src/main/java/duke/UI.java diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java new file mode 100644 index 000000000..fdca32faa --- /dev/null +++ b/src/main/java/duke/Parser.java @@ -0,0 +1,2 @@ +package duke;public class Parser { +} diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java new file mode 100644 index 000000000..89262bcb7 --- /dev/null +++ b/src/main/java/duke/Storage.java @@ -0,0 +1,2 @@ +package duke;public class Storage { +} diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java new file mode 100644 index 000000000..21e1f6cbe --- /dev/null +++ b/src/main/java/duke/TaskList.java @@ -0,0 +1,2 @@ +package duke;public class TaskList { +} diff --git a/src/main/java/duke/UI.java b/src/main/java/duke/UI.java new file mode 100644 index 000000000..341efbbdc --- /dev/null +++ b/src/main/java/duke/UI.java @@ -0,0 +1,2 @@ +package duke;public class UI { +} From a6b118112ef35f9d86b070b37ca4edf808c40dbf Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Sun, 3 Oct 2021 22:49:44 +0800 Subject: [PATCH 16/24] Make the code more OOP --- src/main/java/duke/Duke.java | 189 +------------------------------ src/main/java/duke/Parser.java | 37 +++++- src/main/java/duke/Storage.java | 55 ++++++++- src/main/java/duke/TaskList.java | 77 ++++++++++++- src/main/java/duke/UI.java | 51 ++++++++- src/main/java/duke/data/task.txt | 2 +- 6 files changed, 218 insertions(+), 193 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 4c55f3f71..28b64349c 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,194 +1,13 @@ package duke; -import duke.task.*; - -import java.util.Scanner; -import java.util.ArrayList; - -import java.io.File; -import java.io.FileWriter; - -import java.io.IOException; -import java.util.ArrayList; - public class Duke { - public static final ArrayList listInput = new ArrayList<>(); - public static final String BREAKER = "......................................................................"; - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo + "\n" + BREAKER + "\n" + "Hi! I'm Duke.\n" + "How can I make your life easier?\n" + BREAKER); - int taskNumber = 0; - taskNumber = getFromFile(listInput, taskNumber); - Scanner input = new Scanner(System.in); + UI.printWelcomeMessage(); String lineInput = ""; + Storage.getFromFile(); while (!lineInput.equals("bye")) { - lineInput = input.nextLine(); - String[] arrayInput = lineInput.split(" "); - String commandInput = arrayInput[0]; - System.out.println(BREAKER); - if (commandInput.equals(("bye"))) { - break; - } - try { - switch (commandInput) { - case "list": - try { - showTask(listInput, taskNumber); - } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { - System.out.println("OOPS!!! The index of the task that you entered does not exist:(\n"); - } - break; - case "done": - try { - doneTask(listInput, arrayInput[1]); - } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { - System.out.println("OOPS!!! The index of the task that you entered does not exist:(\n"); - } - break; - case "deadline": - case "event": - case "todo": - try { - recordTask(listInput, lineInput, taskNumber, commandInput); - taskNumber++; - } catch (StringIndexOutOfBoundsException e) { - System.out.println("OOPS!!! The name of the task that you entered is invalid:(\n"); - } - break; - case "delete": - try { - deleteTask(listInput, arrayInput, taskNumber); - taskNumber--; - } catch (NullPointerException | ArrayIndexOutOfBoundsException e) { - System.out.println("OOPS!!! The index of the task that you entered does not exist:(\n"); - } - break; - default: - throw new DukeException("OOPS!!! Sorry, but I do not understand:(\n"); - } - saveToFile(listInput, taskNumber); - } catch (IOException | DukeException e) { - System.out.println(e.getMessage()); - } - System.out.println(BREAKER); - } - - System.out.println("Byebye! Have a wonderful day!\n" + BREAKER); - } - - private static void showTask(ArrayList listInput, int taskNumber) { - if (taskNumber == 0) { - System.out.println("The list is empty! Add something to it:)"); - } else { - System.out.println("Here are the tasks in your list:"); - for (int i = 0; i < taskNumber; i++) { - System.out.println((i + 1) + "." + listInput.get(i).toString()); - } - } - } - - private static void doneTask(ArrayList listInput, String arrayInput) { - int inputIndex = Integer.parseInt(arrayInput) - 1; - ((Task) listInput.get(inputIndex)).markAsDone(); - System.out.println("Wonderful! This task is now marked as done:\n" + listInput.get(inputIndex).toString()); - } - - private static void deleteTask(ArrayList listInput, String[] arrayInput, int taskNumber) { - int inputIndex = Integer.parseInt(arrayInput[1]) - 1; - System.out.println("Alright, the following task has been removed\n" + listInput.get(inputIndex).toString() + "\n" + "Now you have " + (taskNumber - 1) + " tasks left"); - listInput.remove(inputIndex); - } - - private static void recordTask(ArrayList listInput, String lineInput, int taskNumber, String commandInput) throws DukeException { - switch (commandInput) { - case "event": - recordEvent(listInput, lineInput, taskNumber); - break; - case "deadline": - recordDeadline(listInput, lineInput, taskNumber); - break; - case "todo": - recordToDo(listInput, lineInput, taskNumber); - break; - } - System.out.println("Got it. I've added this task:\n" + listInput.get(taskNumber).toString() + "\n" + "Now you have " + (taskNumber + 1) + " tasks in your list"); - } - - private static void recordDeadline(ArrayList listInput, String lineInput, int taskNumber) throws DukeException { - int breakIndex = lineInput.indexOf("/"); - if (lineInput.length() < 12) { - throw new DukeException("The description of the deadline is too short! Please enter again.\n"); - } - String deadlineName = lineInput.substring(9, breakIndex); - String deadlineDate = lineInput.substring(breakIndex + 3); - listInput.add(taskNumber, new Deadline(deadlineName, deadlineDate)); - } - - private static void recordEvent(ArrayList listInput, String lineInput, int taskNumber) throws DukeException { - int breakIndex = lineInput.indexOf("/"); - if (lineInput.length() < 9) { - throw new DukeException("The description of the event is too short! Please enter again.\n"); - } - String eventName = lineInput.substring(6, breakIndex); - String eventDate = lineInput.substring(breakIndex + 3); - listInput.add(taskNumber, new Event(eventName, eventDate)); - } - - private static void recordToDo(ArrayList listInput, String lineInput, int taskNumber) { - String todoName = lineInput.substring(5); - listInput.add(taskNumber, new ToDo(todoName)); - } - - public static void saveToFile(ArrayList listInput, int numTask) throws IOException { - FileWriter file = new FileWriter("src/main/java/duke/data/task.txt"); - for (int i = 0; i < numTask; i++) { - String saveInput = ((Task) listInput.get(i)).getType() + " | " + getNumberStatus(listInput, i) + " | " + ((Task) listInput.get(i)).getName() + "\n"; - file.write(saveInput); - } - file.close(); - } - - private static String getNumberStatus(ArrayList listInput, int taskNumber) { - if (((Task) listInput.get(taskNumber)).getStatus().equals("[X]")) { - return "1"; - } else { - return "0"; - } - } - - private static int getFromFile(ArrayList listInput, int taskNumber) { - try { - File file = new File("src/main/java/duke/data/task.txt"); - Scanner updateInput = new Scanner(file); - while (updateInput.hasNext()) { - String[] lineInput = updateInput.nextLine().split("\\|"); - String taskType = lineInput[0]; - switch (taskType) { - case "D ": - recordDeadline(listInput, "deadline" + lineInput[2], taskNumber); - break; - case "E ": - recordEvent(listInput, "event" + lineInput[2], taskNumber); - break; - case "T ": - recordToDo(listInput, "todo" + lineInput[2], taskNumber); - break; - } - if (lineInput[1].equals("1")) { - ((Task) listInput.get(taskNumber)).markAsDone(); - } - taskNumber++; - } - } catch (IOException e) { - System.out.println("There is no saved file:( but I will create a new one for you:)\n" + BREAKER); - } catch (DukeException e) { - System.out.println(e.getMessage()); + lineInput = UI.getInput(); + Parser.parseInput(lineInput); } - return taskNumber; } } \ No newline at end of file diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index fdca32faa..06551d6bb 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -1,2 +1,35 @@ -package duke;public class Parser { -} +package duke; + +public class Parser { + public static void parseInput(String lineInput) { + String[] arrayInput = lineInput.split(" "); + String commandInput = arrayInput[0]; + try { + switch (commandInput) { + case "list": + TaskList.showTask(); + break; + case "done": + TaskList.doneTask(Integer.parseInt(arrayInput[1])); + break; + case "delete": + TaskList.deleteTask(Integer.parseInt(arrayInput[1])); + break; + case "deadline": + case "event": + case "todo": + TaskList.recordTask(commandInput, lineInput); + break; + case "bye": + UI.printByeMessage(); + break; + default: + System.out.println("OOPS!!! Sorry, but I do not understand:("); + break; + } + } catch (ArrayIndexOutOfBoundsException | DukeException e) { + System.out.println("OOPS!!! Please enter a valid input:("); + UI.printBreaker(); + } + } +} \ No newline at end of file diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index 89262bcb7..f43a4067d 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -1,2 +1,55 @@ -package duke;public class Storage { +package duke; + +import duke.task.*; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +public class Storage { + public static void getFromFile() { + try { + File file = new File("src/main/java/duke/data/task.txt"); + Scanner updateInput = new Scanner(file); + int taskNumber = 1; + while (updateInput.hasNext()) { + String[] lineInput = updateInput.nextLine().split("\\|"); + switch (lineInput[0]) { + case "D ": + TaskList.recordTask("deadline", "deadline" + lineInput[2]); + break; + case "E ": + TaskList.recordTask("deadline", "event" + lineInput[2]); + break; + case "T ": + TaskList.recordTask("deadline", "todo" + lineInput[2]); + break; + } + if (lineInput[1].equals(" 1 ")) { + TaskList.doneTask(taskNumber); + } + taskNumber++; + } + } catch (IOException | DukeException e) { + System.out.println("There is no saved file:( but I will create a new one for you:)"); + UI.printBreaker(); + } + } + + public static void saveToFile(ArrayList listInput, int taskNumber) { + try { + FileWriter file = new FileWriter("src/main/java/duke/data/task.txt"); + for (int i = 0; i < taskNumber; i++) { + String numberStatus = ((listInput.get(i)).getStatus().equals("[X] ") ? "1" : "0"); + String taskType = (listInput.get(i)).getType(); + String taskName = (listInput.get(i)).getName(); + file.write(taskType + " | " + numberStatus + " | " + taskName + "\n"); + } + file.close(); + }catch (IOException e) { + System.out.println("There is no valid file:("); + } + } } diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index 21e1f6cbe..c1bb31534 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -1,2 +1,75 @@ -package duke;public class TaskList { -} +package duke; + +import duke.task.*; + +import java.util.ArrayList; + +public class TaskList { + private static final ArrayList listInput = new ArrayList<>(); + private static int taskNumber = 0; + + public static void showTask() { + if (taskNumber <= 0) { + System.out.println("The list is empty! Add something to it:)"); + } else { + System.out.println("Here are the tasks in your list:"); + for (int i = 0; i < taskNumber; i++) { + System.out.println((i + 1) + "." + listInput.get(i).toString()); + } + } + UI.printBreaker(); + } + + public static void doneTask(int inputIndex) { + try { + listInput.get(inputIndex).markAsDone(); + UI.printDoneTask(listInput.get(inputIndex - 1).toString()); + Storage.saveToFile(listInput, taskNumber); + } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { + System.out.println("OOPS!!! The index of the task that you entered does not exist:("); + UI.printBreaker(); + } + } + + public static void deleteTask(int inputIndex) { + try { + listInput.remove(inputIndex); + UI.printDeleteTask(taskNumber, listInput.get(inputIndex - 1).toString()); + taskNumber--; + Storage.saveToFile(listInput, taskNumber); + } catch (NullPointerException | ArrayIndexOutOfBoundsException e) { + System.out.println("OOPS!!! The index of the task that you entered does not exist:("); + UI.printBreaker(); + } + } + + public static void recordTask(String commandInput, String lineInput) throws DukeException { + int breakIndex = lineInput.indexOf("/"); + try { + switch (commandInput) { + case "deadline": + if (lineInput.length() < 12) { + throw new DukeException("The description of the deadline is too short! Please enter again.\n"); + } + listInput.add(taskNumber, new Deadline(lineInput.substring(9, breakIndex), lineInput.substring(breakIndex + 3))); + UI.printRecordTask(taskNumber, new Deadline(lineInput.substring(6, breakIndex), lineInput.substring(breakIndex + 3))); + break; + case "event": + if (lineInput.length() < 9) { + throw new DukeException("The description of the event is too short! Please enter again.\n"); + } + listInput.add(taskNumber, new Event(lineInput.substring(6, breakIndex), lineInput.substring(breakIndex + 3))); + UI.printRecordTask(taskNumber, new Event(lineInput.substring(6, breakIndex), lineInput.substring(breakIndex + 3))); + break; + case "todo": + listInput.add(taskNumber, new ToDo(lineInput.substring(5))); + UI.printRecordTask(taskNumber, new ToDo(lineInput.substring(5))); + break; + } + Storage.saveToFile(listInput, taskNumber); + }catch (DukeException e) { + System.out.println("OOPS!!! Sorry, but I do not understand:("); + UI.printBreaker(); + } + } +} \ No newline at end of file diff --git a/src/main/java/duke/UI.java b/src/main/java/duke/UI.java index 341efbbdc..53585c334 100644 --- a/src/main/java/duke/UI.java +++ b/src/main/java/duke/UI.java @@ -1,2 +1,49 @@ -package duke;public class UI { -} +package duke; + +import duke.task.Task; +import java.util.Scanner; + +public class UI { + public static void printBreaker() { + System.out.println("......................................................................"); + } + + public static void printWelcomeMessage() { + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + System.out.println("Hello from\n" + logo); + printBreaker(); + System.out.println("Hi! I'm Duke.\n" + "How can I make your life easier?"); + printBreaker(); + } + + public static void printByeMessage() { + System.out.println("Bye bye! Have a wonderful day!"); + printBreaker(); + } + + public static void printDoneTask(String taskDone) { + System.out.println("Wonderful! This task is now marked as done:\n" + taskDone); + printBreaker(); + } + + public static void printDeleteTask(int taskNumber, String taskDelete) { + System.out.println("Alright, the following task has been removed\n" + taskDelete + "\n" + "Now you have " + (taskNumber - 1) + " tasks left."); + printBreaker(); + } + + public static void printRecordTask(int taskNumber, Task taskRecord) { + System.out.println("Got it. I've added this task:\n" + taskRecord.toString() + "\n" + "Now you have " + (taskNumber + 1) + " tasks in your list."); + printBreaker(); + } + + public static String getInput() { + String lineInput; + Scanner input = new Scanner(System.in); + lineInput = input.nextLine(); + return lineInput; + } +} \ No newline at end of file diff --git a/src/main/java/duke/data/task.txt b/src/main/java/duke/data/task.txt index 1a683f0c5..0652327fb 100644 --- a/src/main/java/duke/data/task.txt +++ b/src/main/java/duke/data/task.txt @@ -1 +1 @@ -T | 0 | 1 +T | 0 | 1 \ No newline at end of file From 3e382bcf96d97f589b5cc8237bc789bb82314d20 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Sun, 3 Oct 2021 23:06:23 +0800 Subject: [PATCH 17/24] Add Increment: Level 9. Find --- src/main/java/duke/Parser.java | 5 +++++ src/main/java/duke/TaskList.java | 8 ++++++++ src/main/java/duke/UI.java | 16 +++++++++++++++- src/main/java/duke/data/task.txt | 1 - 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 06551d6bb..0418834d1 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -1,5 +1,7 @@ package duke; +import duke.task.*; + public class Parser { public static void parseInput(String lineInput) { String[] arrayInput = lineInput.split(" "); @@ -9,6 +11,9 @@ public static void parseInput(String lineInput) { case "list": TaskList.showTask(); break; + case "find": + TaskList.findTask(arrayInput); + break; case "done": TaskList.doneTask(Integer.parseInt(arrayInput[1])); break; diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index c1bb31534..8648cf0f1 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -4,6 +4,9 @@ import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + public class TaskList { private static final ArrayList listInput = new ArrayList<>(); private static int taskNumber = 0; @@ -20,6 +23,11 @@ public static void showTask() { UI.printBreaker(); } + public static void findTask(String[] arrayInput) { + UI.printFindTask(listInput.stream().filter(t -> t.getName().contains(arrayInput[1])).collect(Collectors.toList())); + UI.printBreaker(); + } + public static void doneTask(int inputIndex) { try { listInput.get(inputIndex).markAsDone(); diff --git a/src/main/java/duke/UI.java b/src/main/java/duke/UI.java index 53585c334..859575d02 100644 --- a/src/main/java/duke/UI.java +++ b/src/main/java/duke/UI.java @@ -1,8 +1,11 @@ package duke; -import duke.task.Task; +import duke.task.*; + import java.util.Scanner; +import java.util.List; + public class UI { public static void printBreaker() { System.out.println("......................................................................"); @@ -25,6 +28,17 @@ public static void printByeMessage() { printBreaker(); } + public static void printFindTask(List taskFind) { + if (taskFind.size() == 0) { + System.out.println("OPPS!!! No matches found:("); + } else { + System.out.println("Here is the task that you are looking for:)"); + for (int i = 0; i < taskFind.size(); i++) { + System.out.println((i + 1) + "." + taskFind.get(i).toString()); + } + } + } + public static void printDoneTask(String taskDone) { System.out.println("Wonderful! This task is now marked as done:\n" + taskDone); printBreaker(); diff --git a/src/main/java/duke/data/task.txt b/src/main/java/duke/data/task.txt index 0652327fb..e69de29bb 100644 --- a/src/main/java/duke/data/task.txt +++ b/src/main/java/duke/data/task.txt @@ -1 +0,0 @@ -T | 0 | 1 \ No newline at end of file From 81c854ade2a113de4f8c69569dde6e8be3d85cdb Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Sun, 3 Oct 2021 23:09:41 +0800 Subject: [PATCH 18/24] Revert "Add Increment: Level 9. Find" This reverts commit 3e382bcf96d97f589b5cc8237bc789bb82314d20. --- src/main/java/duke/Parser.java | 5 ----- src/main/java/duke/TaskList.java | 8 -------- src/main/java/duke/UI.java | 16 +--------------- src/main/java/duke/data/task.txt | 1 + 4 files changed, 2 insertions(+), 28 deletions(-) diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 0418834d1..06551d6bb 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -1,7 +1,5 @@ package duke; -import duke.task.*; - public class Parser { public static void parseInput(String lineInput) { String[] arrayInput = lineInput.split(" "); @@ -11,9 +9,6 @@ public static void parseInput(String lineInput) { case "list": TaskList.showTask(); break; - case "find": - TaskList.findTask(arrayInput); - break; case "done": TaskList.doneTask(Integer.parseInt(arrayInput[1])); break; diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index 8648cf0f1..c1bb31534 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -4,9 +4,6 @@ import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - public class TaskList { private static final ArrayList listInput = new ArrayList<>(); private static int taskNumber = 0; @@ -23,11 +20,6 @@ public static void showTask() { UI.printBreaker(); } - public static void findTask(String[] arrayInput) { - UI.printFindTask(listInput.stream().filter(t -> t.getName().contains(arrayInput[1])).collect(Collectors.toList())); - UI.printBreaker(); - } - public static void doneTask(int inputIndex) { try { listInput.get(inputIndex).markAsDone(); diff --git a/src/main/java/duke/UI.java b/src/main/java/duke/UI.java index 859575d02..53585c334 100644 --- a/src/main/java/duke/UI.java +++ b/src/main/java/duke/UI.java @@ -1,11 +1,8 @@ package duke; -import duke.task.*; - +import duke.task.Task; import java.util.Scanner; -import java.util.List; - public class UI { public static void printBreaker() { System.out.println("......................................................................"); @@ -28,17 +25,6 @@ public static void printByeMessage() { printBreaker(); } - public static void printFindTask(List taskFind) { - if (taskFind.size() == 0) { - System.out.println("OPPS!!! No matches found:("); - } else { - System.out.println("Here is the task that you are looking for:)"); - for (int i = 0; i < taskFind.size(); i++) { - System.out.println((i + 1) + "." + taskFind.get(i).toString()); - } - } - } - public static void printDoneTask(String taskDone) { System.out.println("Wonderful! This task is now marked as done:\n" + taskDone); printBreaker(); diff --git a/src/main/java/duke/data/task.txt b/src/main/java/duke/data/task.txt index e69de29bb..0652327fb 100644 --- a/src/main/java/duke/data/task.txt +++ b/src/main/java/duke/data/task.txt @@ -0,0 +1 @@ +T | 0 | 1 \ No newline at end of file From af72749023c40c41224dfc72ac80067532129fc1 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Sun, 3 Oct 2021 23:11:40 +0800 Subject: [PATCH 19/24] Add-Increment: Level 9.Find --- src/main/java/duke/Duke.java | 2 +- src/main/java/duke/Parser.java | 2 +- src/main/java/duke/Storage.java | 2 +- src/main/java/duke/TaskList.java | 2 +- src/main/java/duke/UI.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 28b64349c..354b02d74 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -10,4 +10,4 @@ public static void main(String[] args) { Parser.parseInput(lineInput); } } -} \ No newline at end of file +} diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 06551d6bb..56cf1e92f 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -32,4 +32,4 @@ public static void parseInput(String lineInput) { UI.printBreaker(); } } -} \ No newline at end of file +} diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index f43a4067d..f8546b976 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -52,4 +52,4 @@ public static void saveToFile(ArrayList listInput, int taskNumber) { System.out.println("There is no valid file:("); } } -} +} \ No newline at end of file diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index c1bb31534..29d27e256 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -72,4 +72,4 @@ public static void recordTask(String commandInput, String lineInput) throws Duke UI.printBreaker(); } } -} \ No newline at end of file +} diff --git a/src/main/java/duke/UI.java b/src/main/java/duke/UI.java index 53585c334..258bcd994 100644 --- a/src/main/java/duke/UI.java +++ b/src/main/java/duke/UI.java @@ -46,4 +46,4 @@ public static String getInput() { lineInput = input.nextLine(); return lineInput; } -} \ No newline at end of file +} From 59808e6c3f38599ae17dd11586e1607c76d92a35 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Sun, 3 Oct 2021 23:42:49 +0800 Subject: [PATCH 20/24] Add a User Guide and update the files --- README.md | 105 ++++++++++++++++++++++++------- src/main/java/duke/Duke.java | 10 +-- src/main/java/duke/Parser.java | 19 +++--- src/main/java/duke/Storage.java | 10 +-- src/main/java/duke/TaskList.java | 34 ++++++---- src/main/java/duke/UI.java | 18 +++++- 6 files changed, 140 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 0f2208ab6..c7f0455a3 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,81 @@ -# duke.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. - -## Setting up in Intellij - -Prerequisites: JDK 11, update Intellij to the most recent version. - -1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) -1. Open the project into Intellij as follows: - 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 1. If there are any further prompts, accept the defaults. -1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
- In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/duke.Duke.java` file, right-click it, and choose `Run duke.Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: - ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +# User Guide + +Duke is a CLI task-managing app to help you and make your life easier. + +##Quick Start +1. Ensure you have Java 11 or above installed in your computer. +2. Download the latest Duke JAR file from github. +3. Locate the JAR file into a folder which you will run it from. +4. Navigate to this folder using CLI and run the command `java -jar ip.jar` +5. You can now start using Duke by typing the features command directly! + +## Features + +### Showing all tasks: `list` + +Shows all tasks in the task list. + +* Format: `list` + +### Finding a task: `find` + +Finds a task in the task list. + +* Format: `find TASK` +* Example: `find study` + +### Marking a task as done: `done` + +Marks the task as done. + +* Format: `done TASK_INDEX` +* TASK_INDEX is a positive number which refer to the task. +* Example: `done 1` + +### Deleting a task: `delete` + +Deletes a task from the task list. + +* Format: `delete TASK_INDEX` +* TASK_INDEX is a positive number which refer to the task. +* Example: `delete 1` + +### Recording a deadline task: `deadline` + +Adds a deadline task into the task list. + +* Format: `deadline TASK_NAME /by TASK_TIME` +* Example: `deadline sleep /by 11p.m.` + +### Recording a event task: `event` + +Adds a event task into the task list. + +* Format: `event TASK_NAME /at TASK_TIME` +* Example: `event eat /at 11a.m.` + +### Recording a todo task: `todo` + +Adds a todo task into the task list. + +* Format: `todo TASK_NAME` +* Example: `todo study` + +### Exiting the program: `bye` + +Exits the program. + +* Format: `bye` + +## Command Summary + +Action | Format & Example +-------|----------------- +Show all tasks|`list` +Find a task|`find TASK` (eg. `find work`) +Mark a task as done|`done TASK_INDEX` (eg. `done 1`) +Delete a task|`delete TASK_INDEX` (eg. `delete 1`) +Record a deadline task| `deadline deadline TASK_NAME /by TASK_TIME` (eg. `deadline sleep /by 11p.m.`) +Record a event task|`event TASK_NAME /at TASK_TIME` (eg. `event eat /at 11a.m.`) +Record a todo task| `todo TASK_NAME` (eg. `todo study`) +Exit the program|`bye` \ No newline at end of file diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 354b02d74..ea781800b 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -2,12 +2,12 @@ public class Duke { public static void main(String[] args) { - UI.printWelcomeMessage(); + duke.UI.printWelcomeMessage(); String lineInput = ""; - Storage.getFromFile(); + duke.Storage.getFromFile(); while (!lineInput.equals("bye")) { - lineInput = UI.getInput(); - Parser.parseInput(lineInput); + lineInput = duke.UI.getInput(); + duke.Parser.parseInput(lineInput); } } -} +} \ No newline at end of file diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 56cf1e92f..9b25c4fb3 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -1,5 +1,7 @@ package duke; +import duke.task.*; + public class Parser { public static void parseInput(String lineInput) { String[] arrayInput = lineInput.split(" "); @@ -7,21 +9,24 @@ public static void parseInput(String lineInput) { try { switch (commandInput) { case "list": - TaskList.showTask(); + duke.TaskList.showTask(); + break; + case "find": + duke.TaskList.findTask(arrayInput); break; case "done": - TaskList.doneTask(Integer.parseInt(arrayInput[1])); + duke.TaskList.doneTask(Integer.parseInt(arrayInput[1])); break; case "delete": - TaskList.deleteTask(Integer.parseInt(arrayInput[1])); + duke.TaskList.deleteTask(Integer.parseInt(arrayInput[1])); break; case "deadline": case "event": case "todo": - TaskList.recordTask(commandInput, lineInput); + duke.TaskList.recordTask(commandInput, lineInput); break; case "bye": - UI.printByeMessage(); + duke.UI.printByeMessage(); break; default: System.out.println("OOPS!!! Sorry, but I do not understand:("); @@ -29,7 +34,7 @@ public static void parseInput(String lineInput) { } } catch (ArrayIndexOutOfBoundsException | DukeException e) { System.out.println("OOPS!!! Please enter a valid input:("); - UI.printBreaker(); + duke.UI.printBreaker(); } } -} +} \ No newline at end of file diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index f8546b976..d0dfa1c4e 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -18,23 +18,23 @@ public static void getFromFile() { String[] lineInput = updateInput.nextLine().split("\\|"); switch (lineInput[0]) { case "D ": - TaskList.recordTask("deadline", "deadline" + lineInput[2]); + duke.TaskList.recordTask("deadline", "deadline" + lineInput[2]); break; case "E ": - TaskList.recordTask("deadline", "event" + lineInput[2]); + duke.TaskList.recordTask("deadline", "event" + lineInput[2]); break; case "T ": - TaskList.recordTask("deadline", "todo" + lineInput[2]); + duke.TaskList.recordTask("deadline", "todo" + lineInput[2]); break; } if (lineInput[1].equals(" 1 ")) { - TaskList.doneTask(taskNumber); + duke.TaskList.doneTask(taskNumber); } taskNumber++; } } catch (IOException | DukeException e) { System.out.println("There is no saved file:( but I will create a new one for you:)"); - UI.printBreaker(); + duke.UI.printBreaker(); } } diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index 29d27e256..7cf3170b4 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -4,6 +4,9 @@ import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + public class TaskList { private static final ArrayList listInput = new ArrayList<>(); private static int taskNumber = 0; @@ -17,29 +20,34 @@ public static void showTask() { System.out.println((i + 1) + "." + listInput.get(i).toString()); } } - UI.printBreaker(); + duke.UI.printBreaker(); + } + + public static void findTask(String[] arrayInput) { + duke.UI.printFindTask(listInput.stream().filter(t -> t.getName().contains(arrayInput[1])).collect(Collectors.toList())); + duke.UI.printBreaker(); } public static void doneTask(int inputIndex) { try { listInput.get(inputIndex).markAsDone(); - UI.printDoneTask(listInput.get(inputIndex - 1).toString()); - Storage.saveToFile(listInput, taskNumber); + duke.UI.printDoneTask(listInput.get(inputIndex - 1).toString()); + duke.Storage.saveToFile(listInput, taskNumber); } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { System.out.println("OOPS!!! The index of the task that you entered does not exist:("); - UI.printBreaker(); + duke.UI.printBreaker(); } } public static void deleteTask(int inputIndex) { try { listInput.remove(inputIndex); - UI.printDeleteTask(taskNumber, listInput.get(inputIndex - 1).toString()); + duke.UI.printDeleteTask(taskNumber, listInput.get(inputIndex - 1).toString()); taskNumber--; - Storage.saveToFile(listInput, taskNumber); + duke.Storage.saveToFile(listInput, taskNumber); } catch (NullPointerException | ArrayIndexOutOfBoundsException e) { System.out.println("OOPS!!! The index of the task that you entered does not exist:("); - UI.printBreaker(); + duke.UI.printBreaker(); } } @@ -52,24 +60,24 @@ public static void recordTask(String commandInput, String lineInput) throws Duke throw new DukeException("The description of the deadline is too short! Please enter again.\n"); } listInput.add(taskNumber, new Deadline(lineInput.substring(9, breakIndex), lineInput.substring(breakIndex + 3))); - UI.printRecordTask(taskNumber, new Deadline(lineInput.substring(6, breakIndex), lineInput.substring(breakIndex + 3))); + duke.UI.printRecordTask(taskNumber, new Deadline(lineInput.substring(6, breakIndex), lineInput.substring(breakIndex + 3))); break; case "event": if (lineInput.length() < 9) { throw new DukeException("The description of the event is too short! Please enter again.\n"); } listInput.add(taskNumber, new Event(lineInput.substring(6, breakIndex), lineInput.substring(breakIndex + 3))); - UI.printRecordTask(taskNumber, new Event(lineInput.substring(6, breakIndex), lineInput.substring(breakIndex + 3))); + duke.UI.printRecordTask(taskNumber, new Event(lineInput.substring(6, breakIndex), lineInput.substring(breakIndex + 3))); break; case "todo": listInput.add(taskNumber, new ToDo(lineInput.substring(5))); - UI.printRecordTask(taskNumber, new ToDo(lineInput.substring(5))); + duke.UI.printRecordTask(taskNumber, new ToDo(lineInput.substring(5))); break; } - Storage.saveToFile(listInput, taskNumber); + duke.Storage.saveToFile(listInput, taskNumber); }catch (DukeException e) { System.out.println("OOPS!!! Sorry, but I do not understand:("); - UI.printBreaker(); + duke.UI.printBreaker(); } } -} +} \ No newline at end of file diff --git a/src/main/java/duke/UI.java b/src/main/java/duke/UI.java index 258bcd994..859575d02 100644 --- a/src/main/java/duke/UI.java +++ b/src/main/java/duke/UI.java @@ -1,8 +1,11 @@ package duke; -import duke.task.Task; +import duke.task.*; + import java.util.Scanner; +import java.util.List; + public class UI { public static void printBreaker() { System.out.println("......................................................................"); @@ -25,6 +28,17 @@ public static void printByeMessage() { printBreaker(); } + public static void printFindTask(List taskFind) { + if (taskFind.size() == 0) { + System.out.println("OPPS!!! No matches found:("); + } else { + System.out.println("Here is the task that you are looking for:)"); + for (int i = 0; i < taskFind.size(); i++) { + System.out.println((i + 1) + "." + taskFind.get(i).toString()); + } + } + } + public static void printDoneTask(String taskDone) { System.out.println("Wonderful! This task is now marked as done:\n" + taskDone); printBreaker(); @@ -46,4 +60,4 @@ public static String getInput() { lineInput = input.nextLine(); return lineInput; } -} +} \ No newline at end of file From 5f0972426a0b071b9ba381ad5b23bad944fef56a Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Fri, 8 Oct 2021 07:29:03 +0800 Subject: [PATCH 21/24] Fixed all errors in the files and added JavaDoc comments --- src/main/java/duke/Duke.java | 23 +++-- src/main/java/duke/DukeException.java | 7 -- src/main/java/duke/DukeExceptions.java | 8 ++ src/main/java/duke/Parser.java | 40 +++++--- src/main/java/duke/Storage.java | 50 ++++++---- src/main/java/duke/TaskList.java | 121 ++++++++++++++++--------- src/main/java/duke/UI.java | 82 ++++++++++++----- src/main/java/duke/data/task.txt | 5 +- src/main/java/duke/task/Deadline.java | 22 +++-- src/main/java/duke/task/Event.java | 22 +++-- src/main/java/duke/task/Task.java | 32 ++++--- src/main/java/duke/task/ToDo.java | 10 +- task.txt | 2 - 13 files changed, 275 insertions(+), 149 deletions(-) delete mode 100644 src/main/java/duke/DukeException.java create mode 100644 src/main/java/duke/DukeExceptions.java delete mode 100644 task.txt diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index ea781800b..a09171ffd 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,13 +1,22 @@ package duke; +import java.util.Scanner; + +/** + * Shows the main class of Duke. + */ public class Duke { + public static void main(String[] args) { - duke.UI.printWelcomeMessage(); - String lineInput = ""; - duke.Storage.getFromFile(); - while (!lineInput.equals("bye")) { - lineInput = duke.UI.getInput(); - duke.Parser.parseInput(lineInput); - } + UI.printWelcomeMessage(); + String lineInput; + Storage.getFromFile(); + do { + Scanner input = new Scanner(System.in); + lineInput = input.nextLine(); + Parser.parseInput(lineInput); + UI.printBreaker(); + } while (!lineInput.equals("bye")); + UI.printByeMessage(); } } \ No newline at end of file diff --git a/src/main/java/duke/DukeException.java b/src/main/java/duke/DukeException.java deleted file mode 100644 index 20c3a7d93..000000000 --- a/src/main/java/duke/DukeException.java +++ /dev/null @@ -1,7 +0,0 @@ -package duke; - -public class DukeException extends Exception { - public DukeException(String errorMessage) { - super(errorMessage); - } -} \ No newline at end of file diff --git a/src/main/java/duke/DukeExceptions.java b/src/main/java/duke/DukeExceptions.java new file mode 100644 index 000000000..6b69ec1a1 --- /dev/null +++ b/src/main/java/duke/DukeExceptions.java @@ -0,0 +1,8 @@ +package duke; + +public class DukeExceptions extends Exception{ + + public DukeExceptions(String errorMessage) { + super(errorMessage); + } +} \ No newline at end of file diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 9b25c4fb3..44d070972 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -2,39 +2,49 @@ import duke.task.*; +/** + * Formats the inputs to pass to different methods. + */ public class Parser { - public static void parseInput(String lineInput) { + + /** + * Formats the input sent from the user and pass it to different methods accordingly. + * + * @param lineInput The line input from the user. + */ + public static void parseInput(String lineInput) { + boolean printMessage = true; String[] arrayInput = lineInput.split(" "); - String commandInput = arrayInput[0]; + String userCommand = arrayInput[0]; try { - switch (commandInput) { + switch (userCommand) { case "list": - duke.TaskList.showTask(); - break; - case "find": - duke.TaskList.findTask(arrayInput); + TaskList.showTask(); break; case "done": - duke.TaskList.doneTask(Integer.parseInt(arrayInput[1])); + int doneIndex = Integer.parseInt(arrayInput[1]); + TaskList.doneTask(doneIndex, printMessage); break; - case "delete": - duke.TaskList.deleteTask(Integer.parseInt(arrayInput[1])); + case "find": + TaskList.searchTask(arrayInput); break; - case "deadline": case "event": case "todo": - duke.TaskList.recordTask(commandInput, lineInput); + case "deadline": + TaskList.recordTask(userCommand, lineInput, printMessage); + break; + case "delete": + String deleteIndex = arrayInput[1]; + TaskList.deleteTask(deleteIndex); break; case "bye": - duke.UI.printByeMessage(); break; default: System.out.println("OOPS!!! Sorry, but I do not understand:("); break; } - } catch (ArrayIndexOutOfBoundsException | DukeException e) { + } catch (ArrayIndexOutOfBoundsException | NumberFormatException | StringIndexOutOfBoundsException e) { System.out.println("OOPS!!! Please enter a valid input:("); - duke.UI.printBreaker(); } } } \ No newline at end of file diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index d0dfa1c4e..f3f0e00e2 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -1,54 +1,70 @@ package duke; -import duke.task.*; +import java.util.Scanner; + +import java.io.IOException; import java.io.File; import java.io.FileWriter; -import java.io.IOException; + import java.util.ArrayList; -import java.util.Scanner; +import duke.task.*; + +/** + * Reads from a text file and writes to the file to store tasks. + */ public class Storage { + + /** + * Gets the task list from the file. + */ public static void getFromFile() { try { File file = new File("src/main/java/duke/data/task.txt"); + file.createNewFile(); Scanner updateInput = new Scanner(file); + boolean printMessage = false; int taskNumber = 1; while (updateInput.hasNext()) { - String[] lineInput = updateInput.nextLine().split("\\|"); - switch (lineInput[0]) { + String[] arrayInput = updateInput.nextLine().split("\\|"); + switch (arrayInput[0]) { case "D ": - duke.TaskList.recordTask("deadline", "deadline" + lineInput[2]); + TaskList.recordTask("deadline", "deadline" + arrayInput[2], printMessage); break; case "E ": - duke.TaskList.recordTask("deadline", "event" + lineInput[2]); + TaskList.recordTask("event", "event" + arrayInput[2], printMessage); break; case "T ": - duke.TaskList.recordTask("deadline", "todo" + lineInput[2]); + TaskList.recordTask("todo", "todo" + arrayInput[2], printMessage); break; } - if (lineInput[1].equals(" 1 ")) { - duke.TaskList.doneTask(taskNumber); + if (arrayInput[1].equals(" 1 ")) { + TaskList.doneTask(taskNumber, printMessage); } taskNumber++; } - } catch (IOException | DukeException e) { + } catch (IOException e) { System.out.println("There is no saved file:( but I will create a new one for you:)"); - duke.UI.printBreaker(); } } + /** + * Saves the task list to the file. + * + * @param listInput The task list to be saved. + * @param taskNumber The integer total number of tasks in the list. + */ public static void saveToFile(ArrayList listInput, int taskNumber) { try { FileWriter file = new FileWriter("src/main/java/duke/data/task.txt"); for (int i = 0; i < taskNumber; i++) { - String numberStatus = ((listInput.get(i)).getStatus().equals("[X] ") ? "1" : "0"); - String taskType = (listInput.get(i)).getType(); - String taskName = (listInput.get(i)).getName(); - file.write(taskType + " | " + numberStatus + " | " + taskName + "\n"); + String numberStatus = ((listInput.get(i).getTaskStatus().equals("[X] "))? "1" : "0"); + String stringToSave = listInput.get(i).getTaskType() + " | " + numberStatus + " | " + listInput.get(i).getTaskDescription() + "\n"; + file.write(stringToSave); } file.close(); - }catch (IOException e) { + } catch (IOException e) { System.out.println("There is no valid file:("); } } diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index 7cf3170b4..8eed1dc48 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -1,18 +1,26 @@ package duke; -import duke.task.*; +import java.util.stream.Collectors; import java.util.ArrayList; - import java.util.List; -import java.util.stream.Collectors; +import duke.task.*; + +/** + * Classifies different actions on the list into various methods. + */ public class TaskList { + private static final ArrayList listInput = new ArrayList<>(); private static int taskNumber = 0; + /** + * Prints the list of the tasks. + */ public static void showTask() { - if (taskNumber <= 0) { + UI.printBreaker(); + if (taskNumber == 0) { System.out.println("The list is empty! Add something to it:)"); } else { System.out.println("Here are the tasks in your list:"); @@ -20,64 +28,95 @@ public static void showTask() { System.out.println((i + 1) + "." + listInput.get(i).toString()); } } - duke.UI.printBreaker(); } - public static void findTask(String[] arrayInput) { - duke.UI.printFindTask(listInput.stream().filter(t -> t.getName().contains(arrayInput[1])).collect(Collectors.toList())); - duke.UI.printBreaker(); - } - - public static void doneTask(int inputIndex) { + /** + * Marks a task as done. + * + * @param inputIndex The index of the task done. + * @param printMessage The flag of whether or not to print the summary message after the action. + */ + public static void doneTask(int inputIndex, boolean printMessage) { try { - listInput.get(inputIndex).markAsDone(); - duke.UI.printDoneTask(listInput.get(inputIndex - 1).toString()); - duke.Storage.saveToFile(listInput, taskNumber); - } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { + listInput.get(inputIndex - 1).markAsDone(); + if (printMessage) { + UI.printDoneTask(listInput.get(inputIndex -1).toString()); + } + Storage.saveToFile(listInput, taskNumber); + } catch (NumberFormatException | IndexOutOfBoundsException e) { System.out.println("OOPS!!! The index of the task that you entered does not exist:("); - duke.UI.printBreaker(); } } - public static void deleteTask(int inputIndex) { - try { - listInput.remove(inputIndex); - duke.UI.printDeleteTask(taskNumber, listInput.get(inputIndex - 1).toString()); - taskNumber--; - duke.Storage.saveToFile(listInput, taskNumber); - } catch (NullPointerException | ArrayIndexOutOfBoundsException e) { - System.out.println("OOPS!!! The index of the task that you entered does not exist:("); - duke.UI.printBreaker(); - } + /** + * Search for a task in the list. + * + * @param arrayInput The string array input of the task to be searched for. + */ + public static void searchTask(String[] arrayInput) { + List taskSearch =listInput.stream().filter(t -> t.getTaskDescription().contains(arrayInput[1])).collect(Collectors.toList()); + UI.printSearchTask(taskSearch); } - public static void recordTask(String commandInput, String lineInput) throws DukeException { - int breakIndex = lineInput.indexOf("/"); + /** + * Records different types of tasks. + * + * @param commandInput Command from the user showing which type of task to be recorded. + * @param lineInput The line input from the user. + * @param printMessage The flag of whether or not to print the summary message after the action. + */ + public static void recordTask(String commandInput, String lineInput, boolean printMessage) { try { switch (commandInput) { + case "event": + String eventName = lineInput.substring(6, lineInput.indexOf("/")); + String eventTime = lineInput.substring(lineInput.indexOf("/") + 3); + if (lineInput.length() < 9) { + throw new DukeExceptions ("The description of the event is too short! Please enter again."); + } + listInput.add(taskNumber, new Event(eventName, eventTime)); + if (printMessage) { + UI.printRecordTask(taskNumber, new Event(eventName, eventTime)); + } + break; case "deadline": + String deadlineName = lineInput.substring(9, lineInput.indexOf("/")); + String deadlineTime = lineInput.substring(lineInput.indexOf("/") + 3); if (lineInput.length() < 12) { - throw new DukeException("The description of the deadline is too short! Please enter again.\n"); + throw new DukeExceptions ("The description of the deadline is too short! Please enter again."); } - listInput.add(taskNumber, new Deadline(lineInput.substring(9, breakIndex), lineInput.substring(breakIndex + 3))); - duke.UI.printRecordTask(taskNumber, new Deadline(lineInput.substring(6, breakIndex), lineInput.substring(breakIndex + 3))); - break; - case "event": - if (lineInput.length() < 9) { - throw new DukeException("The description of the event is too short! Please enter again.\n"); + listInput.add(taskNumber, new Deadline(deadlineName, deadlineTime)); + if (printMessage) { + UI.printRecordTask(taskNumber, new Deadline(deadlineName, deadlineTime)); } - listInput.add(taskNumber, new Event(lineInput.substring(6, breakIndex), lineInput.substring(breakIndex + 3))); - duke.UI.printRecordTask(taskNumber, new Event(lineInput.substring(6, breakIndex), lineInput.substring(breakIndex + 3))); break; case "todo": listInput.add(taskNumber, new ToDo(lineInput.substring(5))); - duke.UI.printRecordTask(taskNumber, new ToDo(lineInput.substring(5))); + if (printMessage) { + UI.printRecordTask(taskNumber, new ToDo(lineInput.substring(5))); + } break; } - duke.Storage.saveToFile(listInput, taskNumber); - }catch (DukeException e) { + taskNumber++; + Storage.saveToFile(listInput, taskNumber); + } catch (DukeExceptions e) { System.out.println("OOPS!!! Sorry, but I do not understand:("); - duke.UI.printBreaker(); + } + } + + /** + * Deletes a task from the list. + * + * @param inputIndex The index of the task deleted. + */ + public static void deleteTask(String inputIndex) { + try { + UI.printDeleteTask(taskNumber, listInput.get(Integer.parseInt(inputIndex) - 1).toString()); + listInput.remove(Integer.parseInt(inputIndex) - 1); + taskNumber--; + Storage.saveToFile(listInput, taskNumber); + } catch (NumberFormatException | IndexOutOfBoundsException e) { + System.out.println("OOPS!!! The index of the task that you entered does not exist:("); } } } \ No newline at end of file diff --git a/src/main/java/duke/UI.java b/src/main/java/duke/UI.java index 859575d02..c1dda4406 100644 --- a/src/main/java/duke/UI.java +++ b/src/main/java/duke/UI.java @@ -1,63 +1,97 @@ package duke; -import duke.task.*; - import java.util.Scanner; import java.util.List; +import duke.task.*; + +/** + * Prints the outputs corresponding to different actions. + */ public class UI { + + /** + * Prints the dot line breaker. + */ public static void printBreaker() { System.out.println("......................................................................"); } + /** + * Prints welcome message after starting the bot. + */ public static void printWelcomeMessage() { String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); printBreaker(); System.out.println("Hi! I'm Duke.\n" + "How can I make your life easier?"); printBreaker(); } - public static void printByeMessage() { - System.out.println("Bye bye! Have a wonderful day!"); + /** + * Prints summary message after a task is marked as done. + * + * @param taskDone The string description of the task done. + */ + public static void printDoneTask(String taskDone) { printBreaker(); + System.out.println("Wonderful! This task is now marked as done:\n"); + System.out.println(taskDone); + } - public static void printFindTask(List taskFind) { - if (taskFind.size() == 0) { + /** + * Prints summary message after a task is searched for. + * + * @param taskSearch The List of task searched for. + */ + public static void printSearchTask(List taskSearch) { + if (taskSearch.size() == 0) { System.out.println("OPPS!!! No matches found:("); } else { System.out.println("Here is the task that you are looking for:)"); - for (int i = 0; i < taskFind.size(); i++) { - System.out.println((i + 1) + "." + taskFind.get(i).toString()); + for (int i = 0; i < taskSearch.size(); i++) { + System.out.println((i + 1) + "." + taskSearch.get(i).toString()); } } } - public static void printDoneTask(String taskDone) { - System.out.println("Wonderful! This task is now marked as done:\n" + taskDone); + /** + * Prints summary message after a task is added. + * + * @param taskNumber The integer total number of tasks in the list. + * @param taskRecord The task added. + */ + public static void printRecordTask(int taskNumber, Task taskRecord) { printBreaker(); + System.out.println("Got it. I've added this task:\n"); + System.out.println(taskRecord.toString()); + System.out.println("Now you have " + taskNumber + " tasks in your list"); } + /** + * Prints summary message after a task is deleted from the list. + * + * @param taskNumber The integer total number of tasks in the list. + * @param taskDelete The string description of the task deleted. + */ public static void printDeleteTask(int taskNumber, String taskDelete) { - System.out.println("Alright, the following task has been removed\n" + taskDelete + "\n" + "Now you have " + (taskNumber - 1) + " tasks left."); printBreaker(); + System.out.println("Alright, the following task has been removed"); + System.out.println(taskDelete); + System.out.println("Now you have " + (taskNumber - 1) + " tasks left"); } - public static void printRecordTask(int taskNumber, Task taskRecord) { - System.out.println("Got it. I've added this task:\n" + taskRecord.toString() + "\n" + "Now you have " + (taskNumber + 1) + " tasks in your list."); + /** + * Prints bye message when terminating the bot. + */ + public static void printByeMessage() { + System.out.println("Bye bye! Have a wonderful day!"); printBreaker(); } - - public static String getInput() { - String lineInput; - Scanner input = new Scanner(System.in); - lineInput = input.nextLine(); - return lineInput; - } } \ No newline at end of file diff --git a/src/main/java/duke/data/task.txt b/src/main/java/duke/data/task.txt index 0652327fb..ab37b8a41 100644 --- a/src/main/java/duke/data/task.txt +++ b/src/main/java/duke/data/task.txt @@ -1 +1,4 @@ -T | 0 | 1 \ No newline at end of file +T | 0 | study +E | 1 | sleep /at 11pm +D | 1 | play /by 5pm +E | 1 | 2 /at diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index edd3ebbda..103236c42 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,21 +1,25 @@ package duke.task; -public class Deadline extends Task { - protected String dueDate; +/** + * Shows the instances and methods of a deadline task. + */ +public class Deadline extends Task{ - public Deadline(String name, String dueDate) { - super(name); - this.dueDate = dueDate; + protected String deadlineTime; + + public Deadline(String deadlineName, String deadlineTime) { + super(deadlineName); + this.deadlineTime = deadlineTime; this.taskType = "D"; } @Override - public String toString() { - return "[D]" + super.toString() + "(by:" + dueDate + ")"; + public String getTaskDescription() { + return this.taskName + "/by" + this.deadlineTime; } @Override - public String getName() { - return this.name + " /by " + this.dueDate; + public String toString() { + return "[D]" + super.toString() + "(by:" + deadlineTime + ")"; } } \ No newline at end of file diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index c3b36dda6..cb63072cf 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,21 +1,25 @@ package duke.task; -public class Event extends Task { - public String eventDate; +/** + * Shows the instances and methods of a event task. + */ +public class Event extends Task{ - public Event(String name, String eventDate) { - super(name); - this.eventDate = eventDate; + protected String eventTime; + + public Event(String eventName, String eventTime) { + super(eventName); + this.eventTime = eventTime; this.taskType = "E"; } @Override - public String toString() { - return "[E]" + super.toString() + " (at:" + eventDate + ")"; + public String getTaskDescription() { + return this.taskName + "/at" + this.eventTime; } @Override - public String getName() { - return this.name + " /at " + this.eventDate; + public String toString() { + return "[E]" + super.toString() + " (at:" + eventTime + ")"; } } \ No newline at end of file diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index 0f4f72958..79b1bea67 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -1,32 +1,36 @@ package duke.task; +/** + * Shows the instances and methods of a task. + */ public class Task { - public String name; - public boolean isDone; - public String taskType; - public Task(String name) { - this.name = name; + protected String taskName; + protected boolean isDone; + protected String taskType; + + public Task(String taskName) { + this.taskName = taskName; this.isDone = false; } - public String getStatus() { + public String getTaskStatus() { return (isDone ? "[X] " : "[ ] "); } - public void markAsDone() { - this.isDone = true; + public String getTaskType(){ + return taskType; } - public String toString() { - return getStatus() + this.name; + public String getTaskDescription() { + return this.taskName; } - public String getType(){ - return taskType; + public void markAsDone() { + this.isDone = true; } - public String getName() { - return this.name; + public String toString() { + return getTaskStatus() + this.taskName; } } \ No newline at end of file diff --git a/src/main/java/duke/task/ToDo.java b/src/main/java/duke/task/ToDo.java index a2fb49f26..16dc5e65b 100644 --- a/src/main/java/duke/task/ToDo.java +++ b/src/main/java/duke/task/ToDo.java @@ -1,8 +1,12 @@ package duke.task; +/** + * Shows the instances and methods of a todo task. + */ public class ToDo extends Task{ - public ToDo(String name) { - super(name); + + public ToDo(String todoName) { + super(todoName); this.taskType = "T"; } @@ -10,4 +14,4 @@ public ToDo(String name) { public String toString() { return "[T]" + super.toString(); } -} \ No newline at end of file +} diff --git a/task.txt b/task.txt deleted file mode 100644 index 8b6a1a684..000000000 --- a/task.txt +++ /dev/null @@ -1,2 +0,0 @@ -T | 0 | 1 -T | 0 | 123 From 3f4ddede83611dbd9b3938341c55d12917daec27 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Fri, 8 Oct 2021 07:35:39 +0800 Subject: [PATCH 22/24] Updated UG. --- docs/README.md | 82 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 15 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..c7f0455a3 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,81 @@ # User Guide -## Features +Duke is a CLI task-managing app to help you and make your life easier. -### Feature-ABC +##Quick Start +1. Ensure you have Java 11 or above installed in your computer. +2. Download the latest Duke JAR file from github. +3. Locate the JAR file into a folder which you will run it from. +4. Navigate to this folder using CLI and run the command `java -jar ip.jar` +5. You can now start using Duke by typing the features command directly! -Description of the feature. +## Features -### Feature-XYZ +### Showing all tasks: `list` -Description of the feature. +Shows all tasks in the task list. -## Usage +* Format: `list` -### `Keyword` - Describe action +### Finding a task: `find` -Describe the action and its outcome. +Finds a task in the task list. -Example of usage: +* Format: `find TASK` +* Example: `find study` -`keyword (optional arguments)` +### Marking a task as done: `done` -Expected outcome: +Marks the task as done. -Description of the outcome. +* Format: `done TASK_INDEX` +* TASK_INDEX is a positive number which refer to the task. +* Example: `done 1` -``` -expected output -``` +### Deleting a task: `delete` + +Deletes a task from the task list. + +* Format: `delete TASK_INDEX` +* TASK_INDEX is a positive number which refer to the task. +* Example: `delete 1` + +### Recording a deadline task: `deadline` + +Adds a deadline task into the task list. + +* Format: `deadline TASK_NAME /by TASK_TIME` +* Example: `deadline sleep /by 11p.m.` + +### Recording a event task: `event` + +Adds a event task into the task list. + +* Format: `event TASK_NAME /at TASK_TIME` +* Example: `event eat /at 11a.m.` + +### Recording a todo task: `todo` + +Adds a todo task into the task list. + +* Format: `todo TASK_NAME` +* Example: `todo study` + +### Exiting the program: `bye` + +Exits the program. + +* Format: `bye` + +## Command Summary + +Action | Format & Example +-------|----------------- +Show all tasks|`list` +Find a task|`find TASK` (eg. `find work`) +Mark a task as done|`done TASK_INDEX` (eg. `done 1`) +Delete a task|`delete TASK_INDEX` (eg. `delete 1`) +Record a deadline task| `deadline deadline TASK_NAME /by TASK_TIME` (eg. `deadline sleep /by 11p.m.`) +Record a event task|`event TASK_NAME /at TASK_TIME` (eg. `event eat /at 11a.m.`) +Record a todo task| `todo TASK_NAME` (eg. `todo study`) +Exit the program|`bye` \ No newline at end of file From cb6235d7dd23cc501bd0f7e1674fc31788149b49 Mon Sep 17 00:00:00 2001 From: Jiale-Sun Date: Fri, 8 Oct 2021 07:38:16 +0800 Subject: [PATCH 23/24] Deleted wrongly located UG. --- README.md | 81 ------------------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index c7f0455a3..000000000 --- a/README.md +++ /dev/null @@ -1,81 +0,0 @@ -# User Guide - -Duke is a CLI task-managing app to help you and make your life easier. - -##Quick Start -1. Ensure you have Java 11 or above installed in your computer. -2. Download the latest Duke JAR file from github. -3. Locate the JAR file into a folder which you will run it from. -4. Navigate to this folder using CLI and run the command `java -jar ip.jar` -5. You can now start using Duke by typing the features command directly! - -## Features - -### Showing all tasks: `list` - -Shows all tasks in the task list. - -* Format: `list` - -### Finding a task: `find` - -Finds a task in the task list. - -* Format: `find TASK` -* Example: `find study` - -### Marking a task as done: `done` - -Marks the task as done. - -* Format: `done TASK_INDEX` -* TASK_INDEX is a positive number which refer to the task. -* Example: `done 1` - -### Deleting a task: `delete` - -Deletes a task from the task list. - -* Format: `delete TASK_INDEX` -* TASK_INDEX is a positive number which refer to the task. -* Example: `delete 1` - -### Recording a deadline task: `deadline` - -Adds a deadline task into the task list. - -* Format: `deadline TASK_NAME /by TASK_TIME` -* Example: `deadline sleep /by 11p.m.` - -### Recording a event task: `event` - -Adds a event task into the task list. - -* Format: `event TASK_NAME /at TASK_TIME` -* Example: `event eat /at 11a.m.` - -### Recording a todo task: `todo` - -Adds a todo task into the task list. - -* Format: `todo TASK_NAME` -* Example: `todo study` - -### Exiting the program: `bye` - -Exits the program. - -* Format: `bye` - -## Command Summary - -Action | Format & Example --------|----------------- -Show all tasks|`list` -Find a task|`find TASK` (eg. `find work`) -Mark a task as done|`done TASK_INDEX` (eg. `done 1`) -Delete a task|`delete TASK_INDEX` (eg. `delete 1`) -Record a deadline task| `deadline deadline TASK_NAME /by TASK_TIME` (eg. `deadline sleep /by 11p.m.`) -Record a event task|`event TASK_NAME /at TASK_TIME` (eg. `event eat /at 11a.m.`) -Record a todo task| `todo TASK_NAME` (eg. `todo study`) -Exit the program|`bye` \ No newline at end of file From 9b551fd416cace44cac48a8210e67b9c7c80b713 Mon Sep 17 00:00:00 2001 From: Jiale-Sun <69443909+Jiale-Sun@users.noreply.github.com> Date: Fri, 8 Oct 2021 07:40:06 +0800 Subject: [PATCH 24/24] Set theme jekyll-theme-architect --- docs/_config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/_config.yml diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 000000000..3397c9a49 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-architect \ No newline at end of file