From f0ecd9cdbc3d816a0ef0efe2f512008fc0db423b Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Fri, 26 Jan 2024 16:59:27 +0800 Subject: [PATCH 01/28] add chatbot name --- src/main/java/Duke.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..9478f0d61 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,8 @@ public class Duke { public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + + System.out.println("Hello! I'm apple"); + System.out.println("What can I do for you?"); + System.out.println("Bye. Hope to see you again soon!"); } } From e0b6eeda26c7b64e6df39652a16d12b867e9bcf4 Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Wed, 7 Feb 2024 15:05:17 +0800 Subject: [PATCH 02/28] Add echo --- src/main/java/Duke.class | Bin 0 -> 943 bytes src/main/java/Duke.java | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/main/java/Duke.class diff --git a/src/main/java/Duke.class b/src/main/java/Duke.class new file mode 100644 index 0000000000000000000000000000000000000000..76684001fa063128c0fa14299c16df64af123ea0 GIT binary patch literal 943 zcmZuw-A)rh6#k|yyW3?EC=?Jyr~c7Ge-seK8com`ngE*AXw<7|8QX>JZf$psO^jaa z8^{ZI;gwvJL=zvtXEEM;fqG_Zf))4ToU`ZWJLfwy^Y!PaF95EfXkr-Cah$+O12ZO0 z;j{s+Bc)ttOlUZ(#5n`!O-$l~60-)7hS)7{OEL_v+pgRU z8Wq{PFDedsVhv%t3=`=m>)YbFC^*8c70Q0gc56jdI8^pUb!S5~!+ag{3})F2T2*<+ zR`v1Q!H&$UQVSy()seN3L!Mz|O*)R3;-%RJ7tN+4brdXI#3gF>ur7RF6)rFFEssC- zTD;>0HyK955dzc!ErDzlx z#zNSBH-p|(Ne*o`ng0J`BWmr3pe45%9D+{$DI(av1L{BwSHAGoF*1y&Ge@!M=;gCO zIPHI0_c#|bj|rkK+V$RrpxaSG3diWOsV@TB07gkB=x>HJBRw#;5B8A^VoOpBol(Rw zjwIPC^&6rXApLd^kwmnMn9>8JKSO)82YnyL`g|Ahjcmf~VsIDLBZ1AxaxB+{^?_jM zx~p#N)pyc~Tv+oCT68&#6hcGbL*aNY%2WNR>>6FHOK z&mcHa&JgJ(@~jX8pSZjvHm@;_H`INCDyE Date: Wed, 7 Feb 2024 15:26:12 +0800 Subject: [PATCH 03/28] add Add,list --- src/main/java/Duke.java | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 7f9a73cca..c86df838a 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -2,11 +2,12 @@ public class Duke { public static void main(String[] args) { + String list[] = new String[100]; System.out.println("Hello! I'm apple"); System.out.println("What can I do for you?"); - + int index = 0; String line = ""; @@ -15,13 +16,27 @@ public static void main(String[] args) { while (!line.equals("bye")){ Scanner input = new Scanner(System.in); line = input.nextLine(); - if (line.equals("bye")){ break; } - System.out.println(line); + if (line.equals("list")){ + for (int i = 0; i < index; i ++) { + + System.out.println((i + 1) + ". " + list[i]); + } + }else { + list[index] = line; + System.out.println("added: " + line); + } + + index ++; + + + + + } System.out.println("Bye. Hope to see you again soon!"); From 0c167248e0c87e57066436708fbf29340460d22f Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Fri, 9 Feb 2024 15:21:54 +0800 Subject: [PATCH 04/28] add mark as done --- src/main/java/Duke.java | 83 ++++++++++++++++++++++------------------- src/main/java/Task.java | 24 ++++++++++++ 2 files changed, 68 insertions(+), 39 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index c86df838a..930f6e9c7 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,45 +1,50 @@ import java.util.Scanner; public class Duke { - public static void main(String[] args) { - String list[] = new String[100]; - - System.out.println("Hello! I'm apple"); - System.out.println("What can I do for you?"); - - int index = 0; - - String line = ""; - - - - while (!line.equals("bye")){ - Scanner input = new Scanner(System.in); - line = input.nextLine(); - - if (line.equals("bye")){ - break; - } - - if (line.equals("list")){ - for (int i = 0; i < index; i ++) { - - System.out.println((i + 1) + ". " + list[i]); - } - }else { - list[index] = line; - System.out.println("added: " + line); - } - - index ++; - - - - - + public static void main(String[] args) { + Task[] list = new Task[100]; + + + + //greeting + System.out.println("Hello! I'm Apple"); + System.out.println("What can I do for you?"); + + int index = 0;//number of items in the list + String line =" "; + + while (!line.equals("bye")) { + Scanner input = new Scanner(System.in); + line = input.nextLine(); + + Task t = new Task(line); + String[] inputs = line.split(" "); + + if (inputs[0].equals("mark")){//mark as done + int idx = Integer.parseInt(inputs[1]); + list[idx - 1].markAsDone(); + System.out.println("Nice! I've marked this task as done: "); + System.out.println("[" + list[idx - 1].getStatusIcon()+ "]" + list[idx - 1].description); + } else if(inputs[0].equals("unmark")){//unmark done + int idx = Integer.parseInt(inputs[1]); + list[idx - 1].unmarkDone(); + System.out.println("OK, I've marked this task as not done yet: "); + System.out.println("[" + list[idx - 1].getStatusIcon()+ "]" + list[idx - 1].description); + }else if (line.equals("list")) {//lists items + System.out.println("Here are the tasks in your list: "); + for (int i = 0; i < index; i++) { + System.out.println((i + 1) + ". [" + list[i].getStatusIcon()+ "]" + list[i].description); } - System.out.println("Bye. Hope to see you again soon!"); - - + }else if (line.equals("bye")) {//exit chat + break; + }else {//add items + list[index] = t; + System.out.println("added: " + t.description); + index ++; + } + } + System.out.println("Bye. Hope to see you again soon!"); + } + } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..458b67c4c --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,24 @@ +public class Task { + protected String description; + protected int taskIndex; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + public void markAsDone(){ + this.isDone = true; + + } + + public void unmarkDone(){ + this.isDone = false; + } +} + From 1b6ca15d9aaa88aa5a7a834645c3e6f233cda887 Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Fri, 9 Feb 2024 16:49:51 +0800 Subject: [PATCH 05/28] add A-CodingStandard --- src/main/java/Duke.java | 84 ++++++++++++++++++++--------------------- src/main/java/Task.java | 33 ++++++++-------- 2 files changed, 56 insertions(+), 61 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 930f6e9c7..66a0d3db4 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,50 +1,48 @@ import java.util.Scanner; public class Duke { - public static void main(String[] args) { - Task[] list = new Task[100]; - - - - //greeting - System.out.println("Hello! I'm Apple"); - System.out.println("What can I do for you?"); - - int index = 0;//number of items in the list - String line =" "; - - while (!line.equals("bye")) { - Scanner input = new Scanner(System.in); - line = input.nextLine(); - - Task t = new Task(line); - String[] inputs = line.split(" "); - - if (inputs[0].equals("mark")){//mark as done - int idx = Integer.parseInt(inputs[1]); - list[idx - 1].markAsDone(); - System.out.println("Nice! I've marked this task as done: "); - System.out.println("[" + list[idx - 1].getStatusIcon()+ "]" + list[idx - 1].description); - } else if(inputs[0].equals("unmark")){//unmark done - int idx = Integer.parseInt(inputs[1]); - list[idx - 1].unmarkDone(); - System.out.println("OK, I've marked this task as not done yet: "); - System.out.println("[" + list[idx - 1].getStatusIcon()+ "]" + list[idx - 1].description); - }else if (line.equals("list")) {//lists items - System.out.println("Here are the tasks in your list: "); - for (int i = 0; i < index; i++) { - System.out.println((i + 1) + ". [" + list[i].getStatusIcon()+ "]" + list[i].description); - } - }else if (line.equals("bye")) {//exit chat - break; - }else {//add items - list[index] = t; - System.out.println("added: " + t.description); - index ++; - } + public static void main(String[] args) { + Task[] list = new Task[100]; + + //greeting + System.out.println("Hello! I'm Apple"); + System.out.println("What can I do for you?"); + + int index = 0;//number of items in the list + String line = " "; + + while (!line.equals("bye")) { + Scanner input = new Scanner(System.in); + line = input.nextLine(); + + Task t = new Task(line); + String[] inputs = line.split(" "); + + if (inputs[0].equals("mark")) {//mark as done + int idx = Integer.parseInt(inputs[1]); + list[idx - 1].markAsDone(); + System.out.println("Nice! I've marked this task as done: "); + System.out.println("[" + list[idx - 1].getStatusIcon() + "]" + list[idx - 1].description); + } else if (inputs[0].equals("unmark")) {//unmark done + int idx = Integer.parseInt(inputs[1]); + list[idx - 1].unmarkDone(); + System.out.println("OK, I've marked this task as not done yet: "); + System.out.println("[" + list[idx - 1].getStatusIcon() + "]" + list[idx - 1].description); + } else if (line.equals("list")) {//lists items + System.out.println("Here are the tasks in your list: "); + for (int i = 0; i < index; i++) { + System.out.println((i + 1) + ". [" + list[i].getStatusIcon() + "]" + list[i].description); + } + } else if (line.equals("bye")) {//exit chat + break; + } else {//add items + list[index] = t; + System.out.println("added: " + t.description); + index++; + } + } + System.out.println("Bye. Hope to see you again soon!"); } - System.out.println("Bye. Hope to see you again soon!"); - } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 458b67c4c..bd2bbd58a 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,24 +1,21 @@ public class Task { - protected String description; - protected int taskIndex; - protected boolean isDone; + protected String description; + protected boolean isDone; + public Task(String description) { + this.description = description; + this.isDone = false; + } - public Task(String description) { - this.description = description; - this.isDone = false; - } + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } - public String getStatusIcon() { - return (isDone ? "X" : " "); // mark done task with X - } + public void markAsDone() { + this.isDone = true; + } - public void markAsDone(){ - this.isDone = true; - - } - - public void unmarkDone(){ - this.isDone = false; - } + public void unmarkDone() { + this.isDone = false; + } } From 6ef3078ef99ac0a9d393d5279651eb9a475b2015 Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Fri, 16 Feb 2024 22:41:43 +0800 Subject: [PATCH 06/28] add todo, deadline and event --- src/main/java/Deadline.java | 13 +++++++++ src/main/java/Duke.java | 53 ++++++++++++++++++++++++++++++++++--- src/main/java/Event.java | 15 +++++++++++ src/main/java/Task.java | 4 +++ src/main/java/Todo.java | 11 ++++++++ 5 files changed, 93 insertions(+), 3 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..bcd049672 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,13 @@ +public class Deadline extends Task{ + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + @Override + public String toString() { + return "[D]" + super.toString() + " (by: " + by + ")"; + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 66a0d3db4..3aa5413d2 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,6 +1,39 @@ import java.util.Scanner; public class Duke { + protected static String from; + protected static String to; + + + public String description; + + public static void dealWithEvent(Task[] list, int index, String[] inputs, String line){ + int indexTo = line.indexOf("/to"); + int indexFrom = line.indexOf("/from"); + String from = line.substring(indexFrom + 6, indexTo - 1); + String to = line.substring(indexTo + 4); + String description = line.substring(6, indexFrom - 1); + + list[index] = new Event(description, from, to); + System.out.println("Got it. I've added this task: "); + System.out.println(list[index]); + } + public static void dealWithDeadline(Task[] list, int index, String line){ + int indexBy = line.indexOf("by"); + String by = line.substring(indexBy + 3); + String description = line.substring(0, indexBy - 1); + list[index] = new Deadline(description, by); + System.out.println("Got it. I've added this task: "); + System.out.println(list[index]); + } + + public static void dealWithTodo(Task[] list, int index, String line){ + int indexSpace = line.indexOf(" "); + String description = line.substring(indexSpace); + list[index] = new Todo(description); + System.out.println("Got it. I've added this task: "); + System.out.println(list[index]); + } public static void main(String[] args) { Task[] list = new Task[100]; @@ -31,16 +64,30 @@ public static void main(String[] args) { } else if (line.equals("list")) {//lists items System.out.println("Here are the tasks in your list: "); for (int i = 0; i < index; i++) { - System.out.println((i + 1) + ". [" + list[i].getStatusIcon() + "]" + list[i].description); + //System.out.println((i + 1) + ". [" + list[i].getStatusIcon() + "]" + list[i].description); + System.out.println((i + 1) + ". " + list[i]); } } else if (line.equals("bye")) {//exit chat break; } else {//add items - list[index] = t; - System.out.println("added: " + t.description); + + if (inputs[0].equals("event")) { + dealWithEvent(list, index, inputs, line); + + } else if (inputs[0].equals("deadline")){ + dealWithDeadline(list, index, line); + } else if (inputs[0].equals("todo")){ + dealWithTodo(list, index, line); + } + System.out.println("Now you have " + (index + 1) + " tasks in the list."); + //System.out.println(from); + //System.out.println(to); + index++; } + + } System.out.println("Bye. Hope to see you again soon!"); } diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..8a985596a --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,15 @@ +public class Event extends Task{ + + + protected String from; + protected String to; + public Event(String description, String from, String to){ + super(description); + this.from = from; + this.to = to; + } + @Override + public String toString() { + return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")"; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index bd2bbd58a..87b80a79e 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -17,5 +17,9 @@ public void markAsDone() { public void unmarkDone() { this.isDone = false; } + + public String toString(){ + return "[" + getStatusIcon() + "]" + description; + } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..3e9d6ee7a --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,11 @@ +public class Todo extends Task{ + + public Todo(String description){ + super(description); + } + @Override + public String toString() { + return "[T]" + super.toString(); + } + +} From b540106ed3d6520543d5b1a4a0fb826199257881 Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Mon, 19 Feb 2024 18:11:22 +0800 Subject: [PATCH 07/28] add code quality --- src/main/java/Duke.java | 48 ++++++++++++++++------------------------ src/main/java/Event.java | 2 -- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 3aa5413d2..0f4d9f844 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,39 +3,37 @@ public class Duke { protected static String from; protected static String to; - - public String description; - public static void dealWithEvent(Task[] list, int index, String[] inputs, String line){ + public static void dealWithEvent(Task[] tasks, int index, String[] inputs, String line){ int indexTo = line.indexOf("/to"); int indexFrom = line.indexOf("/from"); String from = line.substring(indexFrom + 6, indexTo - 1); String to = line.substring(indexTo + 4); String description = line.substring(6, indexFrom - 1); - list[index] = new Event(description, from, to); + tasks[index] = new Event(description, from, to); System.out.println("Got it. I've added this task: "); - System.out.println(list[index]); + System.out.println(tasks[index]); } - public static void dealWithDeadline(Task[] list, int index, String line){ + public static void dealWithDeadline(Task[] tasks, int index, String line){ int indexBy = line.indexOf("by"); String by = line.substring(indexBy + 3); String description = line.substring(0, indexBy - 1); - list[index] = new Deadline(description, by); + tasks[index] = new Deadline(description, by); System.out.println("Got it. I've added this task: "); - System.out.println(list[index]); + System.out.println(tasks[index]); } - public static void dealWithTodo(Task[] list, int index, String line){ + public static void dealWithTodo(Task[] tasks, int index, String line){ int indexSpace = line.indexOf(" "); String description = line.substring(indexSpace); - list[index] = new Todo(description); + tasks[index] = new Todo(description); System.out.println("Got it. I've added this task: "); - System.out.println(list[index]); + System.out.println(tasks[index]); } public static void main(String[] args) { - Task[] list = new Task[100]; + Task[] tasks = new Task[100]; //greeting System.out.println("Hello! I'm Apple"); @@ -53,43 +51,35 @@ public static void main(String[] args) { if (inputs[0].equals("mark")) {//mark as done int idx = Integer.parseInt(inputs[1]); - list[idx - 1].markAsDone(); + tasks[idx - 1].markAsDone(); System.out.println("Nice! I've marked this task as done: "); - System.out.println("[" + list[idx - 1].getStatusIcon() + "]" + list[idx - 1].description); + System.out.println("[" + tasks[idx - 1].getStatusIcon() + "]" + tasks[idx - 1].description); } else if (inputs[0].equals("unmark")) {//unmark done int idx = Integer.parseInt(inputs[1]); - list[idx - 1].unmarkDone(); + tasks[idx - 1].unmarkDone(); System.out.println("OK, I've marked this task as not done yet: "); - System.out.println("[" + list[idx - 1].getStatusIcon() + "]" + list[idx - 1].description); - } else if (line.equals("list")) {//lists items + System.out.println("[" + tasks[idx - 1].getStatusIcon() + "]" + tasks[idx - 1].description); + } else if (line.equals("list")) {//lists tasks System.out.println("Here are the tasks in your list: "); for (int i = 0; i < index; i++) { - //System.out.println((i + 1) + ". [" + list[i].getStatusIcon() + "]" + list[i].description); - System.out.println((i + 1) + ". " + list[i]); + System.out.println((i + 1) + ". " + tasks[i]); } } else if (line.equals("bye")) {//exit chat break; } else {//add items if (inputs[0].equals("event")) { - dealWithEvent(list, index, inputs, line); - + dealWithEvent(tasks, index, inputs, line); } else if (inputs[0].equals("deadline")){ - dealWithDeadline(list, index, line); + dealWithDeadline(tasks, index, line); } else if (inputs[0].equals("todo")){ - dealWithTodo(list, index, line); + dealWithTodo(tasks, index, line); } System.out.println("Now you have " + (index + 1) + " tasks in the list."); - //System.out.println(from); - //System.out.println(to); index++; } - - - } System.out.println("Bye. Hope to see you again soon!"); } - } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 8a985596a..0c9973810 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,6 +1,4 @@ public class Event extends Task{ - - protected String from; protected String to; public Event(String description, String from, String to){ From c2302554e61de79479108a70d79e8a85e504f885 Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Tue, 20 Feb 2024 12:26:34 +0800 Subject: [PATCH 08/28] add error handling --- src/main/java/Duke.java | 71 +--------- src/main/java/EmptyLineException.java | 2 + src/main/java/ManageInputs.java | 127 ++++++++++++++++++ src/main/java/UnexpectedCommandException.java | 2 + 4 files changed, 133 insertions(+), 69 deletions(-) create mode 100644 src/main/java/EmptyLineException.java create mode 100644 src/main/java/ManageInputs.java create mode 100644 src/main/java/UnexpectedCommandException.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 0f4d9f844..a09d411dc 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,38 +1,9 @@ import java.util.Scanner; public class Duke { - protected static String from; - protected static String to; - public String description; - public static void dealWithEvent(Task[] tasks, int index, String[] inputs, String line){ - int indexTo = line.indexOf("/to"); - int indexFrom = line.indexOf("/from"); - String from = line.substring(indexFrom + 6, indexTo - 1); - String to = line.substring(indexTo + 4); - String description = line.substring(6, indexFrom - 1); - tasks[index] = new Event(description, from, to); - System.out.println("Got it. I've added this task: "); - System.out.println(tasks[index]); - } - public static void dealWithDeadline(Task[] tasks, int index, String line){ - int indexBy = line.indexOf("by"); - String by = line.substring(indexBy + 3); - String description = line.substring(0, indexBy - 1); - tasks[index] = new Deadline(description, by); - System.out.println("Got it. I've added this task: "); - System.out.println(tasks[index]); - } - - public static void dealWithTodo(Task[] tasks, int index, String line){ - int indexSpace = line.indexOf(" "); - String description = line.substring(indexSpace); - tasks[index] = new Todo(description); - System.out.println("Got it. I've added this task: "); - System.out.println(tasks[index]); - } - public static void main(String[] args) { + public static void main(String[] args) throws UnexpectedCommandException, EmptyLineException { Task[] tasks = new Task[100]; //greeting @@ -42,44 +13,6 @@ public static void main(String[] args) { int index = 0;//number of items in the list String line = " "; - while (!line.equals("bye")) { - Scanner input = new Scanner(System.in); - line = input.nextLine(); - - Task t = new Task(line); - String[] inputs = line.split(" "); - - if (inputs[0].equals("mark")) {//mark as done - int idx = Integer.parseInt(inputs[1]); - tasks[idx - 1].markAsDone(); - System.out.println("Nice! I've marked this task as done: "); - System.out.println("[" + tasks[idx - 1].getStatusIcon() + "]" + tasks[idx - 1].description); - } else if (inputs[0].equals("unmark")) {//unmark done - int idx = Integer.parseInt(inputs[1]); - tasks[idx - 1].unmarkDone(); - System.out.println("OK, I've marked this task as not done yet: "); - System.out.println("[" + tasks[idx - 1].getStatusIcon() + "]" + tasks[idx - 1].description); - } else if (line.equals("list")) {//lists tasks - System.out.println("Here are the tasks in your list: "); - for (int i = 0; i < index; i++) { - System.out.println((i + 1) + ". " + tasks[i]); - } - } else if (line.equals("bye")) {//exit chat - break; - } else {//add items - - if (inputs[0].equals("event")) { - dealWithEvent(tasks, index, inputs, line); - } else if (inputs[0].equals("deadline")){ - dealWithDeadline(tasks, index, line); - } else if (inputs[0].equals("todo")){ - dealWithTodo(tasks, index, line); - } - System.out.println("Now you have " + (index + 1) + " tasks in the list."); - - index++; - } - } - System.out.println("Bye. Hope to see you again soon!"); + new ManageInputs(tasks, index, line); } } diff --git a/src/main/java/EmptyLineException.java b/src/main/java/EmptyLineException.java new file mode 100644 index 000000000..fd35912c9 --- /dev/null +++ b/src/main/java/EmptyLineException.java @@ -0,0 +1,2 @@ +public class EmptyLineException extends Exception{ +} diff --git a/src/main/java/ManageInputs.java b/src/main/java/ManageInputs.java new file mode 100644 index 000000000..02bbff9fa --- /dev/null +++ b/src/main/java/ManageInputs.java @@ -0,0 +1,127 @@ +import java.util.Scanner; + +public class ManageInputs { + protected static String from; + protected static String to; + public String description; + + public static void dealWithEvent(Task[] tasks, int index, String[] inputs, String line) throws UnexpectedCommandException { + int indexTo = line.indexOf("/to"); + int indexFrom = line.indexOf("/from"); + + if ((indexTo == -1) || (indexFrom == -1)) { + System.out.println("remember to include a description and event timeline!"); + throw new UnexpectedCommandException(); + } + String from = line.substring(indexFrom + 6, indexTo - 1); + String to = line.substring(indexTo + 4); + String description = line.substring(6, indexFrom - 1); + + tasks[index] = new Event(description, from, to); + System.out.println("Got it. I've added this task: "); + System.out.println(tasks[index]); + } + + public static void dealWithDeadline(Task[] tasks, int index, String line) throws UnexpectedCommandException { + int indexBy = line.indexOf("by"); + if (indexBy == -1) { + System.out.println("remember to include a description and a deadline!"); + throw new UnexpectedCommandException(); + } + String by = line.substring(indexBy + 3); + String description = line.substring(0, indexBy - 1); + tasks[index] = new Deadline(description, by); + System.out.println("Got it. I've added this task: "); + System.out.println(tasks[index]); + } + + public static void dealWithTodo(Task[] tasks, int index, String line) throws UnexpectedCommandException { + int indexSpace = line.indexOf(" "); + if (indexSpace == -1) { + System.out.println("todo description cannot be empty"); + throw new UnexpectedCommandException(); + } + + String description = line.substring(indexSpace); + + tasks[index] = new Todo(description); + System.out.println("Got it. I've added this task: "); + System.out.println(tasks[index]); + } + + private void handleUnexpectedCommand(boolean isValidCommand) throws UnexpectedCommandException { + if (!isValidCommand) { + throw new UnexpectedCommandException(); + } + } + + private void handleEmptyInput(String line) throws EmptyLineException { + if (line.isEmpty()) { + throw new EmptyLineException(); + } + } + + public ManageInputs(Task[] tasks, int index, String line){ + + while (!line.equals("bye")) { + Boolean isValidCommand = false; + Scanner input = new Scanner(System.in); + line = input.nextLine(); + + Task t = new Task(line); + String[] inputs = line.split(" "); + + if (inputs[0].equals("mark")) {//mark as done + isValidCommand = true; + int idx = Integer.parseInt(inputs[1]); + tasks[idx - 1].markAsDone(); + System.out.println("Nice! I've marked this task as done: "); + System.out.println("[" + tasks[idx - 1].getStatusIcon() + "]" + tasks[idx - 1].description); + } else if (inputs[0].equals("unmark")) {//unmark done + isValidCommand = true; + int idx = Integer.parseInt(inputs[1]); + tasks[idx - 1].unmarkDone(); + System.out.println("OK, I've marked this task as not done yet: "); + System.out.println("[" + tasks[idx - 1].getStatusIcon() + "]" + tasks[idx - 1].description); + } else if (line.equals("list")) {//lists tasks + isValidCommand = true; + System.out.println("Here are the tasks in your list: "); + for (int i = 0; i < index; i++) { + System.out.println((i + 1) + ". " + tasks[i]); + } + } else if (line.equals("bye")) {//exit chat + isValidCommand = true; + break; + } else if (inputs[0].equals("event") || inputs[0].equals("todo") || inputs[0].equals("deadline")) {//add items + try { + if (inputs[0].equals("event")) { + isValidCommand = true; + dealWithEvent(tasks, index, inputs, line); + index++; + } else if (inputs[0].equals("deadline")) { + isValidCommand = true; + dealWithDeadline(tasks, index, line); + index++; + } else { + isValidCommand = true; + dealWithTodo(tasks, index, line); + index++; + } + System.out.println("Now you have " + index + " tasks in the list."); + } catch (UnexpectedCommandException e) { + + } + } else { + try { + handleEmptyInput(line); + handleUnexpectedCommand(isValidCommand); + } catch (UnexpectedCommandException e) { + System.out.println("please enter a valid command"); + } catch (EmptyLineException e){ + System.out.println("enter a task"); + } + } + } + System.out.println("Bye. Hope to see you again soon!"); + } +} diff --git a/src/main/java/UnexpectedCommandException.java b/src/main/java/UnexpectedCommandException.java new file mode 100644 index 000000000..3d56bc38b --- /dev/null +++ b/src/main/java/UnexpectedCommandException.java @@ -0,0 +1,2 @@ +public class UnexpectedCommandException extends Exception { +} From bedc8ec32b86d83940acdcb69ce5ddf192d49ecd Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Tue, 20 Feb 2024 14:01:50 +0800 Subject: [PATCH 09/28] make error handling more error-specific --- src/main/java/ManageInputs.java | 67 ++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/src/main/java/ManageInputs.java b/src/main/java/ManageInputs.java index 02bbff9fa..1ad4fa861 100644 --- a/src/main/java/ManageInputs.java +++ b/src/main/java/ManageInputs.java @@ -3,19 +3,37 @@ public class ManageInputs { protected static String from; protected static String to; - public String description; + public static String description; + protected static String by; + public static void dealWithEvent(Task[] tasks, int index, String[] inputs, String line) throws UnexpectedCommandException { int indexTo = line.indexOf("/to"); int indexFrom = line.indexOf("/from"); - if ((indexTo == -1) || (indexFrom == -1)) { - System.out.println("remember to include a description and event timeline!"); + if ((indexTo == -1) || (indexFrom == -1)) { //invalid format + System.out.println("Invalid format! Enter event in the format: event (description) /from (start) /to (end)"); + throw new UnexpectedCommandException(); + } + try {//timeline not specified/ both not specified + String from = line.substring(indexFrom + 6, indexTo - 1); + String to = line.substring(indexTo + 4); + } catch (IndexOutOfBoundsException e) { + try { + String description = line.substring(6, indexFrom - 1); + } catch (IndexOutOfBoundsException f) { + System.out.println("event description and timeline not specified"); + throw new UnexpectedCommandException(); + } + System.out.println("event timeline not specified"); + throw new UnexpectedCommandException(); + } + try {//description not specified + String description = line.substring(6, indexFrom - 1); + } catch (IndexOutOfBoundsException e) { + System.out.println("event description not specified"); throw new UnexpectedCommandException(); } - String from = line.substring(indexFrom + 6, indexTo - 1); - String to = line.substring(indexTo + 4); - String description = line.substring(6, indexFrom - 1); tasks[index] = new Event(description, from, to); System.out.println("Got it. I've added this task: "); @@ -24,12 +42,28 @@ public static void dealWithEvent(Task[] tasks, int index, String[] inputs, Strin public static void dealWithDeadline(Task[] tasks, int index, String line) throws UnexpectedCommandException { int indexBy = line.indexOf("by"); - if (indexBy == -1) { - System.out.println("remember to include a description and a deadline!"); + if (indexBy == -1) {//invalid format + System.out.println("Invalid format! Enter deadline in the format: deadline (description) by (deadline)"); + throw new UnexpectedCommandException(); + } + try {//deadline / both not specified + String by = line.substring(indexBy + 3); + } catch (IndexOutOfBoundsException e) { + try { + String description = line.substring(9, indexBy - 1); + } catch (IndexOutOfBoundsException f) { + System.out.println("deadline description and deadline not specified"); + throw new UnexpectedCommandException(); + } + System.out.println("deadline not specified"); + throw new UnexpectedCommandException(); + } + try {//deadline not specified + String description = line.substring(9, indexBy - 1); + } catch (IndexOutOfBoundsException e) { + System.out.println("deadline description not specified"); throw new UnexpectedCommandException(); } - String by = line.substring(indexBy + 3); - String description = line.substring(0, indexBy - 1); tasks[index] = new Deadline(description, by); System.out.println("Got it. I've added this task: "); System.out.println(tasks[index]); @@ -38,7 +72,7 @@ public static void dealWithDeadline(Task[] tasks, int index, String line) throws public static void dealWithTodo(Task[] tasks, int index, String line) throws UnexpectedCommandException { int indexSpace = line.indexOf(" "); if (indexSpace == -1) { - System.out.println("todo description cannot be empty"); + System.out.println("todo description not specified"); throw new UnexpectedCommandException(); } @@ -61,8 +95,7 @@ private void handleEmptyInput(String line) throws EmptyLineException { } } - public ManageInputs(Task[] tasks, int index, String line){ - + public ManageInputs(Task[] tasks, int index, String line) { while (!line.equals("bye")) { Boolean isValidCommand = false; Scanner input = new Scanner(System.in); @@ -117,7 +150,7 @@ public ManageInputs(Task[] tasks, int index, String line){ handleUnexpectedCommand(isValidCommand); } catch (UnexpectedCommandException e) { System.out.println("please enter a valid command"); - } catch (EmptyLineException e){ + } catch (EmptyLineException e) { System.out.println("enter a task"); } } @@ -125,3 +158,9 @@ public ManageInputs(Task[] tasks, int index, String line){ System.out.println("Bye. Hope to see you again soon!"); } } + +/*try{ + handleFromUnspecified(); + } catch (FromUnspecifiedError e){ + System.out.println("remember to include start of event!"); + }*/ \ No newline at end of file From 4793c541ea1fe105390fec9bb05217c3159eddd1 Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Tue, 20 Feb 2024 14:11:20 +0800 Subject: [PATCH 10/28] Revert "make error handling more error-specific" This reverts commit bedc8ec32b86d83940acdcb69ce5ddf192d49ecd. --- src/main/java/ManageInputs.java | 67 +++++++-------------------------- 1 file changed, 14 insertions(+), 53 deletions(-) diff --git a/src/main/java/ManageInputs.java b/src/main/java/ManageInputs.java index 1ad4fa861..02bbff9fa 100644 --- a/src/main/java/ManageInputs.java +++ b/src/main/java/ManageInputs.java @@ -3,37 +3,19 @@ public class ManageInputs { protected static String from; protected static String to; - public static String description; - protected static String by; - + public String description; public static void dealWithEvent(Task[] tasks, int index, String[] inputs, String line) throws UnexpectedCommandException { int indexTo = line.indexOf("/to"); int indexFrom = line.indexOf("/from"); - if ((indexTo == -1) || (indexFrom == -1)) { //invalid format - System.out.println("Invalid format! Enter event in the format: event (description) /from (start) /to (end)"); - throw new UnexpectedCommandException(); - } - try {//timeline not specified/ both not specified - String from = line.substring(indexFrom + 6, indexTo - 1); - String to = line.substring(indexTo + 4); - } catch (IndexOutOfBoundsException e) { - try { - String description = line.substring(6, indexFrom - 1); - } catch (IndexOutOfBoundsException f) { - System.out.println("event description and timeline not specified"); - throw new UnexpectedCommandException(); - } - System.out.println("event timeline not specified"); - throw new UnexpectedCommandException(); - } - try {//description not specified - String description = line.substring(6, indexFrom - 1); - } catch (IndexOutOfBoundsException e) { - System.out.println("event description not specified"); + if ((indexTo == -1) || (indexFrom == -1)) { + System.out.println("remember to include a description and event timeline!"); throw new UnexpectedCommandException(); } + String from = line.substring(indexFrom + 6, indexTo - 1); + String to = line.substring(indexTo + 4); + String description = line.substring(6, indexFrom - 1); tasks[index] = new Event(description, from, to); System.out.println("Got it. I've added this task: "); @@ -42,28 +24,12 @@ public static void dealWithEvent(Task[] tasks, int index, String[] inputs, Strin public static void dealWithDeadline(Task[] tasks, int index, String line) throws UnexpectedCommandException { int indexBy = line.indexOf("by"); - if (indexBy == -1) {//invalid format - System.out.println("Invalid format! Enter deadline in the format: deadline (description) by (deadline)"); - throw new UnexpectedCommandException(); - } - try {//deadline / both not specified - String by = line.substring(indexBy + 3); - } catch (IndexOutOfBoundsException e) { - try { - String description = line.substring(9, indexBy - 1); - } catch (IndexOutOfBoundsException f) { - System.out.println("deadline description and deadline not specified"); - throw new UnexpectedCommandException(); - } - System.out.println("deadline not specified"); - throw new UnexpectedCommandException(); - } - try {//deadline not specified - String description = line.substring(9, indexBy - 1); - } catch (IndexOutOfBoundsException e) { - System.out.println("deadline description not specified"); + if (indexBy == -1) { + System.out.println("remember to include a description and a deadline!"); throw new UnexpectedCommandException(); } + String by = line.substring(indexBy + 3); + String description = line.substring(0, indexBy - 1); tasks[index] = new Deadline(description, by); System.out.println("Got it. I've added this task: "); System.out.println(tasks[index]); @@ -72,7 +38,7 @@ public static void dealWithDeadline(Task[] tasks, int index, String line) throws public static void dealWithTodo(Task[] tasks, int index, String line) throws UnexpectedCommandException { int indexSpace = line.indexOf(" "); if (indexSpace == -1) { - System.out.println("todo description not specified"); + System.out.println("todo description cannot be empty"); throw new UnexpectedCommandException(); } @@ -95,7 +61,8 @@ private void handleEmptyInput(String line) throws EmptyLineException { } } - public ManageInputs(Task[] tasks, int index, String line) { + public ManageInputs(Task[] tasks, int index, String line){ + while (!line.equals("bye")) { Boolean isValidCommand = false; Scanner input = new Scanner(System.in); @@ -150,7 +117,7 @@ public ManageInputs(Task[] tasks, int index, String line) { handleUnexpectedCommand(isValidCommand); } catch (UnexpectedCommandException e) { System.out.println("please enter a valid command"); - } catch (EmptyLineException e) { + } catch (EmptyLineException e){ System.out.println("enter a task"); } } @@ -158,9 +125,3 @@ public ManageInputs(Task[] tasks, int index, String line) { System.out.println("Bye. Hope to see you again soon!"); } } - -/*try{ - handleFromUnspecified(); - } catch (FromUnspecifiedError e){ - System.out.println("remember to include start of event!"); - }*/ \ No newline at end of file From c43aef30e21d72dd3b09e696a9a7b88ddce1017a Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Tue, 20 Feb 2024 14:28:49 +0800 Subject: [PATCH 11/28] Revert "Revert "make error handling more error-specific"" This reverts commit 4793c541ea1fe105390fec9bb05217c3159eddd1. --- src/main/java/ManageInputs.java | 67 ++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/src/main/java/ManageInputs.java b/src/main/java/ManageInputs.java index 02bbff9fa..1ad4fa861 100644 --- a/src/main/java/ManageInputs.java +++ b/src/main/java/ManageInputs.java @@ -3,19 +3,37 @@ public class ManageInputs { protected static String from; protected static String to; - public String description; + public static String description; + protected static String by; + public static void dealWithEvent(Task[] tasks, int index, String[] inputs, String line) throws UnexpectedCommandException { int indexTo = line.indexOf("/to"); int indexFrom = line.indexOf("/from"); - if ((indexTo == -1) || (indexFrom == -1)) { - System.out.println("remember to include a description and event timeline!"); + if ((indexTo == -1) || (indexFrom == -1)) { //invalid format + System.out.println("Invalid format! Enter event in the format: event (description) /from (start) /to (end)"); + throw new UnexpectedCommandException(); + } + try {//timeline not specified/ both not specified + String from = line.substring(indexFrom + 6, indexTo - 1); + String to = line.substring(indexTo + 4); + } catch (IndexOutOfBoundsException e) { + try { + String description = line.substring(6, indexFrom - 1); + } catch (IndexOutOfBoundsException f) { + System.out.println("event description and timeline not specified"); + throw new UnexpectedCommandException(); + } + System.out.println("event timeline not specified"); + throw new UnexpectedCommandException(); + } + try {//description not specified + String description = line.substring(6, indexFrom - 1); + } catch (IndexOutOfBoundsException e) { + System.out.println("event description not specified"); throw new UnexpectedCommandException(); } - String from = line.substring(indexFrom + 6, indexTo - 1); - String to = line.substring(indexTo + 4); - String description = line.substring(6, indexFrom - 1); tasks[index] = new Event(description, from, to); System.out.println("Got it. I've added this task: "); @@ -24,12 +42,28 @@ public static void dealWithEvent(Task[] tasks, int index, String[] inputs, Strin public static void dealWithDeadline(Task[] tasks, int index, String line) throws UnexpectedCommandException { int indexBy = line.indexOf("by"); - if (indexBy == -1) { - System.out.println("remember to include a description and a deadline!"); + if (indexBy == -1) {//invalid format + System.out.println("Invalid format! Enter deadline in the format: deadline (description) by (deadline)"); + throw new UnexpectedCommandException(); + } + try {//deadline / both not specified + String by = line.substring(indexBy + 3); + } catch (IndexOutOfBoundsException e) { + try { + String description = line.substring(9, indexBy - 1); + } catch (IndexOutOfBoundsException f) { + System.out.println("deadline description and deadline not specified"); + throw new UnexpectedCommandException(); + } + System.out.println("deadline not specified"); + throw new UnexpectedCommandException(); + } + try {//deadline not specified + String description = line.substring(9, indexBy - 1); + } catch (IndexOutOfBoundsException e) { + System.out.println("deadline description not specified"); throw new UnexpectedCommandException(); } - String by = line.substring(indexBy + 3); - String description = line.substring(0, indexBy - 1); tasks[index] = new Deadline(description, by); System.out.println("Got it. I've added this task: "); System.out.println(tasks[index]); @@ -38,7 +72,7 @@ public static void dealWithDeadline(Task[] tasks, int index, String line) throws public static void dealWithTodo(Task[] tasks, int index, String line) throws UnexpectedCommandException { int indexSpace = line.indexOf(" "); if (indexSpace == -1) { - System.out.println("todo description cannot be empty"); + System.out.println("todo description not specified"); throw new UnexpectedCommandException(); } @@ -61,8 +95,7 @@ private void handleEmptyInput(String line) throws EmptyLineException { } } - public ManageInputs(Task[] tasks, int index, String line){ - + public ManageInputs(Task[] tasks, int index, String line) { while (!line.equals("bye")) { Boolean isValidCommand = false; Scanner input = new Scanner(System.in); @@ -117,7 +150,7 @@ public ManageInputs(Task[] tasks, int index, String line){ handleUnexpectedCommand(isValidCommand); } catch (UnexpectedCommandException e) { System.out.println("please enter a valid command"); - } catch (EmptyLineException e){ + } catch (EmptyLineException e) { System.out.println("enter a task"); } } @@ -125,3 +158,9 @@ public ManageInputs(Task[] tasks, int index, String line){ System.out.println("Bye. Hope to see you again soon!"); } } + +/*try{ + handleFromUnspecified(); + } catch (FromUnspecifiedError e){ + System.out.println("remember to include start of event!"); + }*/ \ No newline at end of file From e0bf4a2973deab651cd783f2fcea2ff5fdb1f753 Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Tue, 20 Feb 2024 15:19:51 +0800 Subject: [PATCH 12/28] add delete --- src/main/java/Duke.java | 4 ++- src/main/java/ManageInputs.java | 53 +++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index a09d411dc..85c754f07 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,12 @@ +import java.sql.Array; import java.util.Scanner; +import java.util.ArrayList; public class Duke { public static void main(String[] args) throws UnexpectedCommandException, EmptyLineException { - Task[] tasks = new Task[100]; + ArrayList tasks = new ArrayList(); //greeting System.out.println("Hello! I'm Apple"); diff --git a/src/main/java/ManageInputs.java b/src/main/java/ManageInputs.java index 1ad4fa861..f8b00e7c9 100644 --- a/src/main/java/ManageInputs.java +++ b/src/main/java/ManageInputs.java @@ -1,5 +1,7 @@ +import java.util.ArrayList; import java.util.Scanner; + public class ManageInputs { protected static String from; protected static String to; @@ -7,7 +9,7 @@ public class ManageInputs { protected static String by; - public static void dealWithEvent(Task[] tasks, int index, String[] inputs, String line) throws UnexpectedCommandException { + public static void dealWithEvent(ArrayList tasks, int index, String[] inputs, String line) throws UnexpectedCommandException { int indexTo = line.indexOf("/to"); int indexFrom = line.indexOf("/from"); @@ -34,13 +36,16 @@ public static void dealWithEvent(Task[] tasks, int index, String[] inputs, Strin System.out.println("event description not specified"); throw new UnexpectedCommandException(); } + String from = line.substring(indexFrom + 6, indexTo - 1); + String to = line.substring(indexTo + 4); + String description = line.substring(6, indexFrom - 1); - tasks[index] = new Event(description, from, to); + tasks.add(index, new Event(description, from, to)); System.out.println("Got it. I've added this task: "); - System.out.println(tasks[index]); + System.out.println(tasks.get(index)); } - public static void dealWithDeadline(Task[] tasks, int index, String line) throws UnexpectedCommandException { + public static void dealWithDeadline(ArrayList tasks, int index, String line) throws UnexpectedCommandException { int indexBy = line.indexOf("by"); if (indexBy == -1) {//invalid format System.out.println("Invalid format! Enter deadline in the format: deadline (description) by (deadline)"); @@ -64,12 +69,14 @@ public static void dealWithDeadline(Task[] tasks, int index, String line) throws System.out.println("deadline description not specified"); throw new UnexpectedCommandException(); } - tasks[index] = new Deadline(description, by); + String description = line.substring(9, indexBy - 1); + String by = line.substring(indexBy + 3); + tasks.add(index, new Deadline(description, by)); System.out.println("Got it. I've added this task: "); - System.out.println(tasks[index]); + System.out.println(tasks.get(index)); } - public static void dealWithTodo(Task[] tasks, int index, String line) throws UnexpectedCommandException { + public static void dealWithTodo( ArrayList tasks, int index, String line) throws UnexpectedCommandException { int indexSpace = line.indexOf(" "); if (indexSpace == -1) { System.out.println("todo description not specified"); @@ -78,9 +85,9 @@ public static void dealWithTodo(Task[] tasks, int index, String line) throws Une String description = line.substring(indexSpace); - tasks[index] = new Todo(description); + tasks.add(index, new Todo(description)); System.out.println("Got it. I've added this task: "); - System.out.println(tasks[index]); + System.out.println(tasks.get(index)); } private void handleUnexpectedCommand(boolean isValidCommand) throws UnexpectedCommandException { @@ -95,7 +102,7 @@ private void handleEmptyInput(String line) throws EmptyLineException { } } - public ManageInputs(Task[] tasks, int index, String line) { + public ManageInputs(ArrayList tasks, int index, String line) { while (!line.equals("bye")) { Boolean isValidCommand = false; Scanner input = new Scanner(System.in); @@ -107,20 +114,20 @@ public ManageInputs(Task[] tasks, int index, String line) { if (inputs[0].equals("mark")) {//mark as done isValidCommand = true; int idx = Integer.parseInt(inputs[1]); - tasks[idx - 1].markAsDone(); + tasks.get(idx - 1).markAsDone(); System.out.println("Nice! I've marked this task as done: "); - System.out.println("[" + tasks[idx - 1].getStatusIcon() + "]" + tasks[idx - 1].description); + System.out.println(tasks.get(idx-1)); } else if (inputs[0].equals("unmark")) {//unmark done isValidCommand = true; int idx = Integer.parseInt(inputs[1]); - tasks[idx - 1].unmarkDone(); + tasks.get(idx - 1).unmarkDone(); System.out.println("OK, I've marked this task as not done yet: "); - System.out.println("[" + tasks[idx - 1].getStatusIcon() + "]" + tasks[idx - 1].description); + System.out.println(tasks.get(idx-1)); } else if (line.equals("list")) {//lists tasks isValidCommand = true; System.out.println("Here are the tasks in your list: "); for (int i = 0; i < index; i++) { - System.out.println((i + 1) + ". " + tasks[i]); + System.out.println((i + 1) + ". " + tasks.get(i)); } } else if (line.equals("bye")) {//exit chat isValidCommand = true; @@ -140,10 +147,16 @@ public ManageInputs(Task[] tasks, int index, String line) { dealWithTodo(tasks, index, line); index++; } - System.out.println("Now you have " + index + " tasks in the list."); } catch (UnexpectedCommandException e) { - } + System.out.println("Now you have " + tasks.size() + " tasks in the list."); + } else if (inputs[0].equals("delete")){ + int idx = Integer.parseInt(inputs[1]); + System.out.println("Noted. I've removed this task: "); + System.out.println(tasks.get(idx-1)); + tasks.remove(idx - 1); + System.out.println("Now you have " + tasks.size() + " tasks in the list."); + index--; } else { try { handleEmptyInput(line); @@ -158,9 +171,3 @@ public ManageInputs(Task[] tasks, int index, String line) { System.out.println("Bye. Hope to see you again soon!"); } } - -/*try{ - handleFromUnspecified(); - } catch (FromUnspecifiedError e){ - System.out.println("remember to include start of event!"); - }*/ \ No newline at end of file From 4de283c67fe75cd366b03d4592d29469dc621a10 Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Thu, 22 Feb 2024 17:13:22 +0800 Subject: [PATCH 13/28] settle errors --- production/main/Deadline.class | Bin 0 -> 979 bytes production/main/Duke.class | Bin 0 -> 969 bytes production/main/EmptyLineException.class | Bin 0 -> 282 bytes production/main/Event.class | Bin 0 -> 1062 bytes production/main/ManageInputs.class | Bin 0 -> 6396 bytes production/main/Task.class | Bin 0 -> 1269 bytes production/main/Todo.class | Bin 0 -> 853 bytes production/main/UnexpectedCommandException.class | Bin 0 -> 306 bytes src/.idea/.gitignore | 8 ++++++++ src/.idea/.name | 1 + src/.idea/misc.xml | 6 ++++++ src/.idea/modules.xml | 8 ++++++++ src/.idea/vcs.xml | 6 ++++++ src/out/production/ip/Deadline.class | Bin 0 -> 979 bytes src/out/production/ip/Duke.class | Bin 0 -> 973 bytes src/out/production/ip/EmptyLineException.class | Bin 0 -> 282 bytes src/out/production/ip/Event.class | Bin 0 -> 1062 bytes src/out/production/ip/ManageInputs.class | Bin 0 -> 6396 bytes src/out/production/ip/Task.class | Bin 0 -> 1269 bytes src/out/production/ip/Todo.class | Bin 0 -> 853 bytes .../ip/UnexpectedCommandException.class | Bin 0 -> 306 bytes 21 files changed, 29 insertions(+) create mode 100644 production/main/Deadline.class create mode 100644 production/main/Duke.class create mode 100644 production/main/EmptyLineException.class create mode 100644 production/main/Event.class create mode 100644 production/main/ManageInputs.class create mode 100644 production/main/Task.class create mode 100644 production/main/Todo.class create mode 100644 production/main/UnexpectedCommandException.class create mode 100644 src/.idea/.gitignore create mode 100644 src/.idea/.name create mode 100644 src/.idea/misc.xml create mode 100644 src/.idea/modules.xml create mode 100644 src/.idea/vcs.xml create mode 100644 src/out/production/ip/Deadline.class create mode 100644 src/out/production/ip/Duke.class create mode 100644 src/out/production/ip/EmptyLineException.class create mode 100644 src/out/production/ip/Event.class create mode 100644 src/out/production/ip/ManageInputs.class create mode 100644 src/out/production/ip/Task.class create mode 100644 src/out/production/ip/Todo.class create mode 100644 src/out/production/ip/UnexpectedCommandException.class diff --git a/production/main/Deadline.class b/production/main/Deadline.class new file mode 100644 index 0000000000000000000000000000000000000000..a306b63f8fa980cc78210f9ba3e56dbf13cd91d4 GIT binary patch literal 979 zcmaJllv?2w$3`1vs@`|-z`;X? zRDa4)ZlCi@e&};`cGxk2RA)_w>`SSndBw0-OCBdH^&Z1gOAiD?sV$XwKe_0Opv(I{ zRmyGcalgj{Y4feT3UJBe3E8JQE0d_%e;t~WA+!`a5eBnSe*fz zNo8}De}LWTSS)Bio$LS5KNp^9&U=d~THNW}|P@}Jv`veW_VH0;L Kw-Yz%x%UTDOz(97 literal 0 HcmV?d00001 diff --git a/production/main/Duke.class b/production/main/Duke.class new file mode 100644 index 0000000000000000000000000000000000000000..935fed7f2e9a7b72c32b5517eddff9771252d311 GIT binary patch literal 969 zcmZuv+fEZv6kVscX=@cMf{37liWCs)9kmD{h_T6tCPfJG>9jqTfw^TmW9YZ|75X5F zBz}M&Wn8DNN(1w7_T}ue*4lf|uirm@0$4^Rj{;^4+|46_nH*+O%3>~$c`RgcFN;M3 zOL^o_HgMm-1A)wn?b*?)K(aKqBaqtgn@V8FvOTpGyLA7#WZKg+Tsy;ivvg|^qKbkSwlV*SWD*8=HCwhwtb+It&E zwo_gYL)o$Hc0};B?KRbrfT)tlp*}6@3=P=_m3D%^YNyTvUa_`GTUjMRe)FiIg2?v0 zwtf{V=ajg+FC()dJ+o>yee;tanjJr0V{fKF;jQ#!OI5ufj@p{(1^d<1g#6#`yZV7@ zL;@2ZJarV%Rm~0Gb*0z**9GUZ=>`$!=c!Z4Qy{fYJ5nxp@5hAd58n36@42yvdsEWo zTzYK|rUi^Z7dc$_XzA=4^tKoJ`N08Is^?W>8W;HI>MsGI$IEkwQJGfIrst0#zILyN zd1iV^T&7>>`$dc}%Haw|38Ei=K^iIAxf3Mzj*+y!AyrI&M@CzNHu#HvVkWw^*C}F(uP1pX ZiPsa_tGdZ5lbH-_rg4kWZAJ;)`2z_D*meK_ literal 0 HcmV?d00001 diff --git a/production/main/EmptyLineException.class b/production/main/EmptyLineException.class new file mode 100644 index 0000000000000000000000000000000000000000..c25befa72b29be5f22c51773c10e62581baf9dd6 GIT binary patch literal 282 zcmZXOy^6v>6ot=?`Oz4Ss9Yb(KGAHauN_D&ER zXW($pH|JdD@pu0P@QId-3K|ZY4t#<=QK>4Xgv#J!LojFARucSBrE+;bMlxTEC}GkL zvsfe>kt^+=&@A@qi_i_{$5ZjGJM(KSPld|TF~MDB=RB4RrTe}2$mk$0!h;Em*S|j# zIyw*}BHabAz39W>|La41xy)*_3rY`I!yD*_fdPlrW~`%CR2XpW} A7XSbN literal 0 HcmV?d00001 diff --git a/production/main/Event.class b/production/main/Event.class new file mode 100644 index 0000000000000000000000000000000000000000..6c21ce09f9b190c967a8d5cb3985cc7e04eb2cf3 GIT binary patch literal 1062 zcma)5U2hUW6g>l!g#`t%wbqYHl`3pM@XaWV50W-&s6IgOq48l@#r+UiY~?t+#dH$K=ewPQHiRWNS54@1UY8_66)MO;r7oi(?W9=!)kkM*pkzuu3i(6o@ z+iDWH;>a@+cEqx8`pYAStvoWw=3$%RHdYymZvu0MHtK(kPDsj0{J zOW5Ka#gQd#Tc{exy9|{-XX(kQ8jAUm&Kw+ZSF7OM!af~tOR3>x%#eR4r3jin4?{t= zzAoCDbIdm9Eth>?gq2xgBkpVg`Kz#VJ{C*TPZsh&_RfT>8;iZoDVp5(+nyE;3w4I= zSbxjBF>L-j4_ow0SoAX_kTQ3IW+`(mB7`m-@?f|@Q9sH6iq6gzn6rC{gtK>vLimf4Z;BpmL6yi&`QpHsvT#aiKTpNOdZF2KE`M6%emsQ-L;zkuW zDfmhV#ke_y7;aHmx8-P7>|1-zk3zj z7ea-Ua0a%i=#`82hj1Cbrr-go%Yz|I!9()#bp_uDq1q+O_m z>{GE<#Xc3^iO{s~sd!YyV=5jGA&MvDCyl!49rS~+OX}cl1dMMMOD^)9~M57fm1d5x@ zq_Lzs(PpHU>uqtaM4GL3J-$LunR1?46deM`dl*HNF=InZx82e)-|9}r(oGxM4M$y? zAjl+O>*;lAfzrHMa^I8;cs42!G?QK3HV==?qdXOjQ$qp8p;%7u6gs1Yjt@r-RJNxp ztMIsdg6A|Zr&tSnqNSRPd~V^A$WN5XzZCjS5@M&ZKU4r>MZfydKZ7 z{PdnL$%b-)p~qa~s`K)0hx%hA#YuVT`gO`rAI>VU+=|hkA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uH<-97bn>WM@ z8JEsKXAqYyz9YS;o?6?7#;IlgJ}l@%Q!mCi(jp5TF~i-->2mT3YmPs%h(q>TQ71Nu zOQDE^;vMmB=6#5l6*pZEu@ZvaLDsC{#M4ODqX|f`T3V=M;>;uz8;SfVQNN71Uqgtm zCCJwkeOuAPe^PH`Z@n11un7;~670k0@gy$A)A$0O#b)-`%lM7G86RSc@L{V^ak&_V zD?}Zx6b-ma%)`|pifcp*t`)1XP3X8zbmDrEzzrge8$}Op5}R-fEx1{1#;xK;Y!^GR zL)?$s#KX8KSQ@B&SfSuwc+$9cTmv|L-i+6B8t-VLQhkL~b93R4ctPj0DKOXS0 z>iUZDkdtuRc*j`Aird2?!+*u+M$gkj8|4}$o#^h8m&*EnG1m?|qfLB{6z|hBm(YI` z#2d8zQkJwj@jR{H%nmzKJmcI56q%dZq~=K89C%;gNZuS+kT`Ph3%Ty^oNCL|nRbjk zLJ@ui(M-7qzrt;({R;{%Q!qtAwJaz22=fl3j8<#D5fdkjE1It`@*_UNqNN-(E2uca rdNF{VFLO~yu&8~Jknk~J@`@0G5PqSG0Nd(*&WpHnfNFi$dH(RftA#b* literal 0 HcmV?d00001 diff --git a/production/main/Task.class b/production/main/Task.class new file mode 100644 index 0000000000000000000000000000000000000000..3a2f54fde81b89f064efd45733797acc57f24892 GIT binary patch literal 1269 zcmaJ>ZBNrs7(I6@YgfvKYTXW*uRTP7{% zZ30wuEb4F=hMOXGBd;yJFkrCjhy0kY_&nHOX~@V6_Nxp9FMbmSf`NUc%?mH^f&G&qY*!9rm{tk~kwawcA@pQRBYf@T92fc*d~M=WmcUhME84Fh}1-kv@wY zGu&iqNhYE%UyJZjE>>z0ES+tDT7T6V*?qk{qwb!X(%~A vNXIF1=cE|K2?G4)BrsvLITr~)T literal 0 HcmV?d00001 diff --git a/production/main/Todo.class b/production/main/Todo.class new file mode 100644 index 0000000000000000000000000000000000000000..849ca63fab366a0422eb4540960b1143f875a496 GIT binary patch literal 853 zcmaJ<&2AGh5dNH|yXkfzA+$jGX(^;7DH6RPaahy?kt&b^91^vMst0G+YTRt?Xzf($ zoA4NLs?-Ay(1)rR@2*5pB7CrC#@~-;CB98Bh9VpAVM>)|Pscnx;+b@LS*+TT zG^E-a=tM^htBEjiCMQ;EuDB?L+NZ+obo%T6T*WZqK*bb zE*i-E^L%VOlO2ZE-{z#c)MHVOu~0wcvDMj?k2h{ST92m_hVYA0BI~By7(tdl zW-UvNqMy%PC8;p2f*8#|W2W*Cad0&e3*aX+`0vAW5!+~X^rb|Xr)ghW5&38{?9BDI z=xq#}|Hok)Rr-c*RY0?VPkW8B1IjCOdV6oL!G7iUE3^lB)p3?71|AhCtRke0@VJNj zq(Pq)jZ*7@fz$Ko4&>;x!aNR2ttC9jQBAby4Cw9^cJUe;SkD=Z Iyy?sQ0WDe3RR910 literal 0 HcmV?d00001 diff --git a/production/main/UnexpectedCommandException.class b/production/main/UnexpectedCommandException.class new file mode 100644 index 0000000000000000000000000000000000000000..6c0d54dfee7340a2a50b2c5d8b341ff75f628cf2 GIT binary patch literal 306 zcmZ{f&1%9>5QWdg{M0o5V0R*jJL|$MyQp*{brsy$y1youdP{Pzq)~h=S3(y)Kp(1f zZYb`Yfy11S!wmED`+WiMgl>oiS^?StIs|{Fw5nbRjq&4};Lc4Z37te~x!e~US-y!) z&ZL)^ROD+>D(nBDTW!@BVUWCQdECjglG)r8h0xjSF_pVY8U0KMS7u+Pa-r;=;qB=3 zQyfGD7apO1J4Sf0!8jNCBfj3j2oC>ci@13StIsa3J>X5wpc4ZJ0jtm0M( + + + + + \ No newline at end of file diff --git a/src/.idea/modules.xml b/src/.idea/modules.xml new file mode 100644 index 000000000..b8cce4602 --- /dev/null +++ b/src/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/.idea/vcs.xml b/src/.idea/vcs.xml new file mode 100644 index 000000000..6c0b86358 --- /dev/null +++ b/src/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/out/production/ip/Deadline.class b/src/out/production/ip/Deadline.class new file mode 100644 index 0000000000000000000000000000000000000000..a306b63f8fa980cc78210f9ba3e56dbf13cd91d4 GIT binary patch literal 979 zcmaJllv?2w$3`1vs@`|-z`;X? zRDa4)ZlCi@e&};`cGxk2RA)_w>`SSndBw0-OCBdH^&Z1gOAiD?sV$XwKe_0Opv(I{ zRmyGcalgj{Y4feT3UJBe3E8JQE0d_%e;t~WA+!`a5eBnSe*fz zNo8}De}LWTSS)Bio$LS5KNp^9&U=d~THNW}|P@}Jv`veW_VH0;L Kw-Yz%x%UTDOz(97 literal 0 HcmV?d00001 diff --git a/src/out/production/ip/Duke.class b/src/out/production/ip/Duke.class new file mode 100644 index 0000000000000000000000000000000000000000..9e185dddeb79cf764bf50cf40cdfb04de1c4fa81 GIT binary patch literal 973 zcmZuv?M@Rx6g|@qwyj052x0|YRHT4V6&1AzA&9ZbiY6e0_-opZWnsUv-8J-CdlqSDa)acAbv*>ldlcYgi;@e{x@DmmmaZQx!G2~1}(gHi^wIm}@`gZmjQ z7+B09i?V?S1|A9wtk|9%tqLSdv%3PR4ZooThAi7tTd`YH;f}01%oHrYE}dN&+WLH! zOhpHFiyYRg_()aww<~Q=V661fI+UMf*^yqeyd8zM*Q|8dW!NNsq|dcLI+Cp;-i~(v zjU(GBuZN**TXriVdD`|G>R3QjDdfb*|e!C$wN{fJkr9m-Z#DUjPduB#xj zeXnKUk%1+qw*5G)tJk(}K~`6}s1@@V#AVjeQSUWs;Bg*L@Kj*UA9V*fmKE_se*yWNVE%h~%esm>a2`{nnXSj4$0 z>9Q}~GJDekMxa3s$30rQI0ilK`Lld)gDTa2XiVV}U#|WV5W2mLLp&{U68Tc&6ot=?`Oz4Ss9Yb(KGAHauN_D&ER zXW($pH|JdD@pu0P@QId-3K|ZY4t#<=QK>4Xgv#J!LojFARucSBrE+;bMlxTEC}GkL zvsfe>kt^+=&@A@qi_i_{$5ZjGJM(KSPld|TF~MDB=RB4RrTe}2$mk$0!h;Em*S|j# zIyw*}BHabAz39W>|La41xy)*_3rY`I!yD*_fdPlrW~`%CR2XpW} A7XSbN literal 0 HcmV?d00001 diff --git a/src/out/production/ip/Event.class b/src/out/production/ip/Event.class new file mode 100644 index 0000000000000000000000000000000000000000..6c21ce09f9b190c967a8d5cb3985cc7e04eb2cf3 GIT binary patch literal 1062 zcma)5U2hUW6g>l!g#`t%wbqYHl`3pM@XaWV50W-&s6IgOq48l@#r+UiY~?t+#dH$K=ewPQHiRWNS54@1UY8_66)MO;r7oi(?W9=!)kkM*pkzuu3i(6o@ z+iDWH;>a@+cEqx8`pYAStvoWw=3$%RHdYymZvu0MHtK(kPDsj0{J zOW5Ka#gQd#Tc{exy9|{-XX(kQ8jAUm&Kw+ZSF7OM!af~tOR3>x%#eR4r3jin4?{t= zzAoCDbIdm9Eth>?gq2xgBkpVg`Kz#VJ{C*TPZsh&_RfT>8;iZoDVp5(+nyE;3w4I= zSbxjBF>L-j4_ow0SoAX_kTQ3IW+`(mB7`m-@?f|@Q9sH6iq6gzn6rC{gtK>vLimf4Z;BpmL6yi&`QpHsvT#aiKTpNOdZF2KE`M6%emsQ-L;zkuW zDfmhV#ke_y7;aHmx8-P7>|1-zk3zj z7ea-Ua0a%i=#`82hj1Cbrr-go%Yz|I!9()#bp_uDq1q+O_m z>{GE<#Xc3^iO{s~sd!YyV=5jGA&MvDCyl!49rS~+OX}cl1dMMMOD^)9~M57fm1d5x@ zq_Lzs(PpHU>uqtaM4GL3J-$LunR1?46deM`dl*HNF=InZx82e)-|9}r(oGxM4M$y? zAjl+O>*;lAfzrHMa^I8;cs42!G?QK3HV==?qdXOjQ$qp8p;%7u6gs1Yjt@r-RJNxp ztMIsdg6A|Zr&tSnqNSRPd~V^A$WN5XzZCjS5@M&ZKU4r>MZfydKZ7 z{PdnL$%b-)p~qa~s`K)0hx%hA#YuVT`gO`rAI>VU+=|hkA;+JsU3xpM z9KBXg#^T1=Nn=Bo(QX^DMk|rv65~+0%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@%Q!mCi(jp5TF~i-->2mT3YmPs%h(q>TQ71Nu zOQDE^;vMmB=6#5l6*pZEu@ZvaLDsC{#M4ODqX|f`T3V=M;>;uz8;SfVQNN71Uqgtm zCCJwkeOuAPe^PH`Z@n11un7;~670k0@gy$A)A$0O#b)-`%lM7G86RSc@L{V^ak&_V zD?}Zx6b-ma%)`|pifcp*t`)1XP3X8zbmDrEzzrge8$}Op5}R-fEx1{1#;xK;Y!^GR zL)?$s#KX8KSQ@B&SfSuwc+$9cTmv|L-i+6B8t-VLQhkL~b93R4ctPj0DKOXS0 z>iUZDkdtuRc*j`Aird2?!+*u+M$gkj8|4}$o#^h8m&*EnG1m?|qfLB{6z|hBm(YI` z#2d8zQkJwj@jR{H%nmzKJmcI56q%dZq~=K89C%;gNZuS+kT`Ph3%Ty^oNCL|nRbjk zLJ@ui(M-7qzrt;({R;{%Q!qtAwJaz22=fl3j8<#D5fdkjE1It`@*_UNqNN-(E2uca rdNF{VFLO~yu&8~Jknk~J@`@0G5PqSG0Nd(*&WpHnfNFi$dH(RftA#b* literal 0 HcmV?d00001 diff --git a/src/out/production/ip/Task.class b/src/out/production/ip/Task.class new file mode 100644 index 0000000000000000000000000000000000000000..3a2f54fde81b89f064efd45733797acc57f24892 GIT binary patch literal 1269 zcmaJ>ZBNrs7(I6@YgfvKYTXW*uRTP7{% zZ30wuEb4F=hMOXGBd;yJFkrCjhy0kY_&nHOX~@V6_Nxp9FMbmSf`NUc%?mH^f&G&qY*!9rm{tk~kwawcA@pQRBYf@T92fc*d~M=WmcUhME84Fh}1-kv@wY zGu&iqNhYE%UyJZjE>>z0ES+tDT7T6V*?qk{qwb!X(%~A vNXIF1=cE|K2?G4)BrsvLITr~)T literal 0 HcmV?d00001 diff --git a/src/out/production/ip/Todo.class b/src/out/production/ip/Todo.class new file mode 100644 index 0000000000000000000000000000000000000000..849ca63fab366a0422eb4540960b1143f875a496 GIT binary patch literal 853 zcmaJ<&2AGh5dNH|yXkfzA+$jGX(^;7DH6RPaahy?kt&b^91^vMst0G+YTRt?Xzf($ zoA4NLs?-Ay(1)rR@2*5pB7CrC#@~-;CB98Bh9VpAVM>)|Pscnx;+b@LS*+TT zG^E-a=tM^htBEjiCMQ;EuDB?L+NZ+obo%T6T*WZqK*bb zE*i-E^L%VOlO2ZE-{z#c)MHVOu~0wcvDMj?k2h{ST92m_hVYA0BI~By7(tdl zW-UvNqMy%PC8;p2f*8#|W2W*Cad0&e3*aX+`0vAW5!+~X^rb|Xr)ghW5&38{?9BDI z=xq#}|Hok)Rr-c*RY0?VPkW8B1IjCOdV6oL!G7iUE3^lB)p3?71|AhCtRke0@VJNj zq(Pq)jZ*7@fz$Ko4&>;x!aNR2ttC9jQBAby4Cw9^cJUe;SkD=Z Iyy?sQ0WDe3RR910 literal 0 HcmV?d00001 diff --git a/src/out/production/ip/UnexpectedCommandException.class b/src/out/production/ip/UnexpectedCommandException.class new file mode 100644 index 0000000000000000000000000000000000000000..6c0d54dfee7340a2a50b2c5d8b341ff75f628cf2 GIT binary patch literal 306 zcmZ{f&1%9>5QWdg{M0o5V0R*jJL|$MyQp*{brsy$y1youdP{Pzq)~h=S3(y)Kp(1f zZYb`Yfy11S!wmED`+WiMgl>oiS^?StIs|{Fw5nbRjq&4};Lc4Z37te~x!e~US-y!) z&ZL)^ROD+>D(nBDTW!@BVUWCQdECjglG)r8h0xjSF_pVY8U0KMS7u+Pa-r;=;qB=3 zQyfGD7apO1J4Sf0!8jNCBfj3j2oC>ci@13StIsa3J>X5wpc4ZJ0jtm0M( Date: Fri, 23 Feb 2024 02:27:48 +0800 Subject: [PATCH 14/28] add save --- src/main/java/CreateFile.java | 2 ++ src/main/java/ReadFileContents.java | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 src/main/java/CreateFile.java create mode 100644 src/main/java/ReadFileContents.java diff --git a/src/main/java/CreateFile.java b/src/main/java/CreateFile.java new file mode 100644 index 000000000..895711ff5 --- /dev/null +++ b/src/main/java/CreateFile.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class CreateFile { +} diff --git a/src/main/java/ReadFileContents.java b/src/main/java/ReadFileContents.java new file mode 100644 index 000000000..f5f39b9d8 --- /dev/null +++ b/src/main/java/ReadFileContents.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class ReadFileContents { +} From 011c695f9f3c86b23caa4d00802262bb1895062a Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Fri, 23 Feb 2024 02:31:14 +0800 Subject: [PATCH 15/28] resolve errors --- production/main/CreateFile.class | Bin 0 -> 1498 bytes production/main/Duke.class | Bin 969 -> 2188 bytes production/main/ManageInputs.class | Bin 6396 -> 7530 bytes production/main/ReadFileContents.class | Bin 0 -> 1178 bytes production/main/Task.class | Bin 1269 -> 1269 bytes src/TaskList.txt | 16 +++++ src/main/java/CreateFile.java | 22 +++++- src/main/java/Duke.java | 20 +++++- src/main/java/ManageInputs.java | 96 +++++++++++++++++-------- src/main/java/ReadFileContents.java | 27 ++++++- src/main/java/Task.java | 2 +- 11 files changed, 148 insertions(+), 35 deletions(-) create mode 100644 production/main/CreateFile.class create mode 100644 production/main/ReadFileContents.class create mode 100644 src/TaskList.txt diff --git a/production/main/CreateFile.class b/production/main/CreateFile.class new file mode 100644 index 0000000000000000000000000000000000000000..1e7af2c5365d3284f5f318ad9bc1c8eab0f00334 GIT binary patch literal 1498 zcmaJ>+fo}x5IrM6E7pr-gu%Jmij5tC9psQ05=4kW0UJkL63I>_c^Xz@SZlSb+8sIY zCrN(5&&~s`a;owH`38TAE0r@V1u2EfQq@d%PhZaIp4q?udG!~7WjwMmiCGIbGPr3Y zg^$frG|SvL=5fnNxASzpW8+gSX7HJX&oj7d!@*J>0(UHYVc|=G^r{zldQD)YIQLj! zv=TOyK(6WqYPZumP*GhT__XA!p)38zGV+YxGmh#bFBWjBl}Jggwme^znWH7WKwzf$ zbM>iwCQH5y4ofv1dBI`X)DTQJ-97Tc()Qlwv8&qJ3j-4?qeEt#8WPIDCj!~Cz+Sb9 znwD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r z3FF`tb!g-triEhUI6~PNB1q9Be{v>pM-)TEG&&-NVcKS-tBunZW7IuLQ6|4&(?B&r SDu*g6X%d(;h)xleF#QKU_CE;# diff --git a/production/main/ManageInputs.class b/production/main/ManageInputs.class index 3e38f8aa6da2f190899aeab88685856463c9fe05..ba19acc4b42a395b4b1ba140abfe69d1213fc6df 100644 GIT binary patch literal 7530 zcma)B349dSdH=uBN;6spBvuk2B;n<-(G3WL%yLVJAR`2}WUx3KM%qDIkap$WSwQ4; z>V_l^>5iriGTbw z@6CJfyZ_(!zFA)Q)y3xkG^;ipj|ZXfsSsa3BeN&v@mU>D1yO*rIzAVKfzQk13-UN; z;Cv8o#nVCT#}^GeBjcEXaTzZdI4GOX8n~|z7jenJmxA~*p3`wTh;m$!&9BJgt2(}B z;CTaIH}DM|-wa|Qz7@o~@ofXW23|05)xe7e{=~p{bbL36T71vIpX&I25DhphEdET# zOF=9brU!7vz@Li-e_`M+W%I9scocsvI{ZMi{u>>C8$`q-{Goxr3*txkdy)5JS$^5T zPejjuFz{1(|3?EqGw@Fa{y9Wv{ELB~8~9fP|0WXt-N1k7_)i`G6~s>bxA6F%5H$S4 z!2cQerM&;YoO@L?cui)n8@OiRR|c-@3c6AXfkVl}kV2^Auyxd0HfY8BmvuSGSiFC& zg61R?W<>2&UotlA#1e5X^^S1qSTg3=-HENSL0h4sdMa&4x0O1wwq`f^weOy72MjcX^HAy+DrAS=jBkt<6;&E5uIg>pwGMx27 zmG5{?(RH2=Hjw4aF30LSvcnp7y{0RT-s+0=$1NwFq{=I&H8e->G51H>HF##!wg&ga zoPoBZ^w&+@)jpM6!hEZ5xm`T6Gwtj=)RIWYqp4h6#2eHvFz9+#cRkllh!wiCtpuX3 z@_wuSH_@OttN#|;iuxtA5V85GVXKd#&FrD>M3jPquHY_jZ|;Bq5cAsNM zTN6V=T%y9&dtE3y12G13R>ux2ZuQ&k@!_SR zCUR*2!h5dHN3-i1`^R!QGqHjlx`|R6`CrD51DF)G8rI03lif)6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J^%ybyiwvLRL|T!fbk5>UQ9SzSR~wJ z@=kVY*;1Nz7Tv#$?r)|0S1=9FWl&aPHl475CQJ97>?)9RP*cu9O*se6h2=PCA`@Cx zQNPD6O&+%dA*5S|06#%D^M=YNYc2nL{AF<&y92|rwRATZ3LNE&_y$G$nX_REl1h$p z35bO>XRCdnEegtvDm;?2M$6>ON@OrLYPX?&BUCEG$M(8T{{Gr$<;x zPFRWKhnz5Z%+2cxYOsN^bjr{QVRF6y0H&^^trIJ*(g%Bjvupk9@Z>BHRpEGSaHUf2$g(;RuH<-97bn>WM@ z8JEsKXAqYyz9YS;o?6?7#;IlgJ}l@%Q!mCi(jp5TF~i-->2mT3YmPs%h(q>TQ71Nu zOQDE^;vMmB=6#5l6*pZEu@ZvaLDsC{#M4ODqX|f`T3V=M;>;uz8;SfVQNN71Uqgtm zCCJwkeOuAPe^PH`Z@n11un7;~670k0@gy$A)A$0O#b)-`%lM7G86RSc@L{V^ak&_V zD?}Zx6b-ma%)`|pifcp*t`)1XP3X8zbmDrEzzrge8$}Op5}R-fEx1{1#;xK;Y!^GR zL)?$s#KX8KSQ@B&SfSuwc+$9cTmv|L-i+6B8t-VLQhkL~b93R4ctPj0DKOXS0 z>iUZDkdtuRc*j`Aird2?!+*u+M$gkj8|4}$o#^h8m&*EnG1m?|qfLB{6z|hBm(YI` z#2d8zQkJwj@jR{H%nmzKJmcI56q%dZq~=K89C%;gNZuS+kT`Ph3%Ty^oNCL|nRbjk zLJ@ui(M-7qzrt;({R;{%Q!qtAwJaz22=fl3j8<#D5fdkjE1It`@*_UNqNN-(E2uca rdNF{VFLO~yu&8~Jknk~J@`@0G5PqSG0Nd(*&WpHnfNFi$dH(RftA#b* diff --git a/production/main/ReadFileContents.class b/production/main/ReadFileContents.class new file mode 100644 index 0000000000000000000000000000000000000000..acca04e15829034df832c68fd394f0eebc1fa239 GIT binary patch literal 1178 zcmZuw*-{fh6g{0xm}D3r3kecMa3w4fcT^CU2>K9^G87j2)Pw;Bk{K%LD1L$8;1}?W z4`4}^AK=gU1umzPKm}r@()adV&OP_`ou7Zc{{S$Fmlk3eGcj%A3)%T{+P@8U5``$QmZO$z@Ip0%`r>au|v7L(RsaB&vGLzqu zA7r*9y^U-^F<@g#R}HT-cTuWMjnx(*Al3!C8xGgcYD^Xotej{VYsxKU3q|R9PKBPX zf|AAUdAZZ1Y0d5yogL-+9#f36bUlGo=6!o5%|)=;!Be#sd^P9SytNY)mM~;xL)ZTg zh=5h_Yn7s-d9vrTvzgEh+K3||VAq>%_M~lT4z6x%ZAm*G+nB)<6HjeC!*d%syf86q zV@{{oOR~D1cdKeb?J67n+BVP%-PQt0<|>XyYQGp>^G2_VU{qhUmfy4}?K zaE>=iPm)nO`7^+1weSHVdw+jv_+TAAg%I^H zBK*bcke#^Bk5HEzYCz&VF7Ot?MGWw-IVUklZ-BjMQi0!yn+TXN61Yr@!5EwIS8$b@ zruUJt0m^jT`i9Ou^palJ$|1Vnl2*Kjr1lxf-pRynGE1{{a8e<133EyjBE?v_AANOp fDI!KV%WLGTbJG|`hEj7Pn^z|6C>$A|Cp` literal 0 HcmV?d00001 diff --git a/production/main/Task.class b/production/main/Task.class index 3a2f54fde81b89f064efd45733797acc57f24892..668ea5de9cc3c1d21e105be94975fc6c0b04aa76 100644 GIT binary patch delta 18 Zcmey$`IU2nA0w+FBLkzs=3vG}%m6sV1rPuL delta 18 Zcmey$`IU2nA0ul7BLkzt=3vG}%m6v+1t$Oi diff --git a/src/TaskList.txt b/src/TaskList.txt new file mode 100644 index 000000000..74091fd17 --- /dev/null +++ b/src/TaskList.txt @@ -0,0 +1,16 @@ +[T][0] hike +[T][0] run +[D][0] tut (by: 5) +[E][0] he (from: 5 to: 6) +[T][0] jump +[T][0] go +[D][0] hop (by: 4) +[E][0] he (from: 4 to: 5) +[D][0] b (by: 4) +[E][0] go (from: 4 to: 454) +[T][0] ds +[D][0] kj (by: 4) +[T][0] he +[E][0] f (from: 4 to: 5) +[D][0] sd (by: 5) +[D][0] hsd (by: 343354535) diff --git a/src/main/java/CreateFile.java b/src/main/java/CreateFile.java index 895711ff5..32ac2b64e 100644 --- a/src/main/java/CreateFile.java +++ b/src/main/java/CreateFile.java @@ -1,2 +1,22 @@ -package PACKAGE_NAME;public class CreateFile { +import java.io.File; +import java.io.IOException; + +public class CreateFile { + public static void main(String[] args) { + File f = new File("TaskList.txt"); + if (!f.exists()) { + try { + if (f.createNewFile()) { + System.out.println("File created: " + f.getAbsolutePath()); + } else { + System.out.println("File creation failed."); + } + } catch (IOException e) { + System.out.println("An error occurred."); + e.printStackTrace(); + } + } else { + System.out.println("File already exists: " + f.getAbsolutePath()); + } + } } diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 85c754f07..770e0ea1c 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,17 +1,35 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; import java.sql.Array; import java.util.Scanner; import java.util.ArrayList; public class Duke { + private static void printFileContents(String filePath) throws FileNotFoundException { + File f = new File(filePath); // create a File for the given file path + Scanner s = new Scanner(f); // create a Scanner using the File as the source + while (s.hasNext()) { + System.out.println(s.nextLine()); + } + } - public static void main(String[] args) throws UnexpectedCommandException, EmptyLineException { + public static void main(String[] args) throws UnexpectedCommandException, EmptyLineException, IOException { ArrayList tasks = new ArrayList(); //greeting System.out.println("Hello! I'm Apple"); System.out.println("What can I do for you?"); + try { + System.out.println("Here are the items in your task list: "); + printFileContents("TaskList.txt"); + } catch (FileNotFoundException e) { + File f = new File("TaskList.txt"); + System.out.println("File not found"); + System.out.println("File created: " + f.getAbsolutePath()); + } int index = 0;//number of items in the list String line = " "; diff --git a/src/main/java/ManageInputs.java b/src/main/java/ManageInputs.java index f8b00e7c9..58c280686 100644 --- a/src/main/java/ManageInputs.java +++ b/src/main/java/ManageInputs.java @@ -1,25 +1,50 @@ +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; - public class ManageInputs { protected static String from; protected static String to; public static String description; protected static String by; + private static void writeToFile(String filePath, Task textToAdd) throws IOException { + FileWriter fw = new FileWriter(filePath, true); + fw.write(textToAdd + "\n"); + fw.close(); + } + + private static int fillFileContents(ArrayList tasks, String filePath, int index) throws IOException, UnexpectedCommandException {//updates index + File f = new File(filePath); // create a File for the given file path + Scanner s = new Scanner(f); // create a Scanner using the File as the source + + while (s.hasNext()) { + String sLine = s.nextLine(); + if (sLine.contains("[E]")) { + dealWithEvent(tasks, index, sLine); + } else if (sLine.contains("[D]")) { + dealWithDeadline(tasks, index, sLine); + } else if (sLine.contains("[T]")) { + dealWithTodo(tasks, index, sLine); + } + index++; + } + return index; + } - public static void dealWithEvent(ArrayList tasks, int index, String[] inputs, String line) throws UnexpectedCommandException { - int indexTo = line.indexOf("/to"); - int indexFrom = line.indexOf("/from"); + public static void dealWithEvent(ArrayList tasks, int index, String line) throws UnexpectedCommandException, IOException { + int indexTo = line.indexOf("to"); + int indexFrom = line.indexOf("from"); if ((indexTo == -1) || (indexFrom == -1)) { //invalid format - System.out.println("Invalid format! Enter event in the format: event (description) /from (start) /to (end)"); + System.out.println("Invalid format! Enter event in the format: event (description) from (start) to (end)"); throw new UnexpectedCommandException(); } try {//timeline not specified/ both not specified - String from = line.substring(indexFrom + 6, indexTo - 1); - String to = line.substring(indexTo + 4); + String from = line.substring(indexFrom + 5, indexTo - 1); + String to = line.substring(indexTo + 2); } catch (IndexOutOfBoundsException e) { try { String description = line.substring(6, indexFrom - 1); @@ -36,26 +61,25 @@ public static void dealWithEvent(ArrayList tasks, int index, String[] inpu System.out.println("event description not specified"); throw new UnexpectedCommandException(); } - String from = line.substring(indexFrom + 6, indexTo - 1); - String to = line.substring(indexTo + 4); - String description = line.substring(6, indexFrom - 1); + String from = line.substring(indexFrom + 5, indexTo - 1); + String to = line.substring(indexTo + 2); + String description = line.substring(5, indexFrom - 1); tasks.add(index, new Event(description, from, to)); - System.out.println("Got it. I've added this task: "); - System.out.println(tasks.get(index)); } - public static void dealWithDeadline(ArrayList tasks, int index, String line) throws UnexpectedCommandException { + public static void dealWithDeadline(ArrayList tasks, int index, String line) throws UnexpectedCommandException, IOException { int indexBy = line.indexOf("by"); + int space = line.indexOf(" "); if (indexBy == -1) {//invalid format System.out.println("Invalid format! Enter deadline in the format: deadline (description) by (deadline)"); throw new UnexpectedCommandException(); } try {//deadline / both not specified - String by = line.substring(indexBy + 3); + String by = line.substring(indexBy + 2); } catch (IndexOutOfBoundsException e) { try { - String description = line.substring(9, indexBy - 1); + String description = line.substring(space, indexBy - 1); } catch (IndexOutOfBoundsException f) { System.out.println("deadline description and deadline not specified"); throw new UnexpectedCommandException(); @@ -64,19 +88,18 @@ public static void dealWithDeadline(ArrayList tasks, int index, String lin throw new UnexpectedCommandException(); } try {//deadline not specified - String description = line.substring(9, indexBy - 1); + String description = line.substring(space, indexBy - 1); } catch (IndexOutOfBoundsException e) { System.out.println("deadline description not specified"); throw new UnexpectedCommandException(); } - String description = line.substring(9, indexBy - 1); - String by = line.substring(indexBy + 3); + String description = line.substring(space, indexBy - 1); + String by = line.substring(indexBy + 2); + tasks.add(index, new Deadline(description, by)); - System.out.println("Got it. I've added this task: "); - System.out.println(tasks.get(index)); } - public static void dealWithTodo( ArrayList tasks, int index, String line) throws UnexpectedCommandException { + public static void dealWithTodo(ArrayList tasks, int index, String line) throws UnexpectedCommandException, IOException { int indexSpace = line.indexOf(" "); if (indexSpace == -1) { System.out.println("todo description not specified"); @@ -86,8 +109,7 @@ public static void dealWithTodo( ArrayList tasks, int index, String line) String description = line.substring(indexSpace); tasks.add(index, new Todo(description)); - System.out.println("Got it. I've added this task: "); - System.out.println(tasks.get(index)); + } private void handleUnexpectedCommand(boolean isValidCommand) throws UnexpectedCommandException { @@ -102,7 +124,8 @@ private void handleEmptyInput(String line) throws EmptyLineException { } } - public ManageInputs(ArrayList tasks, int index, String line) { + public ManageInputs(ArrayList tasks, int index, String line) throws IOException, UnexpectedCommandException { + index = fillFileContents(tasks, "TaskList.txt", index); while (!line.equals("bye")) { Boolean isValidCommand = false; Scanner input = new Scanner(System.in); @@ -110,22 +133,23 @@ public ManageInputs(ArrayList tasks, int index, String line) { Task t = new Task(line); String[] inputs = line.split(" "); - + if (inputs[0].equals("mark")) {//mark as done isValidCommand = true; int idx = Integer.parseInt(inputs[1]); tasks.get(idx - 1).markAsDone(); System.out.println("Nice! I've marked this task as done: "); - System.out.println(tasks.get(idx-1)); + System.out.println(tasks.get(idx - 1)); } else if (inputs[0].equals("unmark")) {//unmark done isValidCommand = true; int idx = Integer.parseInt(inputs[1]); tasks.get(idx - 1).unmarkDone(); System.out.println("OK, I've marked this task as not done yet: "); - System.out.println(tasks.get(idx-1)); + System.out.println(tasks.get(idx - 1)); } else if (line.equals("list")) {//lists tasks isValidCommand = true; System.out.println("Here are the tasks in your list: "); + for (int i = 0; i < index; i++) { System.out.println((i + 1) + ". " + tasks.get(i)); } @@ -136,24 +160,36 @@ public ManageInputs(ArrayList tasks, int index, String line) { try { if (inputs[0].equals("event")) { isValidCommand = true; - dealWithEvent(tasks, index, inputs, line); + dealWithEvent(tasks, index, line); + writeToFile("TaskList.txt", tasks.get(index)); + System.out.println("Got it. I've added this task: "); + System.out.println(tasks.get(index)); index++; } else if (inputs[0].equals("deadline")) { isValidCommand = true; dealWithDeadline(tasks, index, line); + writeToFile("TaskList.txt", tasks.get(index)); + System.out.println("Got it. I've added this task: "); + System.out.println(tasks.get(index)); index++; } else { isValidCommand = true; dealWithTodo(tasks, index, line); + writeToFile("TaskList.txt", tasks.get(index)); + System.out.println("Got it. I've added this task: "); + System.out.println(tasks.get(index)); index++; } } catch (UnexpectedCommandException e) { + } catch (IOException e) { + throw new RuntimeException(e); } System.out.println("Now you have " + tasks.size() + " tasks in the list."); - } else if (inputs[0].equals("delete")){ + } else if (inputs[0].equals("delete")) { + isValidCommand = true; int idx = Integer.parseInt(inputs[1]); System.out.println("Noted. I've removed this task: "); - System.out.println(tasks.get(idx-1)); + System.out.println(tasks.get(idx - 1)); tasks.remove(idx - 1); System.out.println("Now you have " + tasks.size() + " tasks in the list."); index--; diff --git a/src/main/java/ReadFileContents.java b/src/main/java/ReadFileContents.java index f5f39b9d8..9f914cc71 100644 --- a/src/main/java/ReadFileContents.java +++ b/src/main/java/ReadFileContents.java @@ -1,2 +1,25 @@ -package PACKAGE_NAME;public class ReadFileContents { -} +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class ReadFileContents { + + private static void printFileContents(String filePath) throws FileNotFoundException { + File f = new File(filePath); // create a File for the given file path + Scanner s = new Scanner(f); // create a Scanner using the File as the source + while (s.hasNext()) { + System.out.println(s.nextLine()); + } + } + + public static void main(String[] args) { + try { + printFileContents("TaskList.txt"); + + } catch (FileNotFoundException e) { + new CreateFile(); + System.out.println("File not found"); + } + } + +} \ No newline at end of file diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 87b80a79e..43f4b8705 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -7,7 +7,7 @@ public Task(String description) { } public String getStatusIcon() { - return (isDone ? "X" : " "); // mark done task with X + return (isDone ? "1" : "0"); // mark done task with X } public void markAsDone() { From b1fd82dd74ba227a2a9e43ddc187b8c067735cc4 Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Sat, 2 Mar 2024 12:04:09 +0800 Subject: [PATCH 16/28] fix formatting when listing tasks --- src/main/java/ManageInputs.java | 80 ++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 25 deletions(-) diff --git a/src/main/java/ManageInputs.java b/src/main/java/ManageInputs.java index 58c280686..587f0af4c 100644 --- a/src/main/java/ManageInputs.java +++ b/src/main/java/ManageInputs.java @@ -16,38 +16,47 @@ private static void writeToFile(String filePath, Task textToAdd) throws IOExcept fw.close(); } - private static int fillFileContents(ArrayList tasks, String filePath, int index) throws IOException, UnexpectedCommandException {//updates index + + + private static int fillFileContents(ArrayList tasks, String filePath, int index, boolean isInTxt) throws IOException, UnexpectedCommandException {//updates index File f = new File(filePath); // create a File for the given file path Scanner s = new Scanner(f); // create a Scanner using the File as the source while (s.hasNext()) { + String sLine = s.nextLine(); if (sLine.contains("[E]")) { - dealWithEvent(tasks, index, sLine); + dealWithEvent(tasks, index, sLine, true); } else if (sLine.contains("[D]")) { - dealWithDeadline(tasks, index, sLine); + dealWithDeadline(tasks, index, sLine, true); } else if (sLine.contains("[T]")) { - dealWithTodo(tasks, index, sLine); + dealWithTodo(tasks, index, sLine, true); } index++; } + isInTxt = false; return index; } - public static void dealWithEvent(ArrayList tasks, int index, String line) throws UnexpectedCommandException, IOException { - int indexTo = line.indexOf("to"); + + + public static void dealWithEvent(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { + int indexTo = line.lastIndexOf("to"); int indexFrom = line.indexOf("from"); + String from; + String to; + String description; if ((indexTo == -1) || (indexFrom == -1)) { //invalid format System.out.println("Invalid format! Enter event in the format: event (description) from (start) to (end)"); throw new UnexpectedCommandException(); } try {//timeline not specified/ both not specified - String from = line.substring(indexFrom + 5, indexTo - 1); - String to = line.substring(indexTo + 2); + from = line.substring(indexFrom + 5, indexTo - 1); + to = line.substring(indexTo + 2); } catch (IndexOutOfBoundsException e) { try { - String description = line.substring(6, indexFrom - 1); + description = line.substring(5, indexFrom - 1); } catch (IndexOutOfBoundsException f) { System.out.println("event description and timeline not specified"); throw new UnexpectedCommandException(); @@ -56,30 +65,40 @@ public static void dealWithEvent(ArrayList tasks, int index, String line) throw new UnexpectedCommandException(); } try {//description not specified - String description = line.substring(6, indexFrom - 1); + description = line.substring(5, indexFrom - 1); } catch (IndexOutOfBoundsException e) { System.out.println("event description not specified"); throw new UnexpectedCommandException(); } - String from = line.substring(indexFrom + 5, indexTo - 1); - String to = line.substring(indexTo + 2); - String description = line.substring(5, indexFrom - 1); + if(!isInTxt) { + from = line.substring(indexFrom + 5, indexTo - 1); + to = line.substring(indexTo + 3); + description = line.substring(5, indexFrom - 1); + } else { + from = line.substring(indexFrom + 6, indexTo - 1); + to = line.substring(indexTo + 4, line.length() - 1); + description = line.substring(5, indexFrom - 1); + } //when uncomment this, cannot add but reads file contents properly + //when commented, can add but cannot read file contents properly + //System.out.println(isInTxt); tasks.add(index, new Event(description, from, to)); } - public static void dealWithDeadline(ArrayList tasks, int index, String line) throws UnexpectedCommandException, IOException { + public static void dealWithDeadline(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { int indexBy = line.indexOf("by"); int space = line.indexOf(" "); + String by; + String description; if (indexBy == -1) {//invalid format System.out.println("Invalid format! Enter deadline in the format: deadline (description) by (deadline)"); throw new UnexpectedCommandException(); } try {//deadline / both not specified - String by = line.substring(indexBy + 2); + by = line.substring(indexBy + 2); } catch (IndexOutOfBoundsException e) { try { - String description = line.substring(space, indexBy - 1); + description = line.substring(space, indexBy - 1); } catch (IndexOutOfBoundsException f) { System.out.println("deadline description and deadline not specified"); throw new UnexpectedCommandException(); @@ -88,18 +107,23 @@ public static void dealWithDeadline(ArrayList tasks, int index, String lin throw new UnexpectedCommandException(); } try {//deadline not specified - String description = line.substring(space, indexBy - 1); + description = line.substring(space, indexBy - 1); } catch (IndexOutOfBoundsException e) { System.out.println("deadline description not specified"); throw new UnexpectedCommandException(); } - String description = line.substring(space, indexBy - 1); - String by = line.substring(indexBy + 2); + if (!isInTxt) { + description = line.substring(space, indexBy - 1); + by = line.substring(indexBy + 3); + } else{ + description = line.substring(space, indexBy - 1); + by = line.substring(indexBy + 4, line.length() - 1); + } tasks.add(index, new Deadline(description, by)); } - public static void dealWithTodo(ArrayList tasks, int index, String line) throws UnexpectedCommandException, IOException { + public static void dealWithTodo(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { int indexSpace = line.indexOf(" "); if (indexSpace == -1) { System.out.println("todo description not specified"); @@ -125,7 +149,9 @@ private void handleEmptyInput(String line) throws EmptyLineException { } public ManageInputs(ArrayList tasks, int index, String line) throws IOException, UnexpectedCommandException { - index = fillFileContents(tasks, "TaskList.txt", index); + boolean isInTxt = false; + index = fillFileContents(tasks, "TaskList.txt", index, isInTxt); + while (!line.equals("bye")) { Boolean isValidCommand = false; Scanner input = new Scanner(System.in); @@ -155,26 +181,30 @@ public ManageInputs(ArrayList tasks, int index, String line) throws IOExce } } else if (line.equals("bye")) {//exit chat isValidCommand = true; + + + + break; } else if (inputs[0].equals("event") || inputs[0].equals("todo") || inputs[0].equals("deadline")) {//add items try { if (inputs[0].equals("event")) { isValidCommand = true; - dealWithEvent(tasks, index, line); + dealWithEvent(tasks, index, line, isInTxt); writeToFile("TaskList.txt", tasks.get(index)); System.out.println("Got it. I've added this task: "); System.out.println(tasks.get(index)); index++; } else if (inputs[0].equals("deadline")) { isValidCommand = true; - dealWithDeadline(tasks, index, line); + dealWithDeadline(tasks, index, line, isInTxt); writeToFile("TaskList.txt", tasks.get(index)); System.out.println("Got it. I've added this task: "); System.out.println(tasks.get(index)); index++; } else { isValidCommand = true; - dealWithTodo(tasks, index, line); + dealWithTodo(tasks, index, line, isInTxt); writeToFile("TaskList.txt", tasks.get(index)); System.out.println("Got it. I've added this task: "); System.out.println(tasks.get(index)); @@ -206,4 +236,4 @@ public ManageInputs(ArrayList tasks, int index, String line) throws IOExce } System.out.println("Bye. Hope to see you again soon!"); } -} +} \ No newline at end of file From 61216db1637d89d14f8311fa42c959d044c42f36 Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Sat, 2 Mar 2024 23:42:49 +0800 Subject: [PATCH 17/28] add saveToFile --- src/main/java/ManageInputs.java | 34 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/ManageInputs.java b/src/main/java/ManageInputs.java index 587f0af4c..b75dc2d2e 100644 --- a/src/main/java/ManageInputs.java +++ b/src/main/java/ManageInputs.java @@ -17,8 +17,8 @@ private static void writeToFile(String filePath, Task textToAdd) throws IOExcept } - - private static int fillFileContents(ArrayList tasks, String filePath, int index, boolean isInTxt) throws IOException, UnexpectedCommandException {//updates index +//file -> tasks + private static int fillFileContents(ArrayList tasks, String filePath, int index) throws IOException, UnexpectedCommandException {//updates index File f = new File(filePath); // create a File for the given file path Scanner s = new Scanner(f); // create a Scanner using the File as the source @@ -32,13 +32,19 @@ private static int fillFileContents(ArrayList tasks, String filePath, int } else if (sLine.contains("[T]")) { dealWithTodo(tasks, index, sLine, true); } + boolean isInTxt = false; index++; } - isInTxt = false; + return index; } - +private void saveToFile(ArrayList tasks, int index) throws IOException{ + new FileWriter("TaskList.txt", false).close(); + for (int TaskIndex = 0; TaskIndex < index; TaskIndex ++) { + writeToFile("TaskList.txt", tasks.get(TaskIndex)); + } +} public static void dealWithEvent(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { int indexTo = line.lastIndexOf("to"); @@ -77,10 +83,8 @@ public static void dealWithEvent(ArrayList tasks, int index, String line, } else { from = line.substring(indexFrom + 6, indexTo - 1); to = line.substring(indexTo + 4, line.length() - 1); - description = line.substring(5, indexFrom - 1); - } //when uncomment this, cannot add but reads file contents properly - //when commented, can add but cannot read file contents properly - //System.out.println(isInTxt); + description = line.substring(6, indexFrom - 1); + } tasks.add(index, new Event(description, from, to)); } @@ -150,7 +154,7 @@ private void handleEmptyInput(String line) throws EmptyLineException { public ManageInputs(ArrayList tasks, int index, String line) throws IOException, UnexpectedCommandException { boolean isInTxt = false; - index = fillFileContents(tasks, "TaskList.txt", index, isInTxt); + index = fillFileContents(tasks, "TaskList.txt", index); while (!line.equals("bye")) { Boolean isValidCommand = false; @@ -166,12 +170,14 @@ public ManageInputs(ArrayList tasks, int index, String line) throws IOExce tasks.get(idx - 1).markAsDone(); System.out.println("Nice! I've marked this task as done: "); System.out.println(tasks.get(idx - 1)); + saveToFile(tasks, index); } else if (inputs[0].equals("unmark")) {//unmark done isValidCommand = true; int idx = Integer.parseInt(inputs[1]); tasks.get(idx - 1).unmarkDone(); System.out.println("OK, I've marked this task as not done yet: "); System.out.println(tasks.get(idx - 1)); + saveToFile(tasks, index); } else if (line.equals("list")) {//lists tasks isValidCommand = true; System.out.println("Here are the tasks in your list: "); @@ -181,10 +187,7 @@ public ManageInputs(ArrayList tasks, int index, String line) throws IOExce } } else if (line.equals("bye")) {//exit chat isValidCommand = true; - - - - + saveToFile(tasks, index); break; } else if (inputs[0].equals("event") || inputs[0].equals("todo") || inputs[0].equals("deadline")) {//add items try { @@ -217,12 +220,15 @@ public ManageInputs(ArrayList tasks, int index, String line) throws IOExce System.out.println("Now you have " + tasks.size() + " tasks in the list."); } else if (inputs[0].equals("delete")) { isValidCommand = true; + fillFileContents(tasks, "TaskList.txt", index); int idx = Integer.parseInt(inputs[1]); System.out.println("Noted. I've removed this task: "); System.out.println(tasks.get(idx - 1)); tasks.remove(idx - 1); - System.out.println("Now you have " + tasks.size() + " tasks in the list."); index--; + System.out.println("Now you have " + index + " tasks in the list."); + saveToFile(tasks, index); + } else { try { handleEmptyInput(line); From 996ba2b9a0c58e4600300eedc050aeb3aba7e58e Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Sun, 3 Mar 2024 17:51:39 +0800 Subject: [PATCH 18/28] fix file not found error --- src/main/java/CreateFile.java | 2 +- src/main/java/Duke.java | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/CreateFile.java b/src/main/java/CreateFile.java index 32ac2b64e..424a2b3a2 100644 --- a/src/main/java/CreateFile.java +++ b/src/main/java/CreateFile.java @@ -2,7 +2,7 @@ import java.io.IOException; public class CreateFile { - public static void main(String[] args) { + public static void CreateFile(){ File f = new File("TaskList.txt"); if (!f.exists()) { try { diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 770e0ea1c..c7136f3e8 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -15,7 +15,7 @@ private static void printFileContents(String filePath) throws FileNotFoundExcept } } - public static void main(String[] args) throws UnexpectedCommandException, EmptyLineException, IOException { + public static void main(String[] args) throws UnexpectedCommandException, EmptyLineException, IOException, FileNotFoundException { ArrayList tasks = new ArrayList(); //greeting @@ -26,12 +26,25 @@ public static void main(String[] args) throws UnexpectedCommandException, EmptyL printFileContents("TaskList.txt"); } catch (FileNotFoundException e) { - File f = new File("TaskList.txt"); System.out.println("File not found"); - System.out.println("File created: " + f.getAbsolutePath()); } int index = 0;//number of items in the list String line = " "; + File f = new File("TaskList.txt"); + if (!f.exists()) { + try { + if (f.createNewFile()) { + System.out.println("File created: " + f.getAbsolutePath()); + } else { + System.out.println("File creation failed."); + } + } catch (IOException e) { + System.out.println("An error occurred."); + e.printStackTrace(); + } + } else { + System.out.println("File already exists: " + f.getAbsolutePath()); + } new ManageInputs(tasks, index, line); } From 7162ac7c59ff2c8efb7188baa13bb4c7dbe1d24f Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Thu, 7 Mar 2024 03:04:29 +0800 Subject: [PATCH 19/28] use more oop --- src/main/java/ManageInputs.java | 245 -------------------------------- src/main/java/Parser.java | 105 ++++++++++++++ src/main/java/Storage.java | 2 + src/main/java/TaskList.java | 2 + src/main/java/Ui.java | 2 + 5 files changed, 111 insertions(+), 245 deletions(-) delete mode 100644 src/main/java/ManageInputs.java create mode 100644 src/main/java/Parser.java create mode 100644 src/main/java/Storage.java create mode 100644 src/main/java/TaskList.java create mode 100644 src/main/java/Ui.java diff --git a/src/main/java/ManageInputs.java b/src/main/java/ManageInputs.java deleted file mode 100644 index b75dc2d2e..000000000 --- a/src/main/java/ManageInputs.java +++ /dev/null @@ -1,245 +0,0 @@ -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Scanner; - -public class ManageInputs { - protected static String from; - protected static String to; - public static String description; - protected static String by; - - private static void writeToFile(String filePath, Task textToAdd) throws IOException { - FileWriter fw = new FileWriter(filePath, true); - fw.write(textToAdd + "\n"); - fw.close(); - } - - -//file -> tasks - private static int fillFileContents(ArrayList tasks, String filePath, int index) throws IOException, UnexpectedCommandException {//updates index - File f = new File(filePath); // create a File for the given file path - Scanner s = new Scanner(f); // create a Scanner using the File as the source - - while (s.hasNext()) { - - String sLine = s.nextLine(); - if (sLine.contains("[E]")) { - dealWithEvent(tasks, index, sLine, true); - } else if (sLine.contains("[D]")) { - dealWithDeadline(tasks, index, sLine, true); - } else if (sLine.contains("[T]")) { - dealWithTodo(tasks, index, sLine, true); - } - boolean isInTxt = false; - index++; - } - - return index; - } - -private void saveToFile(ArrayList tasks, int index) throws IOException{ - new FileWriter("TaskList.txt", false).close(); - for (int TaskIndex = 0; TaskIndex < index; TaskIndex ++) { - writeToFile("TaskList.txt", tasks.get(TaskIndex)); - } -} - - public static void dealWithEvent(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { - int indexTo = line.lastIndexOf("to"); - int indexFrom = line.indexOf("from"); - String from; - String to; - String description; - - if ((indexTo == -1) || (indexFrom == -1)) { //invalid format - System.out.println("Invalid format! Enter event in the format: event (description) from (start) to (end)"); - throw new UnexpectedCommandException(); - } - try {//timeline not specified/ both not specified - from = line.substring(indexFrom + 5, indexTo - 1); - to = line.substring(indexTo + 2); - } catch (IndexOutOfBoundsException e) { - try { - description = line.substring(5, indexFrom - 1); - } catch (IndexOutOfBoundsException f) { - System.out.println("event description and timeline not specified"); - throw new UnexpectedCommandException(); - } - System.out.println("event timeline not specified"); - throw new UnexpectedCommandException(); - } - try {//description not specified - description = line.substring(5, indexFrom - 1); - } catch (IndexOutOfBoundsException e) { - System.out.println("event description not specified"); - throw new UnexpectedCommandException(); - } - if(!isInTxt) { - from = line.substring(indexFrom + 5, indexTo - 1); - to = line.substring(indexTo + 3); - description = line.substring(5, indexFrom - 1); - } else { - from = line.substring(indexFrom + 6, indexTo - 1); - to = line.substring(indexTo + 4, line.length() - 1); - description = line.substring(6, indexFrom - 1); - } - - tasks.add(index, new Event(description, from, to)); - } - - public static void dealWithDeadline(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { - int indexBy = line.indexOf("by"); - int space = line.indexOf(" "); - String by; - String description; - if (indexBy == -1) {//invalid format - System.out.println("Invalid format! Enter deadline in the format: deadline (description) by (deadline)"); - throw new UnexpectedCommandException(); - } - try {//deadline / both not specified - by = line.substring(indexBy + 2); - } catch (IndexOutOfBoundsException e) { - try { - description = line.substring(space, indexBy - 1); - } catch (IndexOutOfBoundsException f) { - System.out.println("deadline description and deadline not specified"); - throw new UnexpectedCommandException(); - } - System.out.println("deadline not specified"); - throw new UnexpectedCommandException(); - } - try {//deadline not specified - description = line.substring(space, indexBy - 1); - } catch (IndexOutOfBoundsException e) { - System.out.println("deadline description not specified"); - throw new UnexpectedCommandException(); - } - if (!isInTxt) { - description = line.substring(space, indexBy - 1); - by = line.substring(indexBy + 3); - } else{ - description = line.substring(space, indexBy - 1); - by = line.substring(indexBy + 4, line.length() - 1); - } - - tasks.add(index, new Deadline(description, by)); - } - - public static void dealWithTodo(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { - int indexSpace = line.indexOf(" "); - if (indexSpace == -1) { - System.out.println("todo description not specified"); - throw new UnexpectedCommandException(); - } - - String description = line.substring(indexSpace); - - tasks.add(index, new Todo(description)); - - } - - private void handleUnexpectedCommand(boolean isValidCommand) throws UnexpectedCommandException { - if (!isValidCommand) { - throw new UnexpectedCommandException(); - } - } - - private void handleEmptyInput(String line) throws EmptyLineException { - if (line.isEmpty()) { - throw new EmptyLineException(); - } - } - - public ManageInputs(ArrayList tasks, int index, String line) throws IOException, UnexpectedCommandException { - boolean isInTxt = false; - index = fillFileContents(tasks, "TaskList.txt", index); - - while (!line.equals("bye")) { - Boolean isValidCommand = false; - Scanner input = new Scanner(System.in); - line = input.nextLine(); - - Task t = new Task(line); - String[] inputs = line.split(" "); - - if (inputs[0].equals("mark")) {//mark as done - isValidCommand = true; - int idx = Integer.parseInt(inputs[1]); - tasks.get(idx - 1).markAsDone(); - System.out.println("Nice! I've marked this task as done: "); - System.out.println(tasks.get(idx - 1)); - saveToFile(tasks, index); - } else if (inputs[0].equals("unmark")) {//unmark done - isValidCommand = true; - int idx = Integer.parseInt(inputs[1]); - tasks.get(idx - 1).unmarkDone(); - System.out.println("OK, I've marked this task as not done yet: "); - System.out.println(tasks.get(idx - 1)); - saveToFile(tasks, index); - } else if (line.equals("list")) {//lists tasks - isValidCommand = true; - System.out.println("Here are the tasks in your list: "); - - for (int i = 0; i < index; i++) { - System.out.println((i + 1) + ". " + tasks.get(i)); - } - } else if (line.equals("bye")) {//exit chat - isValidCommand = true; - saveToFile(tasks, index); - break; - } else if (inputs[0].equals("event") || inputs[0].equals("todo") || inputs[0].equals("deadline")) {//add items - try { - if (inputs[0].equals("event")) { - isValidCommand = true; - dealWithEvent(tasks, index, line, isInTxt); - writeToFile("TaskList.txt", tasks.get(index)); - System.out.println("Got it. I've added this task: "); - System.out.println(tasks.get(index)); - index++; - } else if (inputs[0].equals("deadline")) { - isValidCommand = true; - dealWithDeadline(tasks, index, line, isInTxt); - writeToFile("TaskList.txt", tasks.get(index)); - System.out.println("Got it. I've added this task: "); - System.out.println(tasks.get(index)); - index++; - } else { - isValidCommand = true; - dealWithTodo(tasks, index, line, isInTxt); - writeToFile("TaskList.txt", tasks.get(index)); - System.out.println("Got it. I've added this task: "); - System.out.println(tasks.get(index)); - index++; - } - } catch (UnexpectedCommandException e) { - } catch (IOException e) { - throw new RuntimeException(e); - } - System.out.println("Now you have " + tasks.size() + " tasks in the list."); - } else if (inputs[0].equals("delete")) { - isValidCommand = true; - fillFileContents(tasks, "TaskList.txt", index); - int idx = Integer.parseInt(inputs[1]); - System.out.println("Noted. I've removed this task: "); - System.out.println(tasks.get(idx - 1)); - tasks.remove(idx - 1); - index--; - System.out.println("Now you have " + index + " tasks in the list."); - saveToFile(tasks, index); - - } else { - try { - handleEmptyInput(line); - handleUnexpectedCommand(isValidCommand); - } catch (UnexpectedCommandException e) { - System.out.println("please enter a valid command"); - } catch (EmptyLineException e) { - System.out.println("enter a task"); - } - } - } - System.out.println("Bye. Hope to see you again soon!"); - } -} \ No newline at end of file diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 000000000..3c68fe708 --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,105 @@ +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +public class ManageInputs { + protected static String from; + protected static String to; + public static String description; + protected static String by; + private static Ui ui; + private static Storage storage; + + private void dealWithMark(String[] inputs, ArrayList tasks, int index, boolean isValidCommand) throws IOException { + isValidCommand = true; + int idx = Integer.parseInt(inputs[1]); + tasks.get(idx - 1).markAsDone(); + System.out.println("Nice! I've marked this task as done: "); + System.out.println(tasks.get(idx - 1)); + storage.saveToFile(tasks, index); + } + + private void dealWithUnmark(String[] inputs, ArrayList tasks, int index, boolean isValidCommand) throws IOException { + isValidCommand = true; + int idx = Integer.parseInt(inputs[1]); + tasks.get(idx - 1).unmarkDone(); + System.out.println("OK, I've marked this task as not done yet: "); + System.out.println(tasks.get(idx - 1)); + storage.saveToFile(tasks, index); + } + + private void listTasks(ArrayList tasks, int index, boolean isValidCommand){ + isValidCommand = true; + System.out.println("Here are the tasks in your list: "); + + for (int i = 0; i < index; i++) { + System.out.println((i + 1) + ". " + tasks.get(i)); + } + } + + private void deleteTask(ArrayList tasks, String[] inputs, int index, boolean isValidCommand) throws UnexpectedCommandException, IOException { + isValidCommand = true; + Storage.fillFileContents(tasks, "TaskList.txt", index); + TaskList.dealWithDelete(inputs[1], tasks); + index--; + System.out.println("Now you have " + index + " tasks in the list."); + storage.saveToFile(tasks, index); + } + + private void handleUnexpectedCommand(boolean isValidCommand) throws UnexpectedCommandException { + if (!isValidCommand) { + throw new UnexpectedCommandException(); + } + } + + private void handleEmptyInput(String line) throws EmptyLineException { + if (line.isEmpty()) { + throw new EmptyLineException(); + } + } + + public ManageInputs(ArrayList tasks, int index, String line) throws IOException, UnexpectedCommandException { + boolean isInTxt = false; + index = Storage.fillFileContents(tasks, "TaskList.txt", index); + ui = new Ui(); + + while (!line.equals("bye")) { + ui.readCommand(); + Boolean isValidCommand = false; + Scanner input = new Scanner(System.in); + line = input.nextLine(); + + Task t = new Task(line); + String[] inputs = line.split(" "); + + if (inputs[0].equals("mark")) {//mark as done + dealWithMark(inputs, tasks, index, isValidCommand); + } else if (inputs[0].equals("unmark")) {//unmark done + dealWithUnmark(inputs, tasks, index, isValidCommand); + } else if (line.equals("list")) {//lists tasks + listTasks(tasks, index, isValidCommand); + } else if (line.equals("bye")) {//exit chat + isValidCommand = true; + storage.saveToFile(tasks, index); + break; + } else if (inputs[0].equals("event") || inputs[0].equals("todo") || inputs[0].equals("deadline")) {//add items + TaskList.addTasks(tasks, inputs, index, line, isInTxt, isValidCommand); + } else if (inputs[0].equals("delete")) { + deleteTask(tasks, inputs, index, isValidCommand); + + } else { + try { + handleEmptyInput(line); + handleUnexpectedCommand(isValidCommand); + } catch (UnexpectedCommandException e) { + ui.errorMessage("Please enter a valid command"); + } catch (EmptyLineException e) { + ui.errorMessage("No input detected. Please enter a task"); + } + } + } + ui.sayBye(); + } +} \ No newline at end of file diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 000000000..ee840ea8b --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class Storage { +} diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 000000000..685983890 --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class TaskList { +} diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 000000000..b6aacac25 --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,2 @@ +package PACKAGE_NAME;public class Ui { +} From 7a5826c8b085f7bb8b84963bc82b63e8613a9ccd Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Thu, 7 Mar 2024 03:28:11 +0800 Subject: [PATCH 20/28] fix loading file errors --- src/main/java/Duke.java | 9 ++- src/main/java/Parser.java | 84 ++++++++++++++++------ src/main/java/Storage.java | 43 ++++++++++- src/main/java/TaskList.java | 138 +++++++++++++++++++++++++++++++++++- src/main/java/Ui.java | 20 +++++- 5 files changed, 265 insertions(+), 29 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index c7136f3e8..220fbd781 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -15,12 +15,11 @@ private static void printFileContents(String filePath) throws FileNotFoundExcept } } + private static Ui ui; public static void main(String[] args) throws UnexpectedCommandException, EmptyLineException, IOException, FileNotFoundException { ArrayList tasks = new ArrayList(); - - //greeting - System.out.println("Hello! I'm Apple"); - System.out.println("What can I do for you?"); + ui = new Ui(); + ui.sayHi(); try { System.out.println("Here are the items in your task list: "); printFileContents("TaskList.txt"); @@ -46,6 +45,6 @@ public static void main(String[] args) throws UnexpectedCommandException, EmptyL System.out.println("File already exists: " + f.getAbsolutePath()); } - new ManageInputs(tasks, index, line); + new Parser(tasks, index, line); } } diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 3c68fe708..760eb4bcd 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,33 +1,41 @@ -import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; -public class ManageInputs { +public class Parser { protected static String from; protected static String to; public static String description; protected static String by; private static Ui ui; private static Storage storage; + private static TaskList tasklist; private void dealWithMark(String[] inputs, ArrayList tasks, int index, boolean isValidCommand) throws IOException { isValidCommand = true; - int idx = Integer.parseInt(inputs[1]); - tasks.get(idx - 1).markAsDone(); - System.out.println("Nice! I've marked this task as done: "); - System.out.println(tasks.get(idx - 1)); - storage.saveToFile(tasks, index); + try { + int idx = Integer.parseInt(inputs[1]); + tasks.get(idx - 1).markAsDone(); + System.out.println("Nice! I've marked this task as done: "); + System.out.println(tasks.get(idx - 1)); + storage.saveToFile(tasks, index); + } catch (IndexOutOfBoundsException e){ + ui.errorMessage("did not indicate which task to mark"); + } + } private void dealWithUnmark(String[] inputs, ArrayList tasks, int index, boolean isValidCommand) throws IOException { isValidCommand = true; - int idx = Integer.parseInt(inputs[1]); - tasks.get(idx - 1).unmarkDone(); - System.out.println("OK, I've marked this task as not done yet: "); - System.out.println(tasks.get(idx - 1)); - storage.saveToFile(tasks, index); + try { + int idx = Integer.parseInt(inputs[1]); + tasks.get(idx - 1).unmarkDone(); + System.out.println("OK, I've marked this task as not done yet: "); + System.out.println(tasks.get(idx - 1)); + storage.saveToFile(tasks, index); + } catch (IndexOutOfBoundsException e){ + ui.errorMessage("did not indicate which task to unmark"); + } } private void listTasks(ArrayList tasks, int index, boolean isValidCommand){ @@ -39,15 +47,17 @@ private void listTasks(ArrayList tasks, int index, boolean isValidCommand) } } - private void deleteTask(ArrayList tasks, String[] inputs, int index, boolean isValidCommand) throws UnexpectedCommandException, IOException { + private int deleteTask(ArrayList tasks, String[] inputs, int index, boolean isValidCommand) throws UnexpectedCommandException, IOException { isValidCommand = true; Storage.fillFileContents(tasks, "TaskList.txt", index); - TaskList.dealWithDelete(inputs[1], tasks); + TaskList.dealWithDelete(inputs, inputs[1], tasks); index--; System.out.println("Now you have " + index + " tasks in the list."); storage.saveToFile(tasks, index); + return index; } + private void handleUnexpectedCommand(boolean isValidCommand) throws UnexpectedCommandException { if (!isValidCommand) { throw new UnexpectedCommandException(); @@ -60,9 +70,10 @@ private void handleEmptyInput(String line) throws EmptyLineException { } } - public ManageInputs(ArrayList tasks, int index, String line) throws IOException, UnexpectedCommandException { - boolean isInTxt = false; + public Parser(ArrayList tasks, int index, String line) throws IOException, IndexOutOfBoundsException, UnexpectedCommandException { + boolean isInTxt = true; index = Storage.fillFileContents(tasks, "TaskList.txt", index); + isInTxt = false; ui = new Ui(); while (!line.equals("bye")) { @@ -76,19 +87,50 @@ public ManageInputs(ArrayList tasks, int index, String line) throws IOExce if (inputs[0].equals("mark")) {//mark as done dealWithMark(inputs, tasks, index, isValidCommand); + Storage.saveToFile(tasks, index); } else if (inputs[0].equals("unmark")) {//unmark done dealWithUnmark(inputs, tasks, index, isValidCommand); + Storage.saveToFile(tasks, index); } else if (line.equals("list")) {//lists tasks listTasks(tasks, index, isValidCommand); } else if (line.equals("bye")) {//exit chat isValidCommand = true; - storage.saveToFile(tasks, index); + Storage.saveToFile(tasks, index); break; } else if (inputs[0].equals("event") || inputs[0].equals("todo") || inputs[0].equals("deadline")) {//add items - TaskList.addTasks(tasks, inputs, index, line, isInTxt, isValidCommand); - } else if (inputs[0].equals("delete")) { - deleteTask(tasks, inputs, index, isValidCommand); + try { + if (inputs[0].equals("event")) { + isValidCommand = true; + TaskList.dealWithEvent(tasks, index, line, isInTxt); + Storage.writeToFile("TaskList.txt", tasks.get(index)); + System.out.println("Got it. I've added this task: "); + System.out.println(tasks.get(index)); + index++; + } else if (inputs[0].equals("deadline")) { + isValidCommand = true; + TaskList.dealWithDeadline(tasks, index, line, isInTxt); + Storage.writeToFile("TaskList.txt", tasks.get(index)); + System.out.println("Got it. I've added this task: "); + System.out.println(tasks.get(index)); + index++; + } else { + isValidCommand = true; + TaskList.dealWithTodo(tasks, index, line, isInTxt); + Storage.writeToFile("TaskList.txt", tasks.get(index)); + System.out.println("Got it. I've added this task: "); + System.out.println(tasks.get(index)); + index++; + } + } catch (IOException | UnexpectedCommandException | IndexOutOfBoundsException e) { + } + System.out.println("Now you have " + index + " tasks in the list."); + } else if (inputs[0].equals("delete")) { + try { + index = deleteTask(tasks, inputs, index, isValidCommand); + } catch (ArrayIndexOutOfBoundsException e){ + System.out.println("please secify which task you want to delete"); + } } else { try { handleEmptyInput(line); diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index ee840ea8b..b90b61027 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -1,2 +1,43 @@ -package PACKAGE_NAME;public class Storage { +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 int fillFileContents(ArrayList tasks, String filePath, int index) throws IOException, UnexpectedCommandException {//updates index + File f = new File(filePath); // create a File for the given file path + Scanner s = new Scanner(f); // create a Scanner using the File as the source + + while (s.hasNext()) { + + String sLine = s.nextLine(); + + if (sLine.contains("[E]")) { + TaskList.dealWithEvent(tasks, index, sLine, true); + } else if (sLine.contains("[D]")) { + TaskList.dealWithDeadline(tasks, index, sLine, true); + } else if (sLine.contains("[T]")) { + TaskList.dealWithTodo(tasks, index, sLine, true); + } + + index++; + } + boolean isInTxt = false; + //System.out.println("filling contents"); + return index; + } + + protected static void saveToFile(ArrayList tasks, int index) throws IOException{ + new FileWriter("TaskList.txt", false).close(); + for (int TaskIndex = 0; TaskIndex < index; TaskIndex ++) { + writeToFile("TaskList.txt", tasks.get(TaskIndex)); + } + } + + static void writeToFile(String filePath, Task textToAdd) throws IOException{ + FileWriter fw = new FileWriter(filePath, true); + fw.write(textToAdd + "\n"); + fw.close(); + } } diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 685983890..7eea9c8ca 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -1,2 +1,138 @@ -package PACKAGE_NAME;public class TaskList { +import java.io.IOException; +import java.util.ArrayList; + +public class TaskList { + protected static Ui ui; + protected static ArrayList tasks; + public TaskList(){ + this.tasks = tasks; + } + + public static void dealWithEvent(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { + int indexTo = line.lastIndexOf("to"); + int indexFrom = line.indexOf("from"); + String from; + String to; + String description; + + if ((indexTo == -1) || (indexFrom == -1)) { //invalid format + ui.errorMessage("Invalid format! Enter event in the format: event (description) from (start) to (end)"); + throw new UnexpectedCommandException(); + } + try {//timeline not specified/ both not specified + from = line.substring(indexFrom + 5, indexTo - 1); + to = line.substring(indexTo + 3); + } catch (IndexOutOfBoundsException e) { + try { + description = line.substring(6, indexFrom - 1); + } catch (IndexOutOfBoundsException f) { + ui.errorMessage("event description and timeline not specified"); + throw new UnexpectedCommandException(); + } + ui.errorMessage("event timeline not specified"); + throw new UnexpectedCommandException(); + } + try {//description not specified + description = line.substring(6, indexFrom - 1); + } catch (IndexOutOfBoundsException e) { + ui.errorMessage("event description not specified"); + throw new UnexpectedCommandException(); + } + if(!isInTxt) { + from = line.substring(indexFrom + 5, indexTo - 1); + to = line.substring(indexTo + 3); + description = line.substring(5, indexFrom - 1); + } else { + + from = line.substring(indexFrom + 6, indexTo - 1); + to = line.substring(indexTo + 4, line.length() - 1); + description = line.substring(6, indexFrom - 1); + + + } + tasks.add(index, new Event(description, from, to)); + if (isInTxt){ + char[] charArray = line.toCharArray(); + if (charArray[4] == '1'){ + tasks.get(index).markAsDone(); + } else{ + tasks.get(index).unmarkDone(); + } + } + } + + public static void dealWithDeadline(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { + int indexBy = line.indexOf("by"); + int space = line.indexOf(" "); + String by; + String description; + if (indexBy == -1) {//invalid format + ui.errorMessage("Invalid format! Enter deadline in the format: deadline (description) by (deadline)"); + throw new UnexpectedCommandException(); + } + try {//deadline / both not specified + by = line.substring(indexBy + 3); + } catch (IndexOutOfBoundsException e) { + try { + description = line.substring(space + 1, indexBy - 1); + } catch (IndexOutOfBoundsException f) { + ui.errorMessage("deadline description and deadline not specified"); + throw new UnexpectedCommandException(); + } + ui.errorMessage("deadline not specified"); + throw new UnexpectedCommandException(); + } + try {//deadline not specified + description = line.substring(space + 1, indexBy - 1); + } catch (IndexOutOfBoundsException e) { + ui.errorMessage("deadline description not specified"); + throw new UnexpectedCommandException(); + } + if (!isInTxt) { + description = line.substring(space, indexBy - 1); + by = line.substring(indexBy + 3); + } else{ + description = line.substring(space, indexBy - 1); + by = line.substring(indexBy + 4, line.length() - 1); + } + + tasks.add(index, new Deadline(description, by)); + if (isInTxt){ + char[] charArray = line.toCharArray(); + if (charArray[4] == '1'){ + tasks.get(index).markAsDone(); + } else{ + tasks.get(index).unmarkDone(); + } + } + } + + public static void dealWithTodo(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { + int indexSpace = line.indexOf(" "); + if (indexSpace == -1) { + ui.errorMessage("todo description not specified"); + throw new UnexpectedCommandException(); + } + + String description = line.substring(indexSpace); + tasks.add(index, new Todo(description)); + if (isInTxt){ + char[] charArray = line.toCharArray(); + if (charArray[4] == '1'){ + tasks.get(index).markAsDone(); + } else{ + tasks.get(index).unmarkDone(); + } + } + + } + + public static void dealWithDelete (String[] inputs, String ListIndex, ArrayList tasks){ + if (inputs[0].equals("delete")) { + int idx = Integer.parseInt(ListIndex); + System.out.println("Noted. I've removed this task: "); + System.out.println(tasks.get(idx - 1)); + tasks.remove(idx - 1); + } + } } diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index b6aacac25..bf962a771 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,2 +1,20 @@ -package PACKAGE_NAME;public class Ui { +import java.io.FileNotFoundException; + +public class Ui { + public void sayHi(){ + System.out.println("Hello! I'm Apple"); + System.out.println("What can I do for you?"); + } + + public void readCommand(){ + System.out.print("Enter your command: "); + } + + public static void errorMessage(String message){ + System.out.println(message); + } + + public void sayBye(){ + System.out.println("Bye. Hope to see you again soon!"); + } } From 4a60dbe4472dd6a8fd308309e092fcabe5341c90 Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Thu, 7 Mar 2024 13:21:07 +0800 Subject: [PATCH 21/28] add find --- src/main/java/Parser.java | 23 +++++++++++++++++++++++ src/main/java/Storage.java | 1 - 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 760eb4bcd..55b1e5e00 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -11,6 +11,8 @@ public class Parser { private static Storage storage; private static TaskList tasklist; + public String findInput; + private void dealWithMark(String[] inputs, ArrayList tasks, int index, boolean isValidCommand) throws IOException { isValidCommand = true; try { @@ -57,6 +59,21 @@ private int deleteTask(ArrayList tasks, String[] inputs, int index, boolea return index; } + private void dealWithFind(String findInput, ArrayList tasks, int index){ + ArrayList matchingTasks = new ArrayList(); + int matchingTasksIndex = 1; + System.out.println("Here are the matching tasks in your list: "); + for (int i = 0; i < index; i ++){ + String xline = tasks.get(i).toString(); + if (xline.contains(findInput)){ + System.out.print(matchingTasksIndex + ". "); + matchingTasks.add(tasks.get(i)); + System.out.println(matchingTasks.get(matchingTasksIndex - 1)); + matchingTasksIndex ++; + } + } + } + private void handleUnexpectedCommand(boolean isValidCommand) throws UnexpectedCommandException { if (!isValidCommand) { @@ -131,6 +148,12 @@ public Parser(ArrayList tasks, int index, String line) throws IOException, } catch (ArrayIndexOutOfBoundsException e){ System.out.println("please secify which task you want to delete"); } + } else if (inputs[0].equals("find")){ + try { + dealWithFind(inputs[1], tasks, index); + } catch (ArrayIndexOutOfBoundsException e){ + System.out.println("please state what you would like to find"); + } } else { try { handleEmptyInput(line); diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index b90b61027..1545266a6 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -24,7 +24,6 @@ public static int fillFileContents(ArrayList tasks, String filePath, int i index++; } boolean isInTxt = false; - //System.out.println("filling contents"); return index; } From 2152ef7ccae13e8bf00288427ff53ee8c846b8bf Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Thu, 7 Mar 2024 21:39:37 +0800 Subject: [PATCH 22/28] add javadoc --- src/main/java/CreateFile.java | 3 ++ src/main/java/Deadline.java | 3 ++ src/main/java/Duke.java | 5 ++++ src/main/java/Event.java | 3 ++ src/main/java/Parser.java | 52 ++++++++++++++++++++++++++++++++++- src/main/java/Storage.java | 24 ++++++++++++++++ src/main/java/Task.java | 4 +++ src/main/java/TaskList.java | 36 ++++++++++++++++++++++++ src/main/java/Todo.java | 3 ++ src/main/java/Ui.java | 4 ++- 10 files changed, 135 insertions(+), 2 deletions(-) diff --git a/src/main/java/CreateFile.java b/src/main/java/CreateFile.java index 424a2b3a2..b977750c6 100644 --- a/src/main/java/CreateFile.java +++ b/src/main/java/CreateFile.java @@ -1,6 +1,9 @@ import java.io.File; import java.io.IOException; +/** + * creates local TaskList.txt file on the local machine + */ public class CreateFile { public static void CreateFile(){ File f = new File("TaskList.txt"); diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index bcd049672..941068471 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,3 +1,6 @@ +/** + * child class of Task to handle deadlines + */ public class Deadline extends Task{ protected String by; diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 220fbd781..8cebfc61e 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -7,6 +7,11 @@ public class Duke { + /** + * lists tasks saved in the local TaskList.txt file + * @param filePath the path to the local TaskList.txt file + * @throws FileNotFoundException exception when local TaskList.txt file does not exist + */ private static void printFileContents(String filePath) throws FileNotFoundException { File f = new File(filePath); // create a File for the given file path Scanner s = new Scanner(f); // create a Scanner using the File as the source diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 0c9973810..d61530a83 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,3 +1,6 @@ +/** + * child class of Task to handle events + */ public class Event extends Task{ protected String from; protected String to; diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 55b1e5e00..c3465ff7a 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -2,6 +2,9 @@ import java.util.ArrayList; import java.util.Scanner; +/** + * deals with making sense of the user command + */ public class Parser { protected static String from; protected static String to; @@ -13,6 +16,14 @@ public class Parser { public String findInput; + /** + * marks task as done + * @param inputs the array of words the user input + * @param tasks the array of tasks + * @param index the number of tasks in the array of tasks + * @param isValidCommand boolean is true if the command from the user is a valid action + * @throws IOException exception when local TaskList.txt file does not exist + */ private void dealWithMark(String[] inputs, ArrayList tasks, int index, boolean isValidCommand) throws IOException { isValidCommand = true; try { @@ -27,6 +38,14 @@ private void dealWithMark(String[] inputs, ArrayList tasks, int index, boo } + /** + * marks task as undone + * @param inputs the array of words input by the user + * @param tasks the array of tasks + * @param index the number of tasks in the array of tasks + * @param isValidCommand boolean is true if the command from the user is a valid action + * @throws IOException exception when local TaskList.txt file does not exist + */ private void dealWithUnmark(String[] inputs, ArrayList tasks, int index, boolean isValidCommand) throws IOException { isValidCommand = true; try { @@ -40,6 +59,12 @@ private void dealWithUnmark(String[] inputs, ArrayList tasks, int index, b } } + /** + * lists tasks + * @param tasks the array of tasks + * @param index the number of tasks in the array of tasks + * @param isValidCommand boolean is true if the command from the user is a valid action + */ private void listTasks(ArrayList tasks, int index, boolean isValidCommand){ isValidCommand = true; System.out.println("Here are the tasks in your list: "); @@ -49,6 +74,16 @@ private void listTasks(ArrayList tasks, int index, boolean isValidCommand) } } + /** + * deletes task + * @param tasks the array of tasks + * @param inputs the array of words input by the user + * @param index the number of tasks in the array of tasks + * @param isValidCommand boolean is true if the command from the user is a valid action + * @return the number of tasks in the array of tasks after deletion + * @throws UnexpectedCommandException exception when the format or details of the tasks are not followed and provided respectively + * @throws IOException exception when local TaskList.txt file does not exist + */ private int deleteTask(ArrayList tasks, String[] inputs, int index, boolean isValidCommand) throws UnexpectedCommandException, IOException { isValidCommand = true; Storage.fillFileContents(tasks, "TaskList.txt", index); @@ -59,6 +94,12 @@ private int deleteTask(ArrayList tasks, String[] inputs, int index, boolea return index; } + /** + * filters tasks with the keyword input by the user + * @param findInput the keyword the user is looking for + * @param tasks the array of tasks + * @param index the number of tasks in the array of tasks + */ private void dealWithFind(String findInput, ArrayList tasks, int index){ ArrayList matchingTasks = new ArrayList(); int matchingTasksIndex = 1; @@ -87,6 +128,15 @@ private void handleEmptyInput(String line) throws EmptyLineException { } } + /** + * handles the different commands input by the user + * @param tasks the array of tasks + * @param index the number of tasks in the array of tasks + * @param line the user input + * @throws IOException exception when local TaskList.txt file does not exist + * @throws IndexOutOfBoundsException exception when there is missing required details in the input + * @throws UnexpectedCommandException exception when the format or details of the tasks are not followed and provided respectively + */ public Parser(ArrayList tasks, int index, String line) throws IOException, IndexOutOfBoundsException, UnexpectedCommandException { boolean isInTxt = true; index = Storage.fillFileContents(tasks, "TaskList.txt", index); @@ -146,7 +196,7 @@ public Parser(ArrayList tasks, int index, String line) throws IOException, try { index = deleteTask(tasks, inputs, index, isValidCommand); } catch (ArrayIndexOutOfBoundsException e){ - System.out.println("please secify which task you want to delete"); + System.out.println("please specify which task you want to delete"); } } else if (inputs[0].equals("find")){ try { diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 1545266a6..6897d87ae 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -4,7 +4,19 @@ import java.util.ArrayList; import java.util.Scanner; +/** + * deals with loading tasks from the file and saving tasks in the file + */ public class Storage { + /** + * loads ArrayList tasks with tasks saved on TaskList.txt + * @param tasks contains the list of tasks + * @param filePath the path to TaskList.txt saved on the local machine + * @param index the number of tasks saved in TaskList.txt + * @return index the number of tasks saved in TaskList.txt + * @throws IOException exception when local TaskList.txt file does not exist + * @throws UnexpectedCommandException exception when the format or details of the tasks are not followed and provided respectively + */ public static int fillFileContents(ArrayList tasks, String filePath, int index) throws IOException, UnexpectedCommandException {//updates index File f = new File(filePath); // create a File for the given file path Scanner s = new Scanner(f); // create a Scanner using the File as the source @@ -27,6 +39,12 @@ public static int fillFileContents(ArrayList tasks, String filePath, int i return index; } + /** + * saves the updated tasks list onto TaskList.txt in the local machine + * @param tasks the array of tasks + * @param index the nymber of tasks in array of tasks + * @throws IOException exception when local TaskList.txt file does not exist + */ protected static void saveToFile(ArrayList tasks, int index) throws IOException{ new FileWriter("TaskList.txt", false).close(); for (int TaskIndex = 0; TaskIndex < index; TaskIndex ++) { @@ -34,6 +52,12 @@ protected static void saveToFile(ArrayList tasks, int index) throws IOExce } } + /** + * adds additional tasks into TaskList.txt + * @param filePath the path to TaskList.txt saved on the local machine + * @param textToAdd the new task to add + * @throws IOException exception when local TaskList.txt file does not exist + */ static void writeToFile(String filePath, Task textToAdd) throws IOException{ FileWriter fw = new FileWriter(filePath, true); fw.write(textToAdd + "\n"); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 43f4b8705..11b9b77da 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,3 +1,7 @@ +/** + * variables and functions that children classes of tasks inherit + * children classes in this chatbot include event, deadline and todo + */ public class Task { protected String description; protected boolean isDone; diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 7eea9c8ca..45ffe4f05 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -1,6 +1,9 @@ import java.io.IOException; import java.util.ArrayList; +/** + * contains the task list and operations to add or delete tasks + */ public class TaskList { protected static Ui ui; protected static ArrayList tasks; @@ -8,6 +11,15 @@ public TaskList(){ this.tasks = tasks; } + /** + * adds event to array of tasks + * @param tasks the array of tasks + * @param index the number of tasks in the array of tasks + * @param line the input string from the user + * @param isInTxt true if ArrayList tasks is being loaded from TaskList.txt + * @throws UnexpectedCommandException exception when the format or details of the tasks are not followed and provided respectively + * @throws IOException exception when local TaskList.txt file does not exist + */ public static void dealWithEvent(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { int indexTo = line.lastIndexOf("to"); int indexFrom = line.indexOf("from"); @@ -61,6 +73,15 @@ public static void dealWithEvent(ArrayList tasks, int index, String line, } } + /** + * adds deadline to array of tasks + * @param tasks the array of tasks + * @param index the number of tasks in the array of tasks + * @param line the input string from the user + * @param isInTxt true if ArrayList tasks is being loaded from TaskList.txt + * @throws UnexpectedCommandException exception when the format or details of the tasks are not followed and provided respectively + * @throws IOException exception when local TaskList.txt file does not exist + */ public static void dealWithDeadline(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { int indexBy = line.indexOf("by"); int space = line.indexOf(" "); @@ -107,6 +128,15 @@ public static void dealWithDeadline(ArrayList tasks, int index, String lin } } + /** + * adds todo to array of tasks + * @param tasks the array of tasks + * @param index the number of tasks in the array of tasks + * @param line the input string from the user + * @param isInTxt true if ArrayList tasks is being loaded from TaskList.txt + * @throws UnexpectedCommandException exception when the format or details of the tasks are not followed and provided respectively + * @throws IOException exception when local TaskList.txt file does not exist + */ public static void dealWithTodo(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { int indexSpace = line.indexOf(" "); if (indexSpace == -1) { @@ -127,6 +157,12 @@ public static void dealWithTodo(ArrayList tasks, int index, String line, b } + /** + * deletes item from array of tasks + * @param inputs the array of words input by the user + * @param ListIndex the string containing the task number to delete + * @param tasks the array of tasks + */ public static void dealWithDelete (String[] inputs, String ListIndex, ArrayList tasks){ if (inputs[0].equals("delete")) { int idx = Integer.parseInt(ListIndex); diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 3e9d6ee7a..d50a314bc 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -1,3 +1,6 @@ +/** + * child class of Task to handle todos + */ public class Todo extends Task{ public Todo(String description){ diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index bf962a771..4788dddc8 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,4 +1,6 @@ -import java.io.FileNotFoundException; +/** + * deals with interactions with the user + */ public class Ui { public void sayHi(){ From 67523069e7e900a480f85ee888d4182cbdee5c0a Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Fri, 8 Mar 2024 02:28:14 +0800 Subject: [PATCH 23/28] Add user guide --- README.md | 159 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 135 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 8715d4d91..75e6cf898 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,135 @@ -# 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.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: - ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +#User Guide for chatbot "Apple" + +Chatbot Apple is an app to manage tasks, optimised for use through a Command Line Interface (CLI). + +##Quick Start +1. Ensure Java 11 or above is installed in your computer +2. Download `ip.jar` from [here](https://github.com/hongyijie06/ip/releases/tag/A-Jar) +3. Open a command terminal, `cd` into the folder with the jar file and use the `java -jar ip.jar` command to run the application. + +A CLI similar to the picture below should appear in a few seconds. Note how the app returns the path to which the list of tasks is saved on the local computer. + +[picture](/initialSetup.png) + +4. Type the command into the command line and press Enter to execute it. e.g. typing list and pressing Enter will list the current tasks. +Some example commands you can try: + +- `todo tutorial`: Adds task "tutorial" to the list +- `deadline return book by 4pm`: Adds task "return book" nd deadline "4pm" to the list +- `list`: Lists all tasks +- `bye`: Exits the app + +5. Refer to the Features below for more details on each command. + +##Features + +[!NOTE] +> Words in `UPPER_CASE` are parameters to be supplied by the user. e.g. in `delete INDEX`, `INDEX` is a parameter which can be used as `delete 3` + +##Listing tasks: `list` +Lists all tasks in the task list. + +Format: `list` + +[picture1](/List.png) + +##Add tasks +###Add todo : `todo` +Adds task of type todo to the list of tasks + +Format: `todo DESCRIPTION` + +Examples: +- `todo tutorial` Adds task `tutorial` to the list of tasks +- `todo watch lecture` Adds task `watch lecture` to the list of tasks + +ADD PIC HERE + +###Add deadline: `deadline` +Adds task of type deadline to the list of tasks + +Format: `deadline DESCRIPTION by DEADLINE` + +Examples: +- `deadline return book by 4pm` Adds task `return book` with deadline `4pm` to the list of tasks +- `deadline submit report by 7pm` Adds task `submit report` with deadline `7pm` to the list of tasks + +ADD PIC HERE + +##Add event: `event` +Adds task of type event to the list of tasks + +Format: `event DESCRIPTION from START to END` + +Examples: +- `event Math exam from 2pm to 4pm` Adds task `Math exam` with timeline `2pm` to `4pm` to the list of tasks +- `event project group meeting from 11am to 1pm` Adds task `project group meeting` with timeline `11am` to `1pm` to the list of tasks + +ADD PIC HERE + +##Delete tasks: `delete` +Deletes task from the list of tasks + +Format: `delete INDEX` + +- Deletes task at the specified `INDEX`. +- The index refers to the index of the task in the list of tasks. +- The index must be a positive integer. + +Examples: +- `delete 3` Deletes third task in the list +- `delete 5` Deletes fifth task in the list + +##Mark tasks as done: `mark` +Marks tasks as completed + +Format: `mark INDEX` + +- Marks task as done at the specified `INDEX`. +- The index refers to the index of the task in the list of tasks. +- The index must be a positive integer. + +Examples: +- `mark 1` Marks first task in the list as done +- `mark 6` Marks sixth task in the list as done + +##Unmark tasks: `unmark` +Marks tasks as undone + +Format: `unmark INDEX` + +- Marks task as not done at the specified `INDEX`. +- The index refers to the index of the task in the list of tasks. +- The index must be a positive integer. + +Examples: +- `unmark 1` Marks first task in the list as notdone +- `unmark 2` Marks second task in the list as not done + +##Find Keywords: `find` +Filters list of tasks to those containing the keyword the user wants to find + +Format: `find KEYWORD` + +Examples: +- `find book` CLI returns a list with all the tasks with the `KEYWORD` `book`. +- `find tutorial` CLI returns a list with all the tasks with the `KEYWORD` `tutorial`. + +##Exit app: `bye` +Exits the chatbot + +Format: `bye` + +##Command Summary + +| Command | Format,Examples | +| ------- | --------------- | +| `list` | `list` | +| `todo` | `todo DESCRIPTION` e.g. `todo tutorial` | +| `deadline` | `deadline DESCRIPTION by DEADLINE` e.g. `deadline return book by 4pm` | +| `event` | `event DESCRIPTION from START to END` e.g. event Math exam from 2pm to 4pm` | +| `delete` | `delete INDEX` e.g. `delete 3` | +| `mark` | `mark INDEX` e.g. `mark 2` | +| `unmark` | `unmark INDEX` e.g. `unmark 1` | +| `find` | `find KEYWORD` e.g. `find book` | +| `bye` | `bye` | \ No newline at end of file From 2f4b48118b711f55779b87e2434b8efc14275d96 Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Fri, 8 Mar 2024 02:33:14 +0800 Subject: [PATCH 24/28] Format headers --- README.md | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 75e6cf898..0e8e4c0f3 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,14 @@ -#User Guide for chatbot "Apple" +# User Guide for chatbot "Apple" Chatbot Apple is an app to manage tasks, optimised for use through a Command Line Interface (CLI). -##Quick Start +## Quick Start 1. Ensure Java 11 or above is installed in your computer 2. Download `ip.jar` from [here](https://github.com/hongyijie06/ip/releases/tag/A-Jar) 3. Open a command terminal, `cd` into the folder with the jar file and use the `java -jar ip.jar` command to run the application. A CLI similar to the picture below should appear in a few seconds. Note how the app returns the path to which the list of tasks is saved on the local computer. -[picture](/initialSetup.png) - 4. Type the command into the command line and press Enter to execute it. e.g. typing list and pressing Enter will list the current tasks. Some example commands you can try: @@ -21,7 +19,7 @@ Some example commands you can try: 5. Refer to the Features below for more details on each command. -##Features +## Features [!NOTE] > Words in `UPPER_CASE` are parameters to be supplied by the user. e.g. in `delete INDEX`, `INDEX` is a parameter which can be used as `delete 3` @@ -31,10 +29,8 @@ Lists all tasks in the task list. Format: `list` -[picture1](/List.png) - -##Add tasks -###Add todo : `todo` +## Add tasks +### Add todo : `todo` Adds task of type todo to the list of tasks Format: `todo DESCRIPTION` @@ -45,7 +41,7 @@ Examples: ADD PIC HERE -###Add deadline: `deadline` +### Add deadline: `deadline` Adds task of type deadline to the list of tasks Format: `deadline DESCRIPTION by DEADLINE` @@ -56,7 +52,7 @@ Examples: ADD PIC HERE -##Add event: `event` +### Add event: `event` Adds task of type event to the list of tasks Format: `event DESCRIPTION from START to END` @@ -67,7 +63,7 @@ Examples: ADD PIC HERE -##Delete tasks: `delete` +## Delete tasks: `delete` Deletes task from the list of tasks Format: `delete INDEX` @@ -80,7 +76,7 @@ Examples: - `delete 3` Deletes third task in the list - `delete 5` Deletes fifth task in the list -##Mark tasks as done: `mark` +## Mark tasks as done: `mark` Marks tasks as completed Format: `mark INDEX` @@ -93,7 +89,7 @@ Examples: - `mark 1` Marks first task in the list as done - `mark 6` Marks sixth task in the list as done -##Unmark tasks: `unmark` +## Unmark tasks: `unmark` Marks tasks as undone Format: `unmark INDEX` @@ -106,7 +102,7 @@ Examples: - `unmark 1` Marks first task in the list as notdone - `unmark 2` Marks second task in the list as not done -##Find Keywords: `find` +## Find Keywords: `find` Filters list of tasks to those containing the keyword the user wants to find Format: `find KEYWORD` @@ -115,12 +111,12 @@ Examples: - `find book` CLI returns a list with all the tasks with the `KEYWORD` `book`. - `find tutorial` CLI returns a list with all the tasks with the `KEYWORD` `tutorial`. -##Exit app: `bye` +## Exit app: `bye` Exits the chatbot Format: `bye` -##Command Summary +## Command Summary | Command | Format,Examples | | ------- | --------------- | From 4f03af2ddd781c95bf5b2346545493980c7b5777 Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Fri, 8 Mar 2024 20:33:18 +0800 Subject: [PATCH 25/28] follow coding standards --- README.md | 6 +- src/main/java/CreateFile.java | 24 ++-- src/main/java/Deadline.java | 2 +- src/main/java/Duke.java | 31 +++-- src/main/java/EmptyLineException.java | 3 +- src/main/java/Event.java | 4 +- src/main/java/Parser.java | 102 ++++++++-------- src/main/java/ReadFileContents.java | 19 +-- src/main/java/Storage.java | 18 ++- src/main/java/TaskList.java | 114 +++++++++++------- src/main/java/Todo.java | 4 +- src/main/java/Ui.java | 8 +- src/main/java/UnexpectedCommandException.java | 1 + 13 files changed, 192 insertions(+), 144 deletions(-) diff --git a/README.md b/README.md index 0e8e4c0f3..db4a5e14b 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Some example commands you can try: [!NOTE] > Words in `UPPER_CASE` are parameters to be supplied by the user. e.g. in `delete INDEX`, `INDEX` is a parameter which can be used as `delete 3` -##Listing tasks: `list` +## Listing tasks: `list` Lists all tasks in the task list. Format: `list` @@ -118,12 +118,12 @@ Format: `bye` ## Command Summary -| Command | Format,Examples | +| Command | Format, Examples | | ------- | --------------- | | `list` | `list` | | `todo` | `todo DESCRIPTION` e.g. `todo tutorial` | | `deadline` | `deadline DESCRIPTION by DEADLINE` e.g. `deadline return book by 4pm` | -| `event` | `event DESCRIPTION from START to END` e.g. event Math exam from 2pm to 4pm` | +| `event` | `event DESCRIPTION from START to END` e.g. `event Math exam from 2pm to 4pm` | | `delete` | `delete INDEX` e.g. `delete 3` | | `mark` | `mark INDEX` e.g. `mark 2` | | `unmark` | `unmark INDEX` e.g. `unmark 1` | diff --git a/src/main/java/CreateFile.java b/src/main/java/CreateFile.java index b977750c6..8162aba93 100644 --- a/src/main/java/CreateFile.java +++ b/src/main/java/CreateFile.java @@ -5,21 +5,29 @@ * creates local TaskList.txt file on the local machine */ public class CreateFile { - public static void CreateFile(){ - File f = new File("TaskList.txt"); - if (!f.exists()) { + protected static Ui ui; + public static void CreateFile() { + File file = new File("TaskList.txt"); + String errorDescription; + String fileStatus; + + if (!file.exists()) { try { - if (f.createNewFile()) { - System.out.println("File created: " + f.getAbsolutePath()); + if (file.createNewFile()) { + fileStatus = "File created"; + System.out.println(fileStatus + ": " + file.getAbsolutePath()); } else { - System.out.println("File creation failed."); + errorDescription = "File creation failed."; + ui.errorMessage(errorDescription); } } catch (IOException e) { - System.out.println("An error occurred."); + errorDescription = "An I/O error occurred."; + ui.errorMessage(errorDescription); e.printStackTrace(); } } else { - System.out.println("File already exists: " + f.getAbsolutePath()); + fileStatus = "File already exists"; + System.out.println(fileStatus + ": " + file.getAbsolutePath()); } } } diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 941068471..c85aa1cf8 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,7 +1,7 @@ /** * child class of Task to handle deadlines */ -public class Deadline extends Task{ +public class Deadline extends Task { protected String by; public Deadline(String description, String by) { diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 8cebfc61e..df9a9300c 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -12,7 +12,7 @@ public class Duke { * @param filePath the path to the local TaskList.txt file * @throws FileNotFoundException exception when local TaskList.txt file does not exist */ - private static void printFileContents(String filePath) throws FileNotFoundException { + private static void printFileContents (String filePath) throws FileNotFoundException { File f = new File(filePath); // create a File for the given file path Scanner s = new Scanner(f); // create a Scanner using the File as the source while (s.hasNext()) { @@ -21,33 +21,38 @@ private static void printFileContents(String filePath) throws FileNotFoundExcept } private static Ui ui; - public static void main(String[] args) throws UnexpectedCommandException, EmptyLineException, IOException, FileNotFoundException { + public static void main (String[] args) throws UnexpectedCommandException, EmptyLineException, IOException, FileNotFoundException { ArrayList tasks = new ArrayList(); + String errorDescription; + int index = 0;//number of items in the list + String line = " "; + File file = new File("TaskList.txt"); + ui = new Ui(); ui.sayHi(); try { System.out.println("Here are the items in your task list: "); printFileContents("TaskList.txt"); - } catch (FileNotFoundException e) { - System.out.println("File not found"); + errorDescription = "File not found"; + ui.errorMessage(errorDescription); } - int index = 0;//number of items in the list - String line = " "; - File f = new File("TaskList.txt"); - if (!f.exists()) { + + if (!file.exists()) { try { - if (f.createNewFile()) { - System.out.println("File created: " + f.getAbsolutePath()); + if (file.createNewFile()) { + System.out.println("File created: " + file.getAbsolutePath()); } else { - System.out.println("File creation failed."); + errorDescription = "File creation failed."; + ui.errorMessage(errorDescription); } } catch (IOException e) { - System.out.println("An error occurred."); + errorDescription = "An I/O error occurred."; + ui.errorMessage(errorDescription); e.printStackTrace(); } } else { - System.out.println("File already exists: " + f.getAbsolutePath()); + System.out.println("File already exists: " + file.getAbsolutePath()); } new Parser(tasks, index, line); diff --git a/src/main/java/EmptyLineException.java b/src/main/java/EmptyLineException.java index fd35912c9..5348ca427 100644 --- a/src/main/java/EmptyLineException.java +++ b/src/main/java/EmptyLineException.java @@ -1,2 +1,3 @@ -public class EmptyLineException extends Exception{ +public class EmptyLineException extends Exception { + } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index d61530a83..7c94810a5 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,14 +1,16 @@ /** * child class of Task to handle events */ -public class Event extends Task{ +public class Event extends Task { protected String from; protected String to; + public Event(String description, String from, String to){ super(description); this.from = from; this.to = to; } + @Override public String toString() { return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")"; diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index c3465ff7a..fe92bb35b 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -6,36 +6,32 @@ * deals with making sense of the user command */ public class Parser { - protected static String from; - protected static String to; - public static String description; - protected static String by; private static Ui ui; private static Storage storage; private static TaskList tasklist; - public String findInput; - /** * marks task as done * @param inputs the array of words the user input * @param tasks the array of tasks * @param index the number of tasks in the array of tasks * @param isValidCommand boolean is true if the command from the user is a valid action - * @throws IOException exception when local TaskList.txt file does not exist + * @throws IOException exception when there is an I/O error */ - private void dealWithMark(String[] inputs, ArrayList tasks, int index, boolean isValidCommand) throws IOException { + private void dealWithMark (String[] inputs, ArrayList tasks, int index, boolean isValidCommand) throws IOException { isValidCommand = true; + String errorDescription; + try { - int idx = Integer.parseInt(inputs[1]); - tasks.get(idx - 1).markAsDone(); + int markIdx = Integer.parseInt(inputs[1]) - 1; //index to mark as done + tasks.get(markIdx).markAsDone(); System.out.println("Nice! I've marked this task as done: "); - System.out.println(tasks.get(idx - 1)); + System.out.println(tasks.get(markIdx)); storage.saveToFile(tasks, index); - } catch (IndexOutOfBoundsException e){ - ui.errorMessage("did not indicate which task to mark"); + } catch (IndexOutOfBoundsException e) { + errorDescription = "did not indicate which task to mark"; + ui.errorMessage(errorDescription); } - } /** @@ -44,18 +40,21 @@ private void dealWithMark(String[] inputs, ArrayList tasks, int index, boo * @param tasks the array of tasks * @param index the number of tasks in the array of tasks * @param isValidCommand boolean is true if the command from the user is a valid action - * @throws IOException exception when local TaskList.txt file does not exist + * @throws IOException exception when there is an I/O error */ - private void dealWithUnmark(String[] inputs, ArrayList tasks, int index, boolean isValidCommand) throws IOException { + private void dealWithUnmark (String[] inputs, ArrayList tasks, int index, boolean isValidCommand) throws IOException { isValidCommand = true; + String errorDescription; + try { - int idx = Integer.parseInt(inputs[1]); - tasks.get(idx - 1).unmarkDone(); + int unmarkIdx = Integer.parseInt(inputs[1]) - 1; //index of task to unmark + tasks.get(unmarkIdx).unmarkDone(); System.out.println("OK, I've marked this task as not done yet: "); - System.out.println(tasks.get(idx - 1)); + System.out.println(tasks.get(unmarkIdx)); storage.saveToFile(tasks, index); - } catch (IndexOutOfBoundsException e){ - ui.errorMessage("did not indicate which task to unmark"); + } catch (IndexOutOfBoundsException e) { + errorDescription = "did not indicate which task to unmark"; + ui.errorMessage(errorDescription); } } @@ -65,12 +64,12 @@ private void dealWithUnmark(String[] inputs, ArrayList tasks, int index, b * @param index the number of tasks in the array of tasks * @param isValidCommand boolean is true if the command from the user is a valid action */ - private void listTasks(ArrayList tasks, int index, boolean isValidCommand){ + private void listTasks (ArrayList tasks, int index, boolean isValidCommand) { isValidCommand = true; System.out.println("Here are the tasks in your list: "); - for (int i = 0; i < index; i++) { - System.out.println((i + 1) + ". " + tasks.get(i)); + for (int taskNumber = 0; taskNumber < index; taskNumber++) { + System.out.println((taskNumber + 1) + ". " + tasks.get(taskNumber)); } } @@ -82,9 +81,9 @@ private void listTasks(ArrayList tasks, int index, boolean isValidCommand) * @param isValidCommand boolean is true if the command from the user is a valid action * @return the number of tasks in the array of tasks after deletion * @throws UnexpectedCommandException exception when the format or details of the tasks are not followed and provided respectively - * @throws IOException exception when local TaskList.txt file does not exist + * @throws IOException exception when there is an I/O error */ - private int deleteTask(ArrayList tasks, String[] inputs, int index, boolean isValidCommand) throws UnexpectedCommandException, IOException { + private int deleteTask (ArrayList tasks, String[] inputs, int index, boolean isValidCommand) throws UnexpectedCommandException, IOException { isValidCommand = true; Storage.fillFileContents(tasks, "TaskList.txt", index); TaskList.dealWithDelete(inputs, inputs[1], tasks); @@ -100,15 +99,15 @@ private int deleteTask(ArrayList tasks, String[] inputs, int index, boolea * @param tasks the array of tasks * @param index the number of tasks in the array of tasks */ - private void dealWithFind(String findInput, ArrayList tasks, int index){ + private void dealWithFind (String findInput, ArrayList tasks, int index) { ArrayList matchingTasks = new ArrayList(); int matchingTasksIndex = 1; System.out.println("Here are the matching tasks in your list: "); - for (int i = 0; i < index; i ++){ - String xline = tasks.get(i).toString(); - if (xline.contains(findInput)){ + for (int taskNumber = 0; taskNumber < index; taskNumber ++){ + String taskString = tasks.get(taskNumber).toString(); + if (taskString.contains(findInput)) { System.out.print(matchingTasksIndex + ". "); - matchingTasks.add(tasks.get(i)); + matchingTasks.add(tasks.get(taskNumber)); System.out.println(matchingTasks.get(matchingTasksIndex - 1)); matchingTasksIndex ++; } @@ -116,13 +115,13 @@ private void dealWithFind(String findInput, ArrayList tasks, int index){ } - private void handleUnexpectedCommand(boolean isValidCommand) throws UnexpectedCommandException { + private void handleUnexpectedCommand (boolean isValidCommand) throws UnexpectedCommandException { if (!isValidCommand) { throw new UnexpectedCommandException(); } } - private void handleEmptyInput(String line) throws EmptyLineException { + private void handleEmptyInput (String line) throws EmptyLineException { if (line.isEmpty()) { throw new EmptyLineException(); } @@ -133,15 +132,16 @@ private void handleEmptyInput(String line) throws EmptyLineException { * @param tasks the array of tasks * @param index the number of tasks in the array of tasks * @param line the user input - * @throws IOException exception when local TaskList.txt file does not exist + * @throws IOException exception when there is an I/O error * @throws IndexOutOfBoundsException exception when there is missing required details in the input * @throws UnexpectedCommandException exception when the format or details of the tasks are not followed and provided respectively */ - public Parser(ArrayList tasks, int index, String line) throws IOException, IndexOutOfBoundsException, UnexpectedCommandException { + public Parser (ArrayList tasks, int index, String line) throws IOException, IndexOutOfBoundsException, UnexpectedCommandException { boolean isInTxt = true; index = Storage.fillFileContents(tasks, "TaskList.txt", index); isInTxt = false; ui = new Ui(); + String errorDescription; while (!line.equals("bye")) { ui.readCommand(); @@ -151,11 +151,13 @@ public Parser(ArrayList tasks, int index, String line) throws IOException, Task t = new Task(line); String[] inputs = line.split(" "); + + final String commandType = inputs[0]; - if (inputs[0].equals("mark")) {//mark as done + if (commandType.equals("mark")) {//mark as done dealWithMark(inputs, tasks, index, isValidCommand); Storage.saveToFile(tasks, index); - } else if (inputs[0].equals("unmark")) {//unmark done + } else if (commandType.equals("unmark")) {//unmark done dealWithUnmark(inputs, tasks, index, isValidCommand); Storage.saveToFile(tasks, index); } else if (line.equals("list")) {//lists tasks @@ -164,16 +166,16 @@ public Parser(ArrayList tasks, int index, String line) throws IOException, isValidCommand = true; Storage.saveToFile(tasks, index); break; - } else if (inputs[0].equals("event") || inputs[0].equals("todo") || inputs[0].equals("deadline")) {//add items + } else if (commandType.equals("event") || commandType.equals("todo") || commandType.equals("deadline")) {//add items try { - if (inputs[0].equals("event")) { + if (commandType.equals("event")) { isValidCommand = true; TaskList.dealWithEvent(tasks, index, line, isInTxt); Storage.writeToFile("TaskList.txt", tasks.get(index)); System.out.println("Got it. I've added this task: "); System.out.println(tasks.get(index)); index++; - } else if (inputs[0].equals("deadline")) { + } else if (commandType.equals("deadline")) { isValidCommand = true; TaskList.dealWithDeadline(tasks, index, line, isInTxt); Storage.writeToFile("TaskList.txt", tasks.get(index)); @@ -192,26 +194,30 @@ public Parser(ArrayList tasks, int index, String line) throws IOException, } System.out.println("Now you have " + index + " tasks in the list."); - } else if (inputs[0].equals("delete")) { + } else if (commandType.equals("delete")) { try { index = deleteTask(tasks, inputs, index, isValidCommand); - } catch (ArrayIndexOutOfBoundsException e){ - System.out.println("please specify which task you want to delete"); + } catch (ArrayIndexOutOfBoundsException e) { + errorDescription = "please specify which task you want to delete"; + ui.errorMessage(errorDescription); } - } else if (inputs[0].equals("find")){ + } else if (commandType.equals("find")) { try { dealWithFind(inputs[1], tasks, index); - } catch (ArrayIndexOutOfBoundsException e){ - System.out.println("please state what you would like to find"); + } catch (ArrayIndexOutOfBoundsException e) { + errorDescription = "please state what you would like to find"; + ui.errorMessage(errorDescription); } } else { try { handleEmptyInput(line); handleUnexpectedCommand(isValidCommand); } catch (UnexpectedCommandException e) { - ui.errorMessage("Please enter a valid command"); + errorDescription = "Please enter a valid command"; + ui.errorMessage(errorDescription); } catch (EmptyLineException e) { - ui.errorMessage("No input detected. Please enter a task"); + errorDescription = "No input detected. Please enter a task"; + ui.errorMessage(errorDescription); } } } diff --git a/src/main/java/ReadFileContents.java b/src/main/java/ReadFileContents.java index 9f914cc71..0a797b2c7 100644 --- a/src/main/java/ReadFileContents.java +++ b/src/main/java/ReadFileContents.java @@ -2,24 +2,27 @@ import java.io.FileNotFoundException; import java.util.Scanner; +/** + * prints TaskList.txt file contents + */ public class ReadFileContents { + private static Ui ui; - private static void printFileContents(String filePath) throws FileNotFoundException { - File f = new File(filePath); // create a File for the given file path - Scanner s = new Scanner(f); // create a Scanner using the File as the source - while (s.hasNext()) { - System.out.println(s.nextLine()); + private static void printFileContents (String filePath) throws FileNotFoundException { + File file = new File(filePath); + Scanner taskString = new Scanner(file); //reads tasks from TaskList.txt file + while (taskString.hasNext()) { + System.out.println(taskString.nextLine()); } } public static void main(String[] args) { try { printFileContents("TaskList.txt"); - } catch (FileNotFoundException e) { new CreateFile(); - System.out.println("File not found"); + String errorDescription = "File not found"; + ui.errorMessage(errorDescription); } } - } \ No newline at end of file diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 6897d87ae..e40b26e1e 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -17,13 +17,12 @@ public class Storage { * @throws IOException exception when local TaskList.txt file does not exist * @throws UnexpectedCommandException exception when the format or details of the tasks are not followed and provided respectively */ - public static int fillFileContents(ArrayList tasks, String filePath, int index) throws IOException, UnexpectedCommandException {//updates index + public static int fillFileContents (ArrayList tasks, String filePath, int index) throws IOException, UnexpectedCommandException {//updates index File f = new File(filePath); // create a File for the given file path - Scanner s = new Scanner(f); // create a Scanner using the File as the source + Scanner taskLine = new Scanner(f); // create a Scanner using the File as the source - while (s.hasNext()) { - - String sLine = s.nextLine(); + while (taskLine.hasNext()) { + String sLine = taskLine.nextLine(); if (sLine.contains("[E]")) { TaskList.dealWithEvent(tasks, index, sLine, true); @@ -32,7 +31,6 @@ public static int fillFileContents(ArrayList tasks, String filePath, int i } else if (sLine.contains("[T]")) { TaskList.dealWithTodo(tasks, index, sLine, true); } - index++; } boolean isInTxt = false; @@ -43,9 +41,9 @@ public static int fillFileContents(ArrayList tasks, String filePath, int i * saves the updated tasks list onto TaskList.txt in the local machine * @param tasks the array of tasks * @param index the nymber of tasks in array of tasks - * @throws IOException exception when local TaskList.txt file does not exist + * @throws IOException exception when there is an I/O error */ - protected static void saveToFile(ArrayList tasks, int index) throws IOException{ + protected static void saveToFile (ArrayList tasks, int index) throws IOException { new FileWriter("TaskList.txt", false).close(); for (int TaskIndex = 0; TaskIndex < index; TaskIndex ++) { writeToFile("TaskList.txt", tasks.get(TaskIndex)); @@ -56,9 +54,9 @@ protected static void saveToFile(ArrayList tasks, int index) throws IOExce * adds additional tasks into TaskList.txt * @param filePath the path to TaskList.txt saved on the local machine * @param textToAdd the new task to add - * @throws IOException exception when local TaskList.txt file does not exist + * @throws IOException exception when there is an I/O error */ - static void writeToFile(String filePath, Task textToAdd) throws IOException{ + static void writeToFile (String filePath, Task textToAdd) throws IOException { FileWriter fw = new FileWriter(filePath, true); fw.write(textToAdd + "\n"); fw.close(); diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 45ffe4f05..398f411e6 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -18,54 +18,65 @@ public TaskList(){ * @param line the input string from the user * @param isInTxt true if ArrayList tasks is being loaded from TaskList.txt * @throws UnexpectedCommandException exception when the format or details of the tasks are not followed and provided respectively - * @throws IOException exception when local TaskList.txt file does not exist + * @throws IOException exception when there is an I/O error */ - public static void dealWithEvent(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { + public static void dealWithEvent (ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { int indexTo = line.lastIndexOf("to"); int indexFrom = line.indexOf("from"); String from; String to; String description; + String errorDescription; + + final int LENGTHOFFROM = 5; //length of "from " + final int LENGTHOFTO = 3; + final int EVENTCOMMANDLENGTH = 6;//length of "event " + + final int FROMLENGTHCOLON = 6;//length of "from: " + final int TOLENGTHCOLON = 4; + final int STATUSLENGTH = 5;//length of "[E][ ]" if ((indexTo == -1) || (indexFrom == -1)) { //invalid format - ui.errorMessage("Invalid format! Enter event in the format: event (description) from (start) to (end)"); + errorDescription = "Invalid format! Enter event in the format: event (description) from (start) to (end)"; + ui.errorMessage(errorDescription); throw new UnexpectedCommandException(); } try {//timeline not specified/ both not specified - from = line.substring(indexFrom + 5, indexTo - 1); - to = line.substring(indexTo + 3); + from = line.substring(indexFrom + LENGTHOFFROM, indexTo - 1); + to = line.substring(indexTo + LENGTHOFTO); } catch (IndexOutOfBoundsException e) { try { - description = line.substring(6, indexFrom - 1); + description = line.substring(EVENTCOMMANDLENGTH, indexFrom - 1); } catch (IndexOutOfBoundsException f) { - ui.errorMessage("event description and timeline not specified"); + errorDescription = "event description and timeline not specified"; + ui.errorMessage(errorDescription); throw new UnexpectedCommandException(); } - ui.errorMessage("event timeline not specified"); + errorDescription = "event timeline not specified"; + ui.errorMessage(errorDescription); throw new UnexpectedCommandException(); } try {//description not specified - description = line.substring(6, indexFrom - 1); + description = line.substring(EVENTCOMMANDLENGTH, indexFrom - 1); } catch (IndexOutOfBoundsException e) { - ui.errorMessage("event description not specified"); + errorDescription = "event description not specified"; + ui.errorMessage(errorDescription); throw new UnexpectedCommandException(); } - if(!isInTxt) { - from = line.substring(indexFrom + 5, indexTo - 1); - to = line.substring(indexTo + 3); - description = line.substring(5, indexFrom - 1); + if (!isInTxt) { + from = line.substring(indexFrom + LENGTHOFFROM, indexTo - 1); + to = line.substring(indexTo + LENGTHOFTO); + description = line.substring(STATUSLENGTH, indexFrom - 1); } else { - - from = line.substring(indexFrom + 6, indexTo - 1); - to = line.substring(indexTo + 4, line.length() - 1); - description = line.substring(6, indexFrom - 1); - - + from = line.substring(indexFrom + FROMLENGTHCOLON, indexTo - 1); + to = line.substring(indexTo + TOLENGTHCOLON, line.length() - 1); + description = line.substring(EVENTCOMMANDLENGTH, indexFrom - 1); } tasks.add(index, new Event(description, from, to)); + final int STATUSINDEX = 4; if (isInTxt){ char[] charArray = line.toCharArray(); - if (charArray[4] == '1'){ + if (charArray[STATUSINDEX] == '1'){ tasks.get(index).markAsDone(); } else{ tasks.get(index).unmarkDone(); @@ -80,49 +91,59 @@ public static void dealWithEvent(ArrayList tasks, int index, String line, * @param line the input string from the user * @param isInTxt true if ArrayList tasks is being loaded from TaskList.txt * @throws UnexpectedCommandException exception when the format or details of the tasks are not followed and provided respectively - * @throws IOException exception when local TaskList.txt file does not exist + * @throws IOException exception when there is an I/O error */ - public static void dealWithDeadline(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { + public static void dealWithDeadline (ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { int indexBy = line.indexOf("by"); int space = line.indexOf(" "); String by; String description; + String errorDescription; + + final int LENGTHFBY = 3;//length of "by " + final int BYLENGTHCOLON = 4; //length of "by: " + if (indexBy == -1) {//invalid format - ui.errorMessage("Invalid format! Enter deadline in the format: deadline (description) by (deadline)"); + errorDescription = "Invalid format! Enter deadline in the format: deadline (description) by (deadline)"; + ui.errorMessage(errorDescription); throw new UnexpectedCommandException(); } try {//deadline / both not specified - by = line.substring(indexBy + 3); + by = line.substring(indexBy + LENGTHFBY); } catch (IndexOutOfBoundsException e) { try { description = line.substring(space + 1, indexBy - 1); } catch (IndexOutOfBoundsException f) { - ui.errorMessage("deadline description and deadline not specified"); + errorDescription = "deadline description and deadline not specified"; + ui.errorMessage(errorDescription); throw new UnexpectedCommandException(); } - ui.errorMessage("deadline not specified"); + errorDescription = "deadline not specified"; + ui.errorMessage(errorDescription); throw new UnexpectedCommandException(); } try {//deadline not specified description = line.substring(space + 1, indexBy - 1); } catch (IndexOutOfBoundsException e) { - ui.errorMessage("deadline description not specified"); + errorDescription = "deadline description not specified"; + ui.errorMessage(errorDescription); throw new UnexpectedCommandException(); } if (!isInTxt) { description = line.substring(space, indexBy - 1); - by = line.substring(indexBy + 3); - } else{ + by = line.substring(indexBy + LENGTHFBY); + } else { description = line.substring(space, indexBy - 1); - by = line.substring(indexBy + 4, line.length() - 1); + by = line.substring(indexBy + BYLENGTHCOLON, line.length() - 1); } tasks.add(index, new Deadline(description, by)); - if (isInTxt){ + if (isInTxt) { + final int STATUSINDEX = 4; char[] charArray = line.toCharArray(); - if (charArray[4] == '1'){ + if (charArray[STATUSINDEX] == '1'){ tasks.get(index).markAsDone(); - } else{ + } else { tasks.get(index).unmarkDone(); } } @@ -135,26 +156,29 @@ public static void dealWithDeadline(ArrayList tasks, int index, String lin * @param line the input string from the user * @param isInTxt true if ArrayList tasks is being loaded from TaskList.txt * @throws UnexpectedCommandException exception when the format or details of the tasks are not followed and provided respectively - * @throws IOException exception when local TaskList.txt file does not exist + * @throws IOException exception when there is an I/O error */ - public static void dealWithTodo(ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { + public static void dealWithTodo (ArrayList tasks, int index, String line, boolean isInTxt) throws UnexpectedCommandException, IOException { int indexSpace = line.indexOf(" "); + final int STATUSINDEX = 4; + String errorDescription; + if (indexSpace == -1) { - ui.errorMessage("todo description not specified"); + errorDescription = "todo description not specified"; + ui.errorMessage(errorDescription); throw new UnexpectedCommandException(); } String description = line.substring(indexSpace); tasks.add(index, new Todo(description)); - if (isInTxt){ + if (isInTxt) { char[] charArray = line.toCharArray(); - if (charArray[4] == '1'){ + if (charArray[STATUSINDEX] == '1') { tasks.get(index).markAsDone(); - } else{ + } else { tasks.get(index).unmarkDone(); } } - } /** @@ -163,12 +187,12 @@ public static void dealWithTodo(ArrayList tasks, int index, String line, b * @param ListIndex the string containing the task number to delete * @param tasks the array of tasks */ - public static void dealWithDelete (String[] inputs, String ListIndex, ArrayList tasks){ + public static void dealWithDelete (String[] inputs, String ListIndex, ArrayList tasks) { if (inputs[0].equals("delete")) { - int idx = Integer.parseInt(ListIndex); + int deleteIdx = Integer.parseInt(ListIndex) - 1; //index of task to delete System.out.println("Noted. I've removed this task: "); - System.out.println(tasks.get(idx - 1)); - tasks.remove(idx - 1); + System.out.println(tasks.get(deleteIdx)); + tasks.remove(deleteIdx); } } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index d50a314bc..50d8abdcd 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -1,9 +1,9 @@ /** * child class of Task to handle todos */ -public class Todo extends Task{ +public class Todo extends Task { - public Todo(String description){ + public Todo (String description){ super(description); } @Override diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 4788dddc8..1e0a62a5b 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -3,20 +3,20 @@ */ public class Ui { - public void sayHi(){ + public void sayHi() { System.out.println("Hello! I'm Apple"); System.out.println("What can I do for you?"); } - public void readCommand(){ + public void readCommand() { System.out.print("Enter your command: "); } - public static void errorMessage(String message){ + public static void errorMessage (String message) { System.out.println(message); } - public void sayBye(){ + public void sayBye() { System.out.println("Bye. Hope to see you again soon!"); } } diff --git a/src/main/java/UnexpectedCommandException.java b/src/main/java/UnexpectedCommandException.java index 3d56bc38b..0b8f65fcf 100644 --- a/src/main/java/UnexpectedCommandException.java +++ b/src/main/java/UnexpectedCommandException.java @@ -1,2 +1,3 @@ public class UnexpectedCommandException extends Exception { + } From fbcc37c9d7366a390aba1485b45de884af80291e Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Fri, 8 Mar 2024 22:57:17 +0800 Subject: [PATCH 26/28] add README pictures --- docs/README.md | 154 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 138 insertions(+), 16 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..fc387c781 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,151 @@ -# User Guide +# User Guide for chatbot "Apple" -## Features +Chatbot Apple is an app to manage tasks, optimised for use through a Command Line Interface (CLI). -### Feature-ABC +## Quick Start +1. Ensure Java 11 or above is installed in your computer +2. Download `ip.jar` from [here](https://github.com/hongyijie06/ip/releases/tag/A-Release) +3. Open a command terminal, `cd` into the folder with the jar file and use the `java -jar ip.jar` command to run the application. -Description of the feature. +A CLI similar to the picture below should appear in a few seconds. Note how the app returns the path to which the list of tasks is saved on the local computer. -### Feature-XYZ +!("C:\Users\User\Documents\CS2113\ip\docs\welcome_screen.png") -Description of the feature. +4. Type the command into the command line and press Enter to execute it. e.g. typing list and pressing Enter will list the current tasks. +Some example commands you can try: -## Usage +- `todo tutorial`: Adds task "tutorial" to the list +- `deadline return book by 4pm`: Adds task "return book" nd deadline "4pm" to the list +- `list`: Lists all tasks +- `bye`: Exits the app -### `Keyword` - Describe action +5. Refer to the Features below for more details on each command. -Describe the action and its outcome. +## Features -Example of usage: +[!NOTE] +> Words in `UPPER_CASE` are parameters to be supplied by the user. e.g. in `delete INDEX`, `INDEX` is a parameter which can be used as `delete 3` -`keyword (optional arguments)` +## Add tasks +### Add todo : `todo` +Adds task of type todo to the list of tasks -Expected outcome: +Format: `todo DESCRIPTION` -Description of the outcome. +Examples: +- `todo tutorial` Adds task `tutorial` to the list of tasks +- `todo watch lecture` Adds task `watch lecture` to the list of tasks -``` -expected output -``` +The picture below shows the expected output. +!("C:\Users\User\Documents\CS2113\ip\docs\add_todo.png") + +### Add deadline: `deadline` +Adds task of type deadline to the list of tasks + +Format: `deadline DESCRIPTION by DEADLINE` + +Examples: +- `deadline return book by 4pm` Adds task `return book` with deadline `4pm` to the list of tasks +- `deadline submit group report by 7pm` Adds task `submit group report` with deadline `7pm` to the list of tasks + +The picture below shows the expected output. +!("C:\Users\User\Documents\CS2113\ip\docs\add_deadline.png") + +### Add event: `event` +Adds task of type event to the list of tasks + +Format: `event DESCRIPTION from START to END` + +Examples: +- `event Math exam from 2pm to 4pm` Adds task `Math exam` with timeline `2pm` to `4pm` to the list of tasks +- `event project group meeting from 11am to 1pm` Adds task `project group meeting` with timeline `11am` to `1pm` to the list of tasks + +The picture below shows the expected output. +!("C:\Users\User\Documents\CS2113\ip\docs\add_event.png") + +## Listing tasks: `list` +Lists all tasks in the task list. + +Format: `list` + +The picture below shows the expected output. +!("C:\Users\User\Documents\CS2113\ip\docs\list.png") + +## Mark tasks as done: `mark` +Marks tasks as completed + +Format: `mark INDEX` + +- Marks task as done at the specified `INDEX`. +- The index refers to the index of the task in the list of tasks. +- The index must be a positive integer. + +Examples: +- `mark 1` Marks first task in the list as done +- `mark 3` Marks sixth task in the list as done + +The picture below shows the expected output. +!("C:\Users\User\Documents\CS2113\ip\docs\mark.png") + +## Unmark tasks: `unmark` +Marks tasks as undone + +Format: `unmark INDEX` + +- Marks task as not done at the specified `INDEX`. +- The index refers to the index of the task in the list of tasks. +- The index must be a positive integer. + +Examples: +- `unmark 1` Marks first task in the list as not done +- `unmark 2` Marks second task in the list as not done + +## Find Keywords: `find` +Filters list of tasks to those containing the keyword the user wants to find + +Format: `find KEYWORD` + +Examples: +- `find book` CLI returns a list with all the tasks with the `KEYWORD` `book`. +- `find group` CLI returns a list with all the tasks with the `KEYWORD` `group`. + +The picture below shows the expected output. +!("C:\Users\User\Documents\CS2113\ip\docs\find.png") + +## Delete tasks: `delete` +Deletes task from the list of tasks + +Format: `delete INDEX` + +- Deletes task at the specified `INDEX`. +- The index refers to the index of the task in the list of tasks. +- The index must be a positive integer. + +Examples: +- `delete 3` Deletes third task in the list +- `delete 5` Deletes fifth task in the list + +The picture below shows the expected output. +!("C:\Users\User\Documents\CS2113\ip\docs\delete.png") + +## Exit app: `bye` +Exits the chatbot + +Format: `bye` + +The picture below shows the expected output. +!("C:\Users\User\Documents\CS2113\ip\docs\bye.png") + +## Command Summary + +| Command | Format, Examples | +| ------- | --------------- | +| `todo` | `todo DESCRIPTION` e.g. `todo tutorial` | +| `deadline` | `deadline DESCRIPTION by DEADLINE` e.g. `deadline return book by 4pm` | +| `event` | `event DESCRIPTION from START to END` e.g. `event Math exam from 2pm to 4pm` | +| `list` | `list` | +| `mark` | `mark INDEX` e.g. `mark 2` | +| `unmark` | `unmark INDEX` e.g. `unmark 1` | +| `find` | `find KEYWORD` e.g. `find book` | +| `delete` | `delete INDEX` e.g. `delete 3` | +| `bye` | `bye` | \ No newline at end of file From 456bcb01f224dfc36ab8ba39223232f0373c077d Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Fri, 8 Mar 2024 23:17:39 +0800 Subject: [PATCH 27/28] add pictures --- docs/README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/README.md b/docs/README.md index fc387c781..9e10573a7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -9,15 +9,15 @@ Chatbot Apple is an app to manage tasks, optimised for use through a Command Lin A CLI similar to the picture below should appear in a few seconds. Note how the app returns the path to which the list of tasks is saved on the local computer. -!("C:\Users\User\Documents\CS2113\ip\docs\welcome_screen.png") +![welcome](welcome_screen.png) 4. Type the command into the command line and press Enter to execute it. e.g. typing list and pressing Enter will list the current tasks. -Some example commands you can try: + Some example commands you can try: -- `todo tutorial`: Adds task "tutorial" to the list -- `deadline return book by 4pm`: Adds task "return book" nd deadline "4pm" to the list -- `list`: Lists all tasks -- `bye`: Exits the app + - `todo tutorial`: Adds task "tutorial" to the list + - `deadline return book by 4pm`: Adds task "return book" nd deadline "4pm" to the list + - `list`: Lists all tasks + - `bye`: Exits the app 5. Refer to the Features below for more details on each command. @@ -37,7 +37,7 @@ Examples: - `todo watch lecture` Adds task `watch lecture` to the list of tasks The picture below shows the expected output. -!("C:\Users\User\Documents\CS2113\ip\docs\add_todo.png") +![todo](add_todo.png) ### Add deadline: `deadline` Adds task of type deadline to the list of tasks @@ -49,7 +49,7 @@ Examples: - `deadline submit group report by 7pm` Adds task `submit group report` with deadline `7pm` to the list of tasks The picture below shows the expected output. -!("C:\Users\User\Documents\CS2113\ip\docs\add_deadline.png") +![deadline](add_deadline.png) ### Add event: `event` Adds task of type event to the list of tasks @@ -61,7 +61,7 @@ Examples: - `event project group meeting from 11am to 1pm` Adds task `project group meeting` with timeline `11am` to `1pm` to the list of tasks The picture below shows the expected output. -!("C:\Users\User\Documents\CS2113\ip\docs\add_event.png") +![event](add_event.png) ## Listing tasks: `list` Lists all tasks in the task list. @@ -69,7 +69,7 @@ Lists all tasks in the task list. Format: `list` The picture below shows the expected output. -!("C:\Users\User\Documents\CS2113\ip\docs\list.png") +![list](list.png) ## Mark tasks as done: `mark` Marks tasks as completed @@ -85,7 +85,7 @@ Examples: - `mark 3` Marks sixth task in the list as done The picture below shows the expected output. -!("C:\Users\User\Documents\CS2113\ip\docs\mark.png") +![mark](mark.png) ## Unmark tasks: `unmark` Marks tasks as undone @@ -110,7 +110,7 @@ Examples: - `find group` CLI returns a list with all the tasks with the `KEYWORD` `group`. The picture below shows the expected output. -!("C:\Users\User\Documents\CS2113\ip\docs\find.png") +![find](find.png) ## Delete tasks: `delete` Deletes task from the list of tasks @@ -126,7 +126,7 @@ Examples: - `delete 5` Deletes fifth task in the list The picture below shows the expected output. -!("C:\Users\User\Documents\CS2113\ip\docs\delete.png") +![delete](delete.png) ## Exit app: `bye` Exits the chatbot @@ -134,7 +134,7 @@ Exits the chatbot Format: `bye` The picture below shows the expected output. -!("C:\Users\User\Documents\CS2113\ip\docs\bye.png") +![bye](bye.png) ## Command Summary From dc9a769c12687a8b786560e3aeb95ad0eb3a7e3e Mon Sep 17 00:00:00 2001 From: hongyijie06 Date: Fri, 8 Mar 2024 23:24:14 +0800 Subject: [PATCH 28/28] improve formatting, no pictures --- docs/README.md | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/docs/README.md b/docs/README.md index 9e10573a7..096fe006d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,11 +6,6 @@ Chatbot Apple is an app to manage tasks, optimised for use through a Command Lin 1. Ensure Java 11 or above is installed in your computer 2. Download `ip.jar` from [here](https://github.com/hongyijie06/ip/releases/tag/A-Release) 3. Open a command terminal, `cd` into the folder with the jar file and use the `java -jar ip.jar` command to run the application. - -A CLI similar to the picture below should appear in a few seconds. Note how the app returns the path to which the list of tasks is saved on the local computer. - -![welcome](welcome_screen.png) - 4. Type the command into the command line and press Enter to execute it. e.g. typing list and pressing Enter will list the current tasks. Some example commands you can try: @@ -36,9 +31,6 @@ Examples: - `todo tutorial` Adds task `tutorial` to the list of tasks - `todo watch lecture` Adds task `watch lecture` to the list of tasks -The picture below shows the expected output. -![todo](add_todo.png) - ### Add deadline: `deadline` Adds task of type deadline to the list of tasks @@ -48,9 +40,6 @@ Examples: - `deadline return book by 4pm` Adds task `return book` with deadline `4pm` to the list of tasks - `deadline submit group report by 7pm` Adds task `submit group report` with deadline `7pm` to the list of tasks -The picture below shows the expected output. -![deadline](add_deadline.png) - ### Add event: `event` Adds task of type event to the list of tasks @@ -60,17 +49,11 @@ Examples: - `event Math exam from 2pm to 4pm` Adds task `Math exam` with timeline `2pm` to `4pm` to the list of tasks - `event project group meeting from 11am to 1pm` Adds task `project group meeting` with timeline `11am` to `1pm` to the list of tasks -The picture below shows the expected output. -![event](add_event.png) - ## Listing tasks: `list` Lists all tasks in the task list. Format: `list` -The picture below shows the expected output. -![list](list.png) - ## Mark tasks as done: `mark` Marks tasks as completed @@ -84,9 +67,6 @@ Examples: - `mark 1` Marks first task in the list as done - `mark 3` Marks sixth task in the list as done -The picture below shows the expected output. -![mark](mark.png) - ## Unmark tasks: `unmark` Marks tasks as undone @@ -109,9 +89,6 @@ Examples: - `find book` CLI returns a list with all the tasks with the `KEYWORD` `book`. - `find group` CLI returns a list with all the tasks with the `KEYWORD` `group`. -The picture below shows the expected output. -![find](find.png) - ## Delete tasks: `delete` Deletes task from the list of tasks @@ -125,17 +102,11 @@ Examples: - `delete 3` Deletes third task in the list - `delete 5` Deletes fifth task in the list -The picture below shows the expected output. -![delete](delete.png) - ## Exit app: `bye` Exits the chatbot Format: `bye` -The picture below shows the expected output. -![bye](bye.png) - ## Command Summary | Command | Format, Examples |