From 8d479f19e779fcdaf84b969d0065afaf502174d2 Mon Sep 17 00:00:00 2001 From: Your Date: Thu, 31 Aug 2023 03:55:11 -0600 Subject: [PATCH 01/13] Add introduction statements --- src/main/java/Duke.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..a587100a7 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,9 @@ 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 my name is DUKE"); + System.out.println("What can I do for you today?"); + + System.out.println("Fine. If you have no ideas Imma head out"); + } } From 9f133c118c3dcce27919f18eccfccf11ad335f83 Mon Sep 17 00:00:00 2001 From: Your Date: Thu, 31 Aug 2023 11:12:35 -0600 Subject: [PATCH 02/13] Add echo --- src/main/java/Duke.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index a587100a7..a5261aad4 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,8 +1,25 @@ +import java.util.Objects; +import java.util.Scanner; + public class Duke { public static void main(String[] args) { System.out.println("Hello my name is DUKE"); System.out.println("What can I do for you today?"); + boolean echo = true; + while (echo){ + String input; + Scanner scan = new Scanner( System.in ); + input = scan.nextLine(); + if (!input.equals("bye")){ + System.out.println(input); + } + else{ + echo = false; + } + + + } System.out.println("Fine. If you have no ideas Imma head out"); } From d45c1d9a9824139d7fe3f40c53941f636e66c578 Mon Sep 17 00:00:00 2001 From: Your Date: Wed, 6 Sep 2023 08:04:37 -0600 Subject: [PATCH 03/13] Add the list function --- src/main/java/Duke.java | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index a5261aad4..b79de1a48 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,4 +1,4 @@ -import java.util.Objects; +import java.util.ArrayList; import java.util.Scanner; public class Duke { @@ -6,19 +6,35 @@ public static void main(String[] args) { System.out.println("Hello my name is DUKE"); System.out.println("What can I do for you today?"); - boolean echo = true; - while (echo){ + ArrayList commandList = new ArrayList(100); + + Scanner scan = new Scanner( System.in ); + + boolean isEchoing = true; + while (isEchoing){ String input; - Scanner scan = new Scanner( System.in ); input = scan.nextLine(); - if (!input.equals("bye")){ - System.out.println(input); + + if (input.equals("bye")){ + isEchoing = false; + break; } - else{ - echo = false; + + if (!input.equals("list")){ + commandList.add(input); + System.out.println("Added: " + input); + } else if (input.equals("list")){ + for (int i = 0; i < commandList.size(); i++){ + String listItem = commandList.get(i); + System.out.println(i + ": " + listItem); + } } + + + + } System.out.println("Fine. If you have no ideas Imma head out"); From 4f0d7d8a31afb3de847431811927a44929170822 Mon Sep 17 00:00:00 2001 From: Your Date: Wed, 6 Sep 2023 09:34:19 -0600 Subject: [PATCH 04/13] Add task object and marking task ability --- src/main/java/Duke.java | 41 +++++++++++++++++++++++++++++++++-------- src/main/java/Task.java | 25 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index b79de1a48..263719faa 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -3,10 +3,11 @@ public class Duke { public static void main(String[] args) { + System.out.println("Hello my name is DUKE"); System.out.println("What can I do for you today?"); - ArrayList commandList = new ArrayList(100); + ArrayList tasks = new ArrayList<>(100); Scanner scan = new Scanner( System.in ); @@ -20,14 +21,38 @@ public static void main(String[] args) { break; } - if (!input.equals("list")){ - commandList.add(input); - System.out.println("Added: " + input); - } else if (input.equals("list")){ - for (int i = 0; i < commandList.size(); i++){ - String listItem = commandList.get(i); - System.out.println(i + ": " + listItem); + if (input.equals("list")){ + int numOfTasks = 0; + + for (Task task: tasks){ + numOfTasks++; + System.out.println(numOfTasks + ": " + task.getDescription()); } + + } else if (input.toLowerCase().startsWith("mark ")){ + String[] parts = input.split(" "); + + int taskNum = Integer.parseInt(parts[1]); + Task markedTask = tasks.get(taskNum - 1); + + markedTask.isDone = true; + System.out.println("Congrats I marked this class as done : " + markedTask.getDescription()); + + } else if (input.toLowerCase().startsWith("unmark ")) { + String[] parts = input.split(" "); + + int taskNum = Integer.parseInt(parts[1]); + tasks.get(taskNum - 1).isDone = false; + + Task unmarkedTask = tasks.get(taskNum - 1); + + unmarkedTask.isDone = true; + System.out.println("I unmarked this class as done: " + unmarkedTask.getDescription()); + } else { + // Add the task to the list + Task newTask = new Task(input); + tasks.add(newTask); + System.out.println("Added: " + input); } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..0d90dbca7 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,25 @@ +public class Task { + String description; + 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 setDone(boolean done) { + isDone = done; + } + + + public String getDescription() { + return "[" + getStatusIcon() + "] " + description; + } + + + + +} From 23ca33578264ca90ffec2137d87980983af91a10 Mon Sep 17 00:00:00 2001 From: Your Date: Wed, 6 Sep 2023 11:11:37 -0600 Subject: [PATCH 05/13] Add Deadline, event and todo capabilities to mark tasks. --- src/main/java/Deadline.java | 14 ++++++++ src/main/java/Duke.java | 64 ++++++++++++++++++++++++++++++++----- src/main/java/Event.java | 16 ++++++++++ src/main/java/Todo.java | 12 +++++++ 4 files changed, 98 insertions(+), 8 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..9904cd273 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,14 @@ +public class Deadline extends Task { + + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + @Override + public String getDescription() { + return "[D]" + super.getDescription() + " (by: " + by + ")"; + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 263719faa..6e983a8d3 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -16,7 +16,7 @@ public static void main(String[] args) { String input; input = scan.nextLine(); - if (input.equals("bye")){ + if (input.equalsIgnoreCase("bye")){ isEchoing = false; break; } @@ -33,10 +33,14 @@ public static void main(String[] args) { String[] parts = input.split(" "); int taskNum = Integer.parseInt(parts[1]); - Task markedTask = tasks.get(taskNum - 1); + try { + Task markedTask = tasks.get(taskNum - 1); - markedTask.isDone = true; - System.out.println("Congrats I marked this class as done : " + markedTask.getDescription()); + markedTask.isDone = true; + System.out.println("Congrats I marked this class as done : " + markedTask.getDescription()); + } catch (Exception ArrayIndexOutOfBoundsException){ + System.out.println("That task doesnt exist"); + } } else if (input.toLowerCase().startsWith("unmark ")) { String[] parts = input.split(" "); @@ -44,10 +48,54 @@ public static void main(String[] args) { int taskNum = Integer.parseInt(parts[1]); tasks.get(taskNum - 1).isDone = false; - Task unmarkedTask = tasks.get(taskNum - 1); + try { + Task unmarkedTask = tasks.get(taskNum - 1); + + unmarkedTask.isDone = false; + System.out.println("I unmarked this class as done: " + unmarkedTask.getDescription()); + } catch (Exception ArrayIndexOutOfBoundsException){ + System.out.println("That task doesnt exist"); + } + } else if (input.toLowerCase().startsWith("deadline")){ + try { + String[] toDoSplit = input.split("/"); + //First part is task, and last is when by + String desc = toDoSplit[0].substring(9).trim(); // removes "deadline + Deadline deadline = new Deadline(desc, toDoSplit[1].trim()); + System.out.println(deadline.getDescription()); + + tasks.add(deadline); + + } catch (Exception ArrayIndexOutOfBoundsException){ + System.out.println("Put a / after your task if you want to add a todo"); + } + + + } else if (input.toLowerCase().startsWith("event")){ + try { + String[] toDoSplit = input.split("/"); + //First part is task, and last is when by + String desc = toDoSplit[0].substring(6).trim(); + Event event = new Event(desc, toDoSplit[1].trim(), toDoSplit[2].trim()); + System.out.println(event.getDescription()); + tasks.add(event); - unmarkedTask.isDone = true; - System.out.println("I unmarked this class as done: " + unmarkedTask.getDescription()); + } catch (Exception ArrayIndexOutOfBoundsException){ + System.out.println("Put a / after your task if you want to add a todo"); + } + + + } else if (input.toLowerCase().startsWith("todo")) { + try { + String desc = input.substring(4).trim(); + Todo todo = new Todo(desc); + + System.out.println(todo.getDescription()); + tasks.add(todo); + + } catch (Exception e) { + System.out.println("An error occurred while adding the todo."); + } } else { // Add the task to the list Task newTask = new Task(input); @@ -61,7 +109,7 @@ public static void main(String[] args) { } - System.out.println("Fine. If you have no ideas Imma head out"); + System.out.println("Fine. If you have no ideas imma head out"); } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..faa1891f6 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,16 @@ +public class Event extends Task{ + + protected String time; + String start; + String end; + public Event(String description, String start, String end) { + super(description); + this.start = start; + this.end = end; + } + + @Override + public String getDescription() { + return "[E]" + super.getDescription() + " " + start + "-" + end ; + } +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..e55388b03 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,12 @@ +public class Todo extends Task{ + protected String by; + + public Todo(String description) { + super(description); + } + + @Override + public String getDescription() { + return "[T]" + super.getDescription(); + } +} From 4718536b3371364c9fc76ffdb682ff8da79616a7 Mon Sep 17 00:00:00 2001 From: Your Date: Wed, 13 Sep 2023 10:25:42 -0600 Subject: [PATCH 06/13] Added error handling --- src/main/java/Duke.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 6e983a8d3..463513edc 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,11 +1,10 @@ import java.util.ArrayList; import java.util.Scanner; - +//Refactoring methods is helpful for transforming public class Duke { public static void main(String[] args) { - System.out.println("Hello my name is DUKE"); - System.out.println("What can I do for you today?"); + showWelcome(); ArrayList tasks = new ArrayList<>(100); @@ -56,6 +55,7 @@ public static void main(String[] args) { } catch (Exception ArrayIndexOutOfBoundsException){ System.out.println("That task doesnt exist"); } + } else if (input.toLowerCase().startsWith("deadline")){ try { String[] toDoSplit = input.split("/"); @@ -69,6 +69,7 @@ public static void main(String[] args) { } catch (Exception ArrayIndexOutOfBoundsException){ System.out.println("Put a / after your task if you want to add a todo"); } + } else if (input.toLowerCase().startsWith("event")){ @@ -80,8 +81,10 @@ public static void main(String[] args) { System.out.println(event.getDescription()); tasks.add(event); - } catch (Exception ArrayIndexOutOfBoundsException){ + } catch (ArrayIndexOutOfBoundsException e){ System.out.println("Put a / after your task if you want to add a todo"); + } catch (NullPointerException e){ + System.out.println("Please enter a input"); } @@ -112,4 +115,9 @@ public static void main(String[] args) { System.out.println("Fine. If you have no ideas imma head out"); } + + private static void showWelcome() { + System.out.println("Hello my name is DUKE"); + System.out.println("What can I do for you today?"); + } } From 7772ed5cacb2b0ac05d2c932542fe8cef5e1c019 Mon Sep 17 00:00:00 2001 From: Your Date: Wed, 11 Oct 2023 07:29:03 -0600 Subject: [PATCH 07/13] Fix jar file issues --- data/tasks.txt | 8 + src/main - Shortcut.lnk | Bin 0 -> 1009 bytes src/main/java/Deadline.class | Bin 0 -> 981 bytes src/main/java/Deadline.java | 7 + src/main/java/Duke.class | Bin 0 -> 5803 bytes src/main/java/Duke.java | 265 ++++++++++++++++++----------- src/main/java/Event.class | Bin 0 -> 1068 bytes src/main/java/Event.java | 5 + src/main/java/FileSave.class | Bin 0 -> 4517 bytes src/main/java/FileSave.java | 198 +++++++++++++++++++++ src/main/java/META-INF/MANIFEST.MF | 3 + src/main/java/Task.class | Bin 0 -> 1258 bytes src/main/java/Task.java | 8 + src/main/java/Todo.class | Bin 0 -> 876 bytes src/main/java/Todo.java | 5 + storage/tasks.txt | 3 + 16 files changed, 402 insertions(+), 100 deletions(-) create mode 100644 data/tasks.txt create mode 100644 src/main - Shortcut.lnk create mode 100644 src/main/java/Deadline.class create mode 100644 src/main/java/Duke.class create mode 100644 src/main/java/Event.class create mode 100644 src/main/java/FileSave.class create mode 100644 src/main/java/FileSave.java create mode 100644 src/main/java/META-INF/MANIFEST.MF create mode 100644 src/main/java/Task.class create mode 100644 src/main/java/Todo.class create mode 100644 storage/tasks.txt diff --git a/data/tasks.txt b/data/tasks.txt new file mode 100644 index 000000000..682ab9507 --- /dev/null +++ b/data/tasks.txt @@ -0,0 +1,8 @@ +/ /hi +/ / +/ /listioew +/ / +/ / +/ / +/ /clearfile() +/ /FileSave.clearfile() diff --git a/src/main - Shortcut.lnk b/src/main - Shortcut.lnk new file mode 100644 index 0000000000000000000000000000000000000000..5e5cdc133ec8abe42db5d9e4d709990738ba8610 GIT binary patch literal 1009 zcmbVKZAg<*6h5yX-@8e&QVEUhD|)NkxZoHKjD)QV zd5l{1;QO%im9A-GpmK<=VapSCG0;7sAK@v;!u9JK)^{u$%;pKsJy+ zU#REFyZ!y%&{;usR@o(#h>*KOLiEV?kY^yM^hbs456kFHPFJ;s%p_ALTW6YU>;!g} zs88uuM6|Cf91Zb|?r7FtTJ8s0ZW&^+=O2ECKb6<#mixZxCQ_EyHpg1&zwYPIfQD%7 z47h4qkF|cSo_|+IR~x2Miv{DNr_2Sr7r<8_Dg)9ZEu|`|!vJM+!J=Ty0(v)vunX#e zZinun0W_juXi@c^pLH*jL52WMSiM>iOE&D(PON5i4&D7cy&Lv?cHo4$KxPtbD+JVc zuH{pQXPQ4WGv@G_Benq!yi*_2mZFdlG_P7eSZT{gEw4t@2O*6nXcHmzq3Oc~Zs?Zny=3>&gn#1C z&_vUu5B>mulyP=J#Vj$t%-(xv&Y77rv)_N*d;{ncmHtqXA_YOYX&THAPz8q~`tD@bC+LdwP}Y(larMc;LlB*eNCLN1C4(xh!&w}=g$=^yr5MVFRy|=pIOd#Bz7fj!gr^JYi*hZX4+^?% zV>2iy&jlShu6)mJh^{NAedfTO5cdBs!wGBG(0!I5(_$swjW4^>>jZ3sR9la|o(xhD z)_#d~7zj(qzS7$G#uKBr(wytQpGlyQ!XxZhcpUU!BozP5z)@FvC}*RXN^&H6MtiLL z$N5rcfm71gLiJtg7h75n$D?{wp}Cj8fSt)mE(kxJi$CsO$eyXsYdoW92-j^pM%I(q zBiN_SGb)t2lV=4gCsAU-np7ipyirPe4OjTS^et2gyODkuwPE22Vf){qyvoy_S%gbq*hJ{H+48b2z~rZxJ5kI!XT8rnF+9L_SVasEnPE4y`zZ5UitiO1 I;1F9s0V+oAkN^Mx literal 0 HcmV?d00001 diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 9904cd273..8711b4f3c 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -11,4 +11,11 @@ public Deadline(String description, String by) { public String getDescription() { return "[D]" + super.getDescription() + " (by: " + by + ")"; } + + @Override + public String getFileReadableString(){ + return "D" + super.getFileReadableString() + "/" + by; + } + + } diff --git a/src/main/java/Duke.class b/src/main/java/Duke.class new file mode 100644 index 0000000000000000000000000000000000000000..7e4b7492be2d1ee3c9b37d35e63971ef199dcc65 GIT binary patch literal 5803 zcmai231A#$75@I&O=fm8CFw$sV2`0v()0=hjgUYjq*owKD_h#8$T8iWbhp{egq_*8 z5v>;>ltU2Y21S%8g0@A{*ouN8;(-UmUACL4(lwextDDm22-VM@0(Xsnll9-MeI%b-v#j#}v zl;H^I{gR^KlF5RQOPOvh_3I7H5?HXxDLPi(w`{AB_XEr8u`*s?pY3LSYrrd68QZl= zzSB%&O~)L0-rU3ZQKY=Ph5QmY4)b)p(ZunXPyLsbdTARoV%KH&IsTYFr66BuXe$=& zfli)Eed@44N4<%KSTw57L>wACA2>xj@QMP{7u1IuDV&aIzoiOGuvABbi4$=W-J(o4 z0fkn{*?yO^gQlfVH%W?WulXm(gseY1y|%sJJ}-|Oo*lX|V=GKn@U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qliouzN4QyAR)&_4P+xOHw}_!n3!r;1A@oMTA3wmB|5-My-RuE-sPtaE1)pOiJ;W#)Qnssx_PYEPvQEcA>U0ce7*H@FI9rJL zSev?#EBV)c0Cn9p*?suqgJ@N2{b4k9$5I!hyIG3U-4&@^y1O#9HQlYJ3h8bm<)*u9 zDpURGVf=X?UV0GL;Vm^m$&>6pa*EJIC4B()$x2~Rh@;fKM%`2DevG@~ literal 0 HcmV?d00001 diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 463513edc..8305f591b 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,123 +1,188 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; +import java.util.Arrays; //Refactoring methods is helpful for transforming public class Duke { - public static void main(String[] args) { + static ArrayList tasks = new ArrayList<>(100); + static ArrayList commandNames = new ArrayList<>(Arrays.asList("list", "mark", "unmark","delete","deadline","event","todo")); - showWelcome(); - ArrayList tasks = new ArrayList<>(100); + public static void removeTaskFromFile(int index) { + try { + FileSave.removeEntryAtIndex(index); + } catch (IOException e) { + System.out.println(e); + } + } - Scanner scan = new Scanner( System.in ); + public static void showCommands(){ + System.out.println("Here is a list of commands you can use: "); + for (String command: commandNames){ + System.out.println(command); + } + } - boolean isEchoing = true; - while (isEchoing){ - String input; - input = scan.nextLine(); + public static void checkInput(String input) { + //Function to check if the input is a string + } - if (input.equalsIgnoreCase("bye")){ - isEchoing = false; - break; - } + private static void showGoodbye() { + System.out.println("Fine. If you have no ideas imma head out"); + } - if (input.equals("list")){ - int numOfTasks = 0; - - for (Task task: tasks){ - numOfTasks++; - System.out.println(numOfTasks + ": " + task.getDescription()); - } - - } else if (input.toLowerCase().startsWith("mark ")){ - String[] parts = input.split(" "); - - int taskNum = Integer.parseInt(parts[1]); - try { - Task markedTask = tasks.get(taskNum - 1); - - markedTask.isDone = true; - System.out.println("Congrats I marked this class as done : " + markedTask.getDescription()); - } catch (Exception ArrayIndexOutOfBoundsException){ - System.out.println("That task doesnt exist"); - } - - } else if (input.toLowerCase().startsWith("unmark ")) { - String[] parts = input.split(" "); - - int taskNum = Integer.parseInt(parts[1]); - tasks.get(taskNum - 1).isDone = false; - - try { - Task unmarkedTask = tasks.get(taskNum - 1); - - unmarkedTask.isDone = false; - System.out.println("I unmarked this class as done: " + unmarkedTask.getDescription()); - } catch (Exception ArrayIndexOutOfBoundsException){ - System.out.println("That task doesnt exist"); - } - - } else if (input.toLowerCase().startsWith("deadline")){ - try { - String[] toDoSplit = input.split("/"); - //First part is task, and last is when by - String desc = toDoSplit[0].substring(9).trim(); // removes "deadline - Deadline deadline = new Deadline(desc, toDoSplit[1].trim()); - System.out.println(deadline.getDescription()); - - tasks.add(deadline); - - } catch (Exception ArrayIndexOutOfBoundsException){ - System.out.println("Put a / after your task if you want to add a todo"); - } - - - - } else if (input.toLowerCase().startsWith("event")){ - try { - String[] toDoSplit = input.split("/"); - //First part is task, and last is when by - String desc = toDoSplit[0].substring(6).trim(); - Event event = new Event(desc, toDoSplit[1].trim(), toDoSplit[2].trim()); - System.out.println(event.getDescription()); - tasks.add(event); - - } catch (ArrayIndexOutOfBoundsException e){ - System.out.println("Put a / after your task if you want to add a todo"); - } catch (NullPointerException e){ - System.out.println("Please enter a input"); - } - - - } else if (input.toLowerCase().startsWith("todo")) { - try { - String desc = input.substring(4).trim(); - Todo todo = new Todo(desc); - - System.out.println(todo.getDescription()); - tasks.add(todo); - - } catch (Exception e) { - System.out.println("An error occurred while adding the todo."); - } - } else { - // Add the task to the list - Task newTask = new Task(input); - tasks.add(newTask); - System.out.println("Added: " + input); + private static void showWelcome() { + System.out.println("Hello my name is DUKE"); + System.out.println("What can I do for you today? Enter 'help' for a list of commands"); + } + + + private static void saveFile(){ + try { + FileSave.printFileContents(); + } catch (IOException e) { + throw new RuntimeException(e); + } + int numOfTasks = 0; + for (Task task : tasks) { + try { + FileSave.writeToFile(task.getFileReadableString() + System.lineSeparator()); + } catch (IOException e) { + System.out.println(e); } + } + } + + public static void chooseCommand(String input) { + + //checkInput(input); + String[] getKeyword = input.split(" "); + String keyword = getKeyword[0]; + keyword = keyword.toLowerCase(); + String[] parts = input.split(" "); + switch (keyword) { + case ("list"): + int numOfTasks = 0; + for (Task task : tasks) { + numOfTasks++; + System.out.println(numOfTasks + ": " + task.getDescription()); + } + break; + case("help"): + showCommands(); + break; + case ("mark"): + int markedObjectInt = Integer.parseInt(parts[1]); + try { + + Task markedTask = tasks.get(markedObjectInt - 1); + + markedTask.isDone = true; + System.out.println("Congrats I marked this class as done : " + markedTask.getDescription()); + } catch (Exception ArrayIndexOutOfBoundsException) { + System.out.println("That task doesnt exist"); + } + break; + case ("unmark"): + markedObjectInt = Integer.parseInt(parts[1]); + try { + Task unmarkedTask = tasks.get(markedObjectInt - 1); + unmarkedTask.isDone = false; + System.out.println("I unmarked this class as done: " + unmarkedTask.getDescription()); + } catch (Exception ArrayIndexOutOfBoundsException) { + System.out.println("That task doesnt exist"); + } + break; + case("delete"): + int taskToDelete = Integer.parseInt(parts[1]); + tasks.get(taskToDelete - 1).isDone = false; + + removeTaskFromFile(taskToDelete - 1); + try { + Task deleteTask = tasks.get(taskToDelete - 1); + tasks.remove(taskToDelete - 1); + + System.out.println("I deleted this task this class as done: " + deleteTask.getDescription()); + } catch (Exception ArrayIndexOutOfBoundsException) { + System.out.println("That task doesnt exist"); + } + break; + case ("deadline"): + try { + String[] toDoSplit = input.split("/"); + //First part is task, and last is when by + String desc = toDoSplit[0].substring(9).trim(); // removes "deadline + Deadline deadline = new Deadline(desc, toDoSplit[1].trim()); + System.out.println(deadline.getDescription()); + + tasks.add(deadline); + + } catch (Exception ArrayIndexOutOfBoundsException){ + System.out.println("Put a / after your task if you want to add a todo"); + } + break; + case ("event"): + try { + String[] toDoSplit = input.split("/"); + //First part is task, and last is when by + String desc = toDoSplit[0].substring(6).trim(); + Event event = new Event(desc, toDoSplit[1].trim(), toDoSplit[2].trim()); + System.out.println(event.getDescription()); + tasks.add(event); + + } catch (ArrayIndexOutOfBoundsException e){ + System.out.println("Put a /time after description for start and a /time for end"); + } catch (NullPointerException e){ + System.out.println("Please enter a input"); + } + break; + case("todo"): + try { + String desc = input.substring(4).trim(); + Todo todo = new Todo(desc); + + + tasks.add(todo); + + } catch (Exception e) { + System.out.println("An error occurred while adding the todo."); + } + break; + default: + // Add the task to the list + Task newTask = new Task(input); + tasks.add(newTask); + System.out.println("Added: " + input); + break; } - System.out.println("Fine. If you have no ideas imma head out"); + } - private static void showWelcome() { - System.out.println("Hello my name is DUKE"); - System.out.println("What can I do for you today?"); + public static void main(String[] args) throws IOException { + showWelcome(); + + FileSave.loadFileObjects(); + ArrayList fileTasks = FileSave.getFileTasksArray(); + tasks.addAll(fileTasks); + + Scanner scan = new Scanner(System.in); + String input; + input = scan.nextLine(); + while (!input.equalsIgnoreCase("bye")){ + chooseCommand(input); + input = scan.nextLine(); + } + saveFile(); + showGoodbye(); } } + diff --git a/src/main/java/Event.class b/src/main/java/Event.class new file mode 100644 index 0000000000000000000000000000000000000000..8fb9a144a70fb4bfdea6b5c5b9902bc743d437ea GIT binary patch literal 1068 zcmbVLTW=CU6#jARjRNp#oLQPeGqA?K~03zhsK8iCUna(Lv{y}{u6(O zCT*JZ!5`p{GM-(C#Vql`Y;w-*%=dlgGG~7Ny7&R$C7zmyA#NaHA&C@2qRssQL+XVi z9sP=-P--6Y39q_b_Ny)JIkI0XA7qe5#(-(z3M__XV(7opq7_A!+GlvT zAm6A~bZ0@pAjNeHH-Z!kl;WP_icf;~c*hmfPUJx+)HCf21;g|I4Shfob=4z@T+@-_ z!+6*cUONcGV7AoQ>xv*Y{e*qq4K9RX`L$Bo*B&3e7y3x`{9Fn}6I*y-;9=0G5<~Iw z?i@K$12Mb8Y3ufQS1a#?;p=?nGvHKopUa*r{9;q7!FW`Q_HAzGFJk*-Bo@FA=kOmp z$D*ri^PQhb)Vb@n94%^T*bM2z#uv89DlCm1n#=~P(#K%El~Qp o3wYNrc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p}0r+Gv3c@M; x_!<=7)oUmmy`|; fileTasksArray = new ArrayList<>(100); + static Path dirPath = Paths.get("./storage"); + static Path filePath = dirPath.resolve("tasks.txt"); + + public static ArrayList getFileTasksArray() throws IOException { + if (fileTasksArray.isEmpty()) { + loadFileObjects(); + } + return fileTasksArray; + } + + public static void printFileContents() throws IOException { + // Create directory and file if they don't exist + if (!Files.exists(dirPath)) { + Files.createDirectories(dirPath); + } + if (!Files.exists(filePath)) { + Files.createFile(filePath); + } + try (Scanner s = new Scanner(filePath)) { + while (s.hasNext()) { + System.out.println(s.nextLine()); + } + } + } + + public static void loadFileObjects() throws IOException { + // Check for file's existence, and return if it doesn't exist + if (!Files.exists(dirPath)) { + try { + Files.createDirectories(dirPath); + } catch (IOException e) { + System.out.println("Error creating directory: " + e.getMessage()); + return; + } + } + + // Ensure the file exists before reading. If not, create it. + if (!Files.exists(filePath)) { + System.out.println("File does not exist. Creating a new one..."); + try { + Files.createFile(filePath); + } catch (IOException e) { + System.out.println("Error creating file: " + e.getMessage()); + return; + } + } + try (Scanner s = new Scanner(filePath)) { + while (s.hasNext()) { + String entry = s.nextLine(); + + String[] parts = entry.split("/"); + + String keyword = parts[0]; + keyword = keyword.toUpperCase(); + + switch (keyword){ + case("D"): + String isMarked = parts[1]; + if (!Objects.equals(isMarked, "X")){ + //The X should be a space + + String desc = parts[2]; + String time = parts[3]; + Deadline deadline = new Deadline(desc, time); + fileTasksArray.add(deadline); + } else { + + String desc = parts[2]; + String time = parts[3]; + Deadline deadline = new Deadline(desc, time); + deadline.isDone = true; + fileTasksArray.add(deadline); + } + + break; + case("T"): + isMarked = parts[1]; + if (!Objects.equals(isMarked, "X")){ + //The X should be a space + String desc = parts[2]; + Todo todo = new Todo(desc); + fileTasksArray.add(todo); + } else { + String desc = parts[2]; + + Todo todo = new Todo(desc); + todo.isDone = true; + fileTasksArray.add(todo); + } + break; + case("E"): + isMarked = parts[1]; + if (!Objects.equals(isMarked, "X")){ + //The X should be a space + + String desc = parts[2]; + String start = parts[3]; + String end = parts[4]; + Event event = new Event(desc, start, end); + fileTasksArray.add(event); + } else { + + String desc = parts[2]; + String start = parts[3]; + String end = parts[4]; + Event event = new Event(desc, start, end); + event.isDone = true; + fileTasksArray.add(event); + } + default: + //Default case is the case where its not a specific kind of task added + isMarked = parts[0]; + //System.out.println(isMarked); + if (!Objects.equals(isMarked, "X")){ + //System.out.println(parts[2]); + + Task newTask = new Task(parts[2]); + //System.out.println(newTask.getFileReadableString() + "TASK NAME"); + fileTasksArray.add(newTask); + } else{ + Task newTask = new Task(parts[2]); + newTask.isDone = true; + fileTasksArray.add(newTask); + } + + } + + } + } catch (IOException e) { + System.out.println("Error reading file"); + } + } + + //Only writes once Savefile is called in Duke + public static void writeToFile(String textToAdd) throws IOException { + // Ensure the directory exists + if (!Files.exists(dirPath)) { + Files.createDirectories(dirPath); + } + try (FileWriter fw = new FileWriter(filePath.toFile(), true)) { + fw.write(textToAdd); + } + } + + public static void clearFile() throws IOException { + if (!Files.exists(dirPath)) { + Files.createDirectories(dirPath); + } + try (FileWriter fw = new FileWriter(filePath.toFile())) { + // Intentionally left empty to clear the file + } catch (IOException e) { + System.out.println(e.getMessage()); + } + } + + public static void removeEntryAtIndex(int index) throws IOException { + List lines = new ArrayList<>(); + + // Ensure the file exists before reading + if (!Files.exists(filePath)) { + return; + } + + try (BufferedReader br = Files.newBufferedReader(filePath)) { + String line; + while ((line = br.readLine()) != null) { + lines.add(line); + } + } + + // Check if the index is valid and remove the entry + if (index >= 0 && index < lines.size()) { + lines.remove(index); + } + + // Write modified list back to the file + try (FileWriter fw = new FileWriter(filePath.toFile())) { + for (String l : lines) { + fw.write(l + System.lineSeparator()); + } + } + } + +} diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..9f37e4e0a --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Duke + diff --git a/src/main/java/Task.class b/src/main/java/Task.class new file mode 100644 index 0000000000000000000000000000000000000000..2273d0ae3ef11dd4dfef543f735843454ead5431 GIT binary patch literal 1258 zcmb7E+fEZv6kWTwY0I?50&-KV2-p^-DyV4DL`#Sypot}DAU+(XCopuFX*#DQ{E2>n zubPM^Joo{AlyRRP%E!+hkD9CX#hD8>k>eW|KSsFuHOY0lw%p_etwB}|x@ z#5Ka`k*Ldx=UPI&v(*9r@|AFvPgu_PB6~f3=?N2rkv{msHrHP9YFtHT!*=EC*3q79 zZizjIJt-D$)i*_>eK&CHLR*855DZ_cpbwG!j^;~q$*bLc9An3t?Z_@?&=S_vdG%I` znojzcG+FgpO-pJNA)$w}pl87XUV5JLRZ}!Jr8@9xekO*yNi3jb;GS;beZtK7*lhRM ztIJYA8+3I|Sjuaj5I%PIqZ1gAz7lTDk^anv=ha({a&MEnJQsjlCk@#re77q;*v4}A zm^u^{;W$-W$#NWvgy=4P$Wa^*c|av95y4z{UD>QS!uO?bV3{!6Q)oZ^2A&e8E)V5x z4vNK1UfvMzqkj0)U>niv&Swm)3R7%v@NJPJbWEoB15}(pg;5NjBK4JBgdE!}1Hpg@ z0~0WiW@27%jCBZ>_#}?V6u%+$3GwWe&xmG+zOXCQCeZnSBr5{LL*@$u)9jkTEL$yM zx+5W0oV<`({}q7qMOipu?q9|^_G`*?@jFI1t8s>LKqm|o2MLGxcKb5S^`U_fF`l4|@jni+6S@EZ literal 0 HcmV?d00001 diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 0d90dbca7..b834553fe 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -19,6 +19,14 @@ public String getDescription() { return "[" + getStatusIcon() + "] " + description; } + public String getFileDescriptionStatus(){ + return "/" + getStatusIcon() + "/" + description; + } + public String getFileReadableString(){ + //This is in place of the normal getDescription that is returned with the List command + return "/" + getStatusIcon() + "/" + description; + } + diff --git a/src/main/java/Todo.class b/src/main/java/Todo.class new file mode 100644 index 0000000000000000000000000000000000000000..c3ea8f5bee8eec1c9699e1db720b2b484e0ad613 GIT binary patch literal 876 zcmaJ<-EI;=6#foHmf{K(i?#k#TWJMq>;s@)h-oxIO=P1NjTgi2gl^f+ke#7P-^9nz zt0r9d06vuQOqW!2i8p7@?D@X${Qmqk`vKquo>ox6iie_)YbX(lfiPo2>3OVT`;yRT z^-si^I7oyV9Sm$5t5LW8$&t!FR#72TN7BBQCQRdrjkO}Ix7vA5owNBqZlFroI2B{r z(<&79b8L^*PeRVVYzje@ZDN^5IuDkkrwJ=T$_mGGc~ zEj;w_$o05QX#Sa6tj_dU&WD$^eJDb!Q?BUiV#9M_Ci+IGD3PYw*Lpmibn}%j{P~L* zoKNHu_|XFX!|+6gw!65dxkOJS$so3}TgGD^%~9}$%Gl-c1;hh=tCUQ8i7-YQ4=uuO zuFGY`d*~3h{txAo%R0q2Zt;4-3oN36+w85d&&SDjgI_xwb@5VX{{r;=5_yNMI|?u^ zL-J`};fXztcP`+~a2@z|#c`UBN$!@G;A=DR;r@%SaYdWVE8s5f@wdv}eP-`m+9vkq LnorQiJ~n>?%<9kr literal 0 HcmV?d00001 diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index e55388b03..641b39589 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -9,4 +9,9 @@ public Todo(String description) { public String getDescription() { return "[T]" + super.getDescription(); } + + @Override + public String getFileReadableString(){ + return "T" + super.getFileReadableString(); + } } diff --git a/storage/tasks.txt b/storage/tasks.txt new file mode 100644 index 000000000..13d70ea02 --- /dev/null +++ b/storage/tasks.txt @@ -0,0 +1,3 @@ +/ /Hi +/ /Hi +E/ /eat/2 jeo2/2 From aad378baee98f1e65d64a89bb4435310612964a5 Mon Sep 17 00:00:00 2001 From: Your Date: Wed, 11 Oct 2023 09:24:51 -0600 Subject: [PATCH 08/13] Add moreOOP --- src/main/java/Commands.java | 133 +++++++++++++ src/main/java/Deadline.class | Bin 981 -> 0 bytes src/main/java/Duke.class | Bin 5803 -> 0 bytes src/main/java/Duke.java | 184 ++---------------- src/main/java/Event.class | Bin 1068 -> 0 bytes src/main/java/FileSave.class | Bin 4517 -> 0 bytes src/main/java/Parser.java | 19 ++ src/main/java/{FileSave.java => Storage.java} | 40 ++-- src/main/java/Task.class | Bin 1258 -> 0 bytes src/main/java/TasksList.java | 178 +++++++++++++++++ src/main/java/Todo.class | Bin 876 -> 0 bytes src/main/java/Ui.java | 42 ++++ storage/tasks.txt | 3 - 13 files changed, 419 insertions(+), 180 deletions(-) create mode 100644 src/main/java/Commands.java delete mode 100644 src/main/java/Deadline.class delete mode 100644 src/main/java/Duke.class delete mode 100644 src/main/java/Event.class delete mode 100644 src/main/java/FileSave.class create mode 100644 src/main/java/Parser.java rename src/main/java/{FileSave.java => Storage.java} (88%) delete mode 100644 src/main/java/Task.class create mode 100644 src/main/java/TasksList.java delete mode 100644 src/main/java/Todo.class create mode 100644 src/main/java/Ui.java diff --git a/src/main/java/Commands.java b/src/main/java/Commands.java new file mode 100644 index 000000000..83ae9d790 --- /dev/null +++ b/src/main/java/Commands.java @@ -0,0 +1,133 @@ +import java.util.List; + +// 1. Create a Command Interface +interface Command { + void execute(String input, List tasks); +} + +class ListCommand implements Command { + public void execute(String input, List tasks) { + int numOfTasks = 0; + for (Task task : tasks) { + numOfTasks++; + System.out.println(numOfTasks + ": " + task.getDescription()); + } + } +} + +class HelpCommand implements Command { + public void execute(String input, List tasks) { + showCommands(); + } + + private void showCommands() { + // Implement the details of showCommands here. + } +} + +class MarkCommand implements Command { + public void execute(String input, List tasks) { + String[] parts = input.split(" "); + int markedObjectInt = Integer.parseInt(parts[1]); + try { + Task markedTask = tasks.get(markedObjectInt - 1); + markedTask.isDone = true; + System.out.println("Congrats! I marked this task as done: " + markedTask.getDescription()); + } catch (IndexOutOfBoundsException e) { + System.out.println("That task doesn't exist."); + } + } +} + +class UnmarkCommand implements Command { + public void execute(String input, List tasks) { + String[] parts = input.split(" "); + int markedObjectInt = Integer.parseInt(parts[1]); + try { + Task unmarkedTask = tasks.get(markedObjectInt - 1); + unmarkedTask.isDone = false; + System.out.println("I unmarked this task as done: " + unmarkedTask.getDescription()); + } catch (IndexOutOfBoundsException e) { + System.out.println("That task doesn't exist."); + } + } +} + + + +class DeleteCommand implements Command { + public void execute(String input, List tasks) { + String[] parts = input.split(" "); + int taskToDelete = Integer.parseInt(parts[1]); + + // Remove task from file (assuming a method exists for this) + //removeTaskFromFile(taskToDelete - 1); + + try { + Task deleteTask = tasks.get(taskToDelete - 1); + tasks.remove(taskToDelete - 1); + System.out.println("I deleted this task: " + deleteTask.getDescription()); + } catch (IndexOutOfBoundsException e) { + System.out.println("That task doesn't exist"); + } + } +} + +class DeadlineCommand implements Command { + public void execute(String input, List tasks) { + try { + String[] toDoSplit = input.split("/"); + String desc = toDoSplit[0].substring(9).trim(); + Deadline deadline = new Deadline(desc, toDoSplit[1].trim()); + tasks.add(deadline); + System.out.println(deadline.getDescription()); + } catch (IndexOutOfBoundsException e) { + System.out.println("Put a / after your task if you want to add a todo"); + } + } +} + +class EventCommand implements Command { + public void execute(String input, List tasks) { + try { + String[] toDoSplit = input.split("/"); + String desc = toDoSplit[0].substring(6).trim(); + Event event = new Event(desc, toDoSplit[1].trim(), toDoSplit[2].trim()); + tasks.add(event); + System.out.println(event.getDescription()); + } catch (IndexOutOfBoundsException e) { + System.out.println("Put a /time after description for start and a /time for end"); + } catch (NullPointerException e) { + System.out.println("Please enter an input"); + } + } +} + +class TodoCommand implements Command { + public void execute(String input, List tasks) { + try { + String desc = input.substring(4).trim(); + Todo todo = new Todo(desc); + tasks.add(todo); + } catch (Exception e) { + System.out.println("An error occurred while adding the todo."); + } + } +} + +class CommandFactory { + public static Command getCommand(String keyword) { + switch(keyword) { + case "list": return new ListCommand(); + case "help": return new HelpCommand(); + case "mark": return new MarkCommand(); + case "unmark": return new UnmarkCommand(); + case "delete": return new DeleteCommand(); + case "deadline": return new DeadlineCommand(); + case "event": return new EventCommand(); + case "todo": return new TodoCommand(); + //... other cases ... + default: return null; + } + } +} diff --git a/src/main/java/Deadline.class b/src/main/java/Deadline.class deleted file mode 100644 index 5ff68a6658f47310bd2c729190646b375345698c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 981 zcma)5U2hUm5IsXFOX(IU7Hj>eSZT{gEw4t@2O*6nXcHmzq3Oc~Zs?Zny=3>&gn#1C z&_vUu5B>mulyP=J#Vj$t%-(xv&Y77rv)_N*d;{ncmHtqXA_YOYX&THAPz8q~`tD@bC+LdwP}Y(larMc;LlB*eNCLN1C4(xh!&w}=g$=^yr5MVFRy|=pIOd#Bz7fj!gr^JYi*hZX4+^?% zV>2iy&jlShu6)mJh^{NAedfTO5cdBs!wGBG(0!I5(_$swjW4^>>jZ3sR9la|o(xhD z)_#d~7zj(qzS7$G#uKBr(wytQpGlyQ!XxZhcpUU!BozP5z)@FvC}*RXN^&H6MtiLL z$N5rcfm71gLiJtg7h75n$D?{wp}Cj8fSt)mE(kxJi$CsO$eyXsYdoW92-j^pM%I(q zBiN_SGb)t2lV=4gCsAU-np7ipyirPe4OjTS^et2gyODkuwPE22Vf){qyvoy_S%gbq*hJ{H+48b2z~rZxJ5kI!XT8rnF+9L_SVasEnPE4y`zZ5UitiO1 I;1F9s0V+oAkN^Mx diff --git a/src/main/java/Duke.class b/src/main/java/Duke.class deleted file mode 100644 index 7e4b7492be2d1ee3c9b37d35e63971ef199dcc65..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5803 zcmai231A#$75@I&O=fm8CFw$sV2`0v()0=hjgUYjq*owKD_h#8$T8iWbhp{egq_*8 z5v>;>ltU2Y21S%8g0@A{*ouN8;(-UmUACL4(lwextDDm22-VM@0(Xsnll9-MeI%b-v#j#}v zl;H^I{gR^KlF5RQOPOvh_3I7H5?HXxDLPi(w`{AB_XEr8u`*s?pY3LSYrrd68QZl= zzSB%&O~)L0-rU3ZQKY=Ph5QmY4)b)p(ZunXPyLsbdTARoV%KH&IsTYFr66Bu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In&Br^nOR!VhiT7%kdWBhQ8O~;+FxwtE~2=}Nu zb}wd)pnyspO*&p1yR+U`tG}8lC%%THEN_S8f30GKNoW2Iu$qogCQbF%o7od&-ESSnmxuAyVLZWR*UAq2 ztqliouzN4QyAR)&_4P+xOHw}_!n3!r;1A@oMTA3wmB|5-My-RuE-sPtaE1)pOiJ;W#)Qnssx_PYEPvQEcA>U0ce7*H@FI9rJL zSev?#EBV)c0Cn9p*?suqgJ@N2{b4k9$5I!hyIG3U-4&@^y1O#9HQlYJ3h8bm<)*u9 zDpURGVf=X?UV0GL;Vm^m$&>6pa*EJIC4B()$x2~Rh@;fKM%`2DevG@~ diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 8305f591b..47a864392 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -6,183 +6,35 @@ import java.util.Arrays; //Refactoring methods is helpful for transforming public class Duke { - static ArrayList tasks = new ArrayList<>(100); - static ArrayList commandNames = new ArrayList<>(Arrays.asList("list", "mark", "unmark","delete","deadline","event","todo")); - - public static void removeTaskFromFile(int index) { - try { - FileSave.removeEntryAtIndex(index); - } catch (IOException e) { - System.out.println(e); - } - } - - public static void showCommands(){ - System.out.println("Here is a list of commands you can use: "); - for (String command: commandNames){ - System.out.println(command); - } - } - - public static void checkInput(String input) { - //Function to check if the input is a string - } - - private static void showGoodbye() { - System.out.println("Fine. If you have no ideas imma head out"); - } - - private static void showWelcome() { - System.out.println("Hello my name is DUKE"); - System.out.println("What can I do for you today? Enter 'help' for a list of commands"); + private Ui ui; + private Storage storage; + private TasksList taskslist; + public Duke() { + ui = new Ui(); + storage = new Storage(); + taskslist = new TasksList(); } + public void run() throws IOException { + storage.loadFileObjects(); + ArrayList fileTasks = Storage.getFileTasksArray(); - private static void saveFile(){ - try { - FileSave.printFileContents(); - } catch (IOException e) { - throw new RuntimeException(e); - } - int numOfTasks = 0; - for (Task task : tasks) { - try { - FileSave.writeToFile(task.getFileReadableString() + System.lineSeparator()); - } catch (IOException e) { - System.out.println(e); - } + TasksList.getTasks().addAll(fileTasks); + while (!TasksList.isExitProgram()){ + taskslist.chooseCommand(ui.getUserInput()); } + Storage.saveFile(); + TasksList.tasksToBeSaved.clear(); + ui.showGoodbye(); } - public static void chooseCommand(String input) { - - //checkInput(input); - String[] getKeyword = input.split(" "); - - String keyword = getKeyword[0]; - keyword = keyword.toLowerCase(); - - String[] parts = input.split(" "); - - - - switch (keyword) { - case ("list"): - int numOfTasks = 0; - - for (Task task : tasks) { - numOfTasks++; - System.out.println(numOfTasks + ": " + task.getDescription()); - } - break; - case("help"): - showCommands(); - break; - case ("mark"): - int markedObjectInt = Integer.parseInt(parts[1]); - try { - - Task markedTask = tasks.get(markedObjectInt - 1); - - markedTask.isDone = true; - System.out.println("Congrats I marked this class as done : " + markedTask.getDescription()); - } catch (Exception ArrayIndexOutOfBoundsException) { - System.out.println("That task doesnt exist"); - } - break; - case ("unmark"): - markedObjectInt = Integer.parseInt(parts[1]); - try { - Task unmarkedTask = tasks.get(markedObjectInt - 1); - unmarkedTask.isDone = false; - System.out.println("I unmarked this class as done: " + unmarkedTask.getDescription()); - } catch (Exception ArrayIndexOutOfBoundsException) { - System.out.println("That task doesnt exist"); - } - break; - case("delete"): - int taskToDelete = Integer.parseInt(parts[1]); - tasks.get(taskToDelete - 1).isDone = false; - - removeTaskFromFile(taskToDelete - 1); - try { - Task deleteTask = tasks.get(taskToDelete - 1); - tasks.remove(taskToDelete - 1); - - System.out.println("I deleted this task this class as done: " + deleteTask.getDescription()); - } catch (Exception ArrayIndexOutOfBoundsException) { - System.out.println("That task doesnt exist"); - } - break; - case ("deadline"): - try { - String[] toDoSplit = input.split("/"); - //First part is task, and last is when by - String desc = toDoSplit[0].substring(9).trim(); // removes "deadline - Deadline deadline = new Deadline(desc, toDoSplit[1].trim()); - System.out.println(deadline.getDescription()); - - tasks.add(deadline); - - } catch (Exception ArrayIndexOutOfBoundsException){ - System.out.println("Put a / after your task if you want to add a todo"); - } - break; - case ("event"): - try { - String[] toDoSplit = input.split("/"); - //First part is task, and last is when by - String desc = toDoSplit[0].substring(6).trim(); - Event event = new Event(desc, toDoSplit[1].trim(), toDoSplit[2].trim()); - System.out.println(event.getDescription()); - tasks.add(event); - - } catch (ArrayIndexOutOfBoundsException e){ - System.out.println("Put a /time after description for start and a /time for end"); - } catch (NullPointerException e){ - System.out.println("Please enter a input"); - } - break; - case("todo"): - try { - String desc = input.substring(4).trim(); - Todo todo = new Todo(desc); - - - tasks.add(todo); - - } catch (Exception e) { - System.out.println("An error occurred while adding the todo."); - } - break; - default: - // Add the task to the list - Task newTask = new Task(input); - tasks.add(newTask); - System.out.println("Added: " + input); - break; - } - + public static void main(String[] args) throws IOException { + new Duke().run(); - } - public static void main(String[] args) throws IOException { - showWelcome(); - FileSave.loadFileObjects(); - ArrayList fileTasks = FileSave.getFileTasksArray(); - tasks.addAll(fileTasks); - Scanner scan = new Scanner(System.in); - String input; - input = scan.nextLine(); - while (!input.equalsIgnoreCase("bye")){ - chooseCommand(input); - input = scan.nextLine(); - } - saveFile(); - showGoodbye(); } } diff --git a/src/main/java/Event.class b/src/main/java/Event.class deleted file mode 100644 index 8fb9a144a70fb4bfdea6b5c5b9902bc743d437ea..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1068 zcmbVLTW=CU6#jARjRNp#oLQPeGqA?K~03zhsK8iCUna(Lv{y}{u6(O zCT*JZ!5`p{GM-(C#Vql`Y;w-*%=dlgGG~7Ny7&R$C7zmyA#NaHA&C@2qRssQL+XVi z9sP=-P--6Y39q_b_Ny)JIkI0XA7qe5#(-(z3M__XV(7opq7_A!+GlvT zAm6A~bZ0@pAjNeHH-Z!kl;WP_icf;~c*hmfPUJx+)HCf21;g|I4Shfob=4z@T+@-_ z!+6*cUONcGV7AoQ>xv*Y{e*qq4K9RX`L$Bo*B&3e7y3x`{9Fn}6I*y-;9=0G5<~Iw z?i@K$12Mb8Y3ufQS1a#?;p=?nGvHKopUa*r{9;q7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|Ul)dGfhHPUqN+T(n%c1$m#KM8UHP zPLA9vP9~&W$i!9Q%~JFU3awDTatHG>nVKdXNdQTh6%03i&IGV8<|Wp}0r+Gv3c@M; x_!<=7)oUmmy`|; 1) { + return parts[1]; + } else { + return ""; + } + } +} \ No newline at end of file diff --git a/src/main/java/FileSave.java b/src/main/java/Storage.java similarity index 88% rename from src/main/java/FileSave.java rename to src/main/java/Storage.java index 2ab7f4cc6..99212dfda 100644 --- a/src/main/java/FileSave.java +++ b/src/main/java/Storage.java @@ -9,7 +9,7 @@ import java.util.ArrayList; import java.util.List; import java.io.FileNotFoundException; -public class FileSave { +public class Storage { static ArrayList fileTasksArray = new ArrayList<>(100); static Path dirPath = Paths.get("./storage"); @@ -67,10 +67,10 @@ public static void loadFileObjects() throws IOException { String keyword = parts[0]; keyword = keyword.toUpperCase(); - switch (keyword){ - case("D"): + switch (keyword) { + case ("D"): String isMarked = parts[1]; - if (!Objects.equals(isMarked, "X")){ + if (!Objects.equals(isMarked, "X")) { //The X should be a space String desc = parts[2]; @@ -87,9 +87,9 @@ public static void loadFileObjects() throws IOException { } break; - case("T"): + case ("T"): isMarked = parts[1]; - if (!Objects.equals(isMarked, "X")){ + if (!Objects.equals(isMarked, "X")) { //The X should be a space String desc = parts[2]; Todo todo = new Todo(desc); @@ -102,9 +102,9 @@ public static void loadFileObjects() throws IOException { fileTasksArray.add(todo); } break; - case("E"): + case ("E"): isMarked = parts[1]; - if (!Objects.equals(isMarked, "X")){ + if (!Objects.equals(isMarked, "X")) { //The X should be a space String desc = parts[2]; @@ -125,13 +125,13 @@ public static void loadFileObjects() throws IOException { //Default case is the case where its not a specific kind of task added isMarked = parts[0]; //System.out.println(isMarked); - if (!Objects.equals(isMarked, "X")){ + if (!Objects.equals(isMarked, "X")) { //System.out.println(parts[2]); Task newTask = new Task(parts[2]); //System.out.println(newTask.getFileReadableString() + "TASK NAME"); fileTasksArray.add(newTask); - } else{ + } else { Task newTask = new Task(parts[2]); newTask.isDone = true; fileTasksArray.add(newTask); @@ -140,6 +140,8 @@ public static void loadFileObjects() throws IOException { } } + + } catch (IOException e) { System.out.println("Error reading file"); } @@ -167,6 +169,23 @@ public static void clearFile() throws IOException { } } + public static void saveFile() { + try { + Storage.printFileContents(); + } catch (IOException e) { + throw new RuntimeException(e); + } + int numOfTasks = 0; + for (Task task : TasksList.tasksToBeSaved) { + try { + Storage.writeToFile(task.getFileReadableString() + System.lineSeparator()); + } catch (IOException e) { + System.out.println(e); + } + } + } + + public static void removeEntryAtIndex(int index) throws IOException { List lines = new ArrayList<>(); @@ -194,5 +213,4 @@ public static void removeEntryAtIndex(int index) throws IOException { } } } - } diff --git a/src/main/java/Task.class b/src/main/java/Task.class deleted file mode 100644 index 2273d0ae3ef11dd4dfef543f735843454ead5431..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1258 zcmb7E+fEZv6kWTwY0I?50&-KV2-p^-DyV4DL`#Sypot}DAU+(XCopuFX*#DQ{E2>n zubPM^Joo{AlyRRP%E!+hkD9CX#hD8>k>eW|KSsFuHOY0lw%p_etwB}|x@ z#5Ka`k*Ldx=UPI&v(*9r@|AFvPgu_PB6~f3=?N2rkv{msHrHP9YFtHT!*=EC*3q79 zZizjIJt-D$)i*_>eK&CHLR*855DZ_cpbwG!j^;~q$*bLc9An3t?Z_@?&=S_vdG%I` znojzcG+FgpO-pJNA)$w}pl87XUV5JLRZ}!Jr8@9xekO*yNi3jb;GS;beZtK7*lhRM ztIJYA8+3I|Sjuaj5I%PIqZ1gAz7lTDk^anv=ha({a&MEnJQsjlCk@#re77q;*v4}A zm^u^{;W$-W$#NWvgy=4P$Wa^*c|av95y4z{UD>QS!uO?bV3{!6Q)oZ^2A&e8E)V5x z4vNK1UfvMzqkj0)U>niv&Swm)3R7%v@NJPJbWEoB15}(pg;5NjBK4JBgdE!}1Hpg@ z0~0WiW@27%jCBZ>_#}?V6u%+$3GwWe&xmG+zOXCQCeZnSBr5{LL*@$u)9jkTEL$yM zx+5W0oV<`({}q7qMOipu?q9|^_G`*?@jFI1t8s>LKqm|o2MLGxcKb5S^`U_fF`l4|@jni+6S@EZ diff --git a/src/main/java/TasksList.java b/src/main/java/TasksList.java new file mode 100644 index 000000000..ad3b12ece --- /dev/null +++ b/src/main/java/TasksList.java @@ -0,0 +1,178 @@ +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; + +public class TasksList { + + static ArrayList tasks = new ArrayList<>(100); + + static ArrayList commandNames = new ArrayList<>(Arrays.asList("list", "mark", "unmark","delete","deadline","event","todo")); + + static ArrayList tasksToBeSaved = new ArrayList<>(100); + + static boolean exitProgram = false; + + + public static void removeTaskFromFile(int index) { + try { + Storage.removeEntryAtIndex(index); + } catch (IOException e) { + System.out.println(e); + } + } + + public static void setCommandNames(ArrayList commandNames) { + TasksList.commandNames = commandNames; + } + + public static void setTasksToBeSaved(ArrayList tasksToBeSaved) { + TasksList.tasksToBeSaved = tasksToBeSaved; + } + + public static void setExitProgram(boolean exitProgram) { + TasksList.exitProgram = exitProgram; + } + + public static ArrayList getTasks() { + return tasks; + } + + public static ArrayList getCommandNames() { + return commandNames; + } + + public static ArrayList getTasksToBeSaved() { + return tasksToBeSaved; + } + + public static boolean isExitProgram() { + return exitProgram; + } + + public static void showCommands(){ + System.out.println("Here is a list of commands you can use: "); + for (String command: commandNames){ + System.out.println(command); + } + } + + + public static void chooseCommand(String input) { + + //checkInput(input); + String[] getKeyword = input.split(" "); + + String keyword = getKeyword[0]; + keyword = keyword.toLowerCase(); + + String[] parts = input.split(" "); + + + + switch (keyword) { + case ("list"): + int numOfTasks = 0; + + for (Task task : tasks) { + numOfTasks++; + System.out.println(numOfTasks + ": " + task.getDescription()); + } + break; + case("help"): + showCommands(); + break; + case ("mark"): + int markedObjectInt = Integer.parseInt(parts[1]); + try { + + Task markedTask = tasks.get(markedObjectInt - 1); + + markedTask.isDone = true; + System.out.println("Congrats I marked this class as done : " + markedTask.getDescription()); + } catch (Exception ArrayIndexOutOfBoundsException) { + System.out.println("That task doesnt exist"); + } + break; + case ("unmark"): + markedObjectInt = Integer.parseInt(parts[1]); + try { + Task unmarkedTask = tasks.get(markedObjectInt - 1); + unmarkedTask.isDone = false; + System.out.println("I unmarked this class as done: " + unmarkedTask.getDescription()); + } catch (Exception ArrayIndexOutOfBoundsException) { + System.out.println("That task doesnt exist"); + } + break; + case("delete"): + int taskToDelete = Integer.parseInt(parts[1]); + tasks.get(taskToDelete - 1).isDone = false; + + removeTaskFromFile(taskToDelete - 1); + try { + Task deleteTask = tasks.get(taskToDelete - 1); + tasks.remove(taskToDelete - 1); + + System.out.println("I deleted this task this class as done: " + deleteTask.getDescription()); + } catch (Exception ArrayIndexOutOfBoundsException) { + System.out.println("That task doesnt exist"); + } + break; + case ("deadline"): + try { + String[] toDoSplit = input.split("/"); + //First part is task, and last is when by + String desc = toDoSplit[0].substring(9).trim(); // removes "deadline + Deadline deadline = new Deadline(desc, toDoSplit[1].trim()); + System.out.println(deadline.getDescription()); + + tasks.add(deadline); + tasksToBeSaved.add(deadline); + } catch (Exception ArrayIndexOutOfBoundsException){ + System.out.println("Put a / after your task if you want to add a todo"); + } + break; + case ("event"): + try { + String[] toDoSplit = input.split("/"); + //First part is task, and last is when by + String desc = toDoSplit[0].substring(6).trim(); + Event event = new Event(desc, toDoSplit[1].trim(), toDoSplit[2].trim()); + System.out.println(event.getDescription()); + tasks.add(event); + tasksToBeSaved.add(event); + + } catch (ArrayIndexOutOfBoundsException e){ + System.out.println("Put a /time after description for start and a /time for end"); + } catch (NullPointerException e){ + System.out.println("Please enter a input"); + } + break; + case("todo"): + try { + String desc = input.substring(4).trim(); + Todo todo = new Todo(desc); + + + tasks.add(todo); + tasksToBeSaved.add(todo); + + } catch (Exception e) { + System.out.println("An error occurred while adding the todo."); + } + break; + + case("bye"): + exitProgram = true; + break; + default: + // Add the task to the list + Task newTask = new Task(input); + tasks.add(newTask); + tasksToBeSaved.add(newTask); + System.out.println("Added: " + input); + break; + } + + + } +} diff --git a/src/main/java/Todo.class b/src/main/java/Todo.class deleted file mode 100644 index c3ea8f5bee8eec1c9699e1db720b2b484e0ad613..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 876 zcmaJ<-EI;=6#foHmf{K(i?#k#TWJMq>;s@)h-oxIO=P1NjTgi2gl^f+ke#7P-^9nz zt0r9d06vuQOqW!2i8p7@?D@X${Qmqk`vKquo>ox6iie_)YbX(lfiPo2>3OVT`;yRT z^-si^I7oyV9Sm$5t5LW8$&t!FR#72TN7BBQCQRdrjkO}Ix7vA5owNBqZlFroI2B{r z(<&79b8L^*PeRVVYzje@ZDN^5IuDkkrwJ=T$_mGGc~ zEj;w_$o05QX#Sa6tj_dU&WD$^eJDb!Q?BUiV#9M_Ci+IGD3PYw*Lpmibn}%j{P~L* zoKNHu_|XFX!|+6gw!65dxkOJS$so3}TgGD^%~9}$%Gl-c1;hh=tCUQ8i7-YQ4=uuO zuFGY`d*~3h{txAo%R0q2Zt;4-3oN36+w85d&&SDjgI_xwb@5VX{{r;=5_yNMI|?u^ zL-J`};fXztcP`+~a2@z|#c`UBN$!@G;A=DR;r@%SaYdWVE8s5f@wdv}eP-`m+9vkq LnorQiJ~n>?%<9kr diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 000000000..a45d8f676 --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,42 @@ +import java.util.Scanner; +import java.util.ArrayList; +public class Ui { + + private final Scanner scanner; + + public Ui() { + this.scanner = new Scanner(System.in); + } + + // Display a welcome message to the user + public void showWelcome() { + System.out.println("Hello my name is DUKE"); + System.out.println("What can I do for you today? Enter 'help' for a list of commands"); + } + + // Display a goodbye message when the user decides to exit + public void showGoodbye() { + System.out.println("Fine. If you have no ideas imma head out"); + } + + // Show the list of commands to the user + public void showCommands(ArrayList commandNames) { + System.out.println("Here is a list of commands you can use: "); + for (String command: commandNames){ + System.out.println(command); + } + } + + // Capture and return user input + public String getUserInput() { + return scanner.nextLine(); + } + + public void showError(String message) { + System.out.println("Error: " + message); + } + + public void showMessage(String message) { + System.out.println(message); + } +} diff --git a/storage/tasks.txt b/storage/tasks.txt index 13d70ea02..e69de29bb 100644 --- a/storage/tasks.txt +++ b/storage/tasks.txt @@ -1,3 +0,0 @@ -/ /Hi -/ /Hi -E/ /eat/2 jeo2/2 From 92b1dcfc942ca78cc40ea39a33737def46ec5cba Mon Sep 17 00:00:00 2001 From: Your Date: Thu, 12 Oct 2023 06:40:42 -0600 Subject: [PATCH 09/13] Add ability to search entries with find command --- src/main/java/Storage.java | 2 ++ src/main/java/TasksList.java | 18 +++++++++++++++++- storage/tasks.txt | 4 ++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 99212dfda..333bc4371 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -40,6 +40,7 @@ public static void printFileContents() throws IOException { public static void loadFileObjects() throws IOException { // Check for file's existence, and return if it doesn't exist if (!Files.exists(dirPath)) { + System.out.println("Dir does not exist. Creating a new one..."); try { Files.createDirectories(dirPath); } catch (IOException e) { @@ -58,6 +59,7 @@ public static void loadFileObjects() throws IOException { return; } } + try (Scanner s = new Scanner(filePath)) { while (s.hasNext()) { String entry = s.nextLine(); diff --git a/src/main/java/TasksList.java b/src/main/java/TasksList.java index ad3b12ece..e724340ae 100644 --- a/src/main/java/TasksList.java +++ b/src/main/java/TasksList.java @@ -6,7 +6,8 @@ public class TasksList { static ArrayList tasks = new ArrayList<>(100); - static ArrayList commandNames = new ArrayList<>(Arrays.asList("list", "mark", "unmark","delete","deadline","event","todo")); + + static ArrayList commandNames = new ArrayList<>(Arrays.asList("list", "mark", "unmark","delete","deadline","event","todo", "find")); static ArrayList tasksToBeSaved = new ArrayList<>(100); @@ -160,6 +161,9 @@ public static void chooseCommand(String input) { System.out.println("An error occurred while adding the todo."); } break; + case("find"): + searchAndDisplayTasks(parts[1]); + break; case("bye"): exitProgram = true; @@ -173,6 +177,18 @@ public static void chooseCommand(String input) { break; } + } + + public static void searchAndDisplayTasks(String keyword) { + System.out.println("____________________________________________________________"); + System.out.println("Here are the matching tasks in your list:"); + int count = 1; + for (Task task : tasks) { + if (task.getDescription().toLowerCase().contains(keyword.toLowerCase())) { + System.out.println(count + "." + task.getDescription()); + count++; + } + } } } diff --git a/storage/tasks.txt b/storage/tasks.txt index e69de29bb..333791aec 100644 --- a/storage/tasks.txt +++ b/storage/tasks.txt @@ -0,0 +1,4 @@ +/ /hi +/ /fa +/ /hope +/ /hope to From 3e90ffed3bc3406ee3d82e05acd4f871bb0e4d91 Mon Sep 17 00:00:00 2001 From: Your Date: Thu, 12 Oct 2023 07:22:25 -0600 Subject: [PATCH 10/13] Add Javadoc comments to method. --- src/main/java/Deadline.java | 9 ++++ src/main/java/Duke.java | 7 +-- src/main/java/Event.java | 7 +++ src/main/java/Parser.java | 19 -------- src/main/java/Storage.java | 87 ++++++++++++++++++++++++++---------- src/main/java/Task.java | 10 ++++- src/main/java/TasksList.java | 37 +++++++-------- src/main/java/Todo.java | 5 +++ src/main/java/Ui.java | 2 + storage/tasks.txt | 4 -- 10 files changed, 116 insertions(+), 71 deletions(-) delete mode 100644 src/main/java/Parser.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 8711b4f3c..bd444b658 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,17 +1,26 @@ +/** + * Deadline is an extension of the Task object. Use to denote when something is due. + * @author Isaiah Cerven + * @version 1.0 + */ + public class Deadline extends Task { protected String by; + public Deadline(String description, String by) { super(description); this.by = by; } + // getDescription prints human-readable tasks when called. @Override public String getDescription() { return "[D]" + super.getDescription() + " (by: " + by + ")"; } + //getFileReadableString() prints tasks and their parameters. Separates them by a '/' to be parsed in txt file. @Override public String getFileReadableString(){ return "D" + super.getFileReadableString() + "/" + by; diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 47a864392..86b9ad510 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -5,6 +5,10 @@ import java.util.Scanner; import java.util.Arrays; //Refactoring methods is helpful for transforming + +/** + * Main class of program. Creates UI, Storage and Task objects and runs program. + */ public class Duke { private Ui ui; @@ -32,9 +36,6 @@ public void run() throws IOException { public static void main(String[] args) throws IOException { new Duke().run(); - - - } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 3a7f94369..ac1dd6c18 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,3 +1,8 @@ +/** + * Event is an extension of the Task object. Use to schedule a task between an x and y time. + * @author Isaiah Cerven + * @version 1.0 + */ public class Event extends Task{ protected String time; @@ -9,11 +14,13 @@ public Event(String description, String start, String end) { this.end = end; } + // getDescription prints human-readable tasks when called. @Override public String getDescription() { return "[E]" + super.getDescription() + " " + start + "-" + end ; } + //getFileReadableString() prints tasks and their parameters. Separates them by a '/' to be parsed in txt file. @Override public String getFileReadableString(){ return "E" + super.getFileReadableString() + "/" + start + "/" + end ; diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java deleted file mode 100644 index aecd78be0..000000000 --- a/src/main/java/Parser.java +++ /dev/null @@ -1,19 +0,0 @@ -public class Parser { - - public static String[] parseInput(String input) { - return input.split(" ", 2); - } - - public static String getCommand(String input) { - return parseInput(input)[0]; - } - - public static String getArgs(String input) { - String[] parts = parseInput(input); - if (parts.length > 1) { - return parts[1]; - } else { - return ""; - } - } -} \ No newline at end of file diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 333bc4371..c534c8d8c 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -9,12 +9,25 @@ import java.util.ArrayList; import java.util.List; import java.io.FileNotFoundException; + +/** + * Storage saves and loads previous trials using a text file. + * @author Isaiah Cerven + * @version 1.0 + */ public class Storage { + //fileTasksArray stores all tasks that are to be loaded static ArrayList fileTasksArray = new ArrayList<>(100); static Path dirPath = Paths.get("./storage"); static Path filePath = dirPath.resolve("tasks.txt"); + /** + * A get function to allow Duke to view the stored Task objects + * + * @return ArrayList + * @throws IOException + */ public static ArrayList getFileTasksArray() throws IOException { if (fileTasksArray.isEmpty()) { loadFileObjects(); @@ -22,6 +35,10 @@ public static ArrayList getFileTasksArray() throws IOException { return fileTasksArray; } + /** + * Prints all text file contents + * @throws IOException + */ public static void printFileContents() throws IOException { // Create directory and file if they don't exist if (!Files.exists(dirPath)) { @@ -37,40 +54,34 @@ public static void printFileContents() throws IOException { } } - public static void loadFileObjects() throws IOException { - // Check for file's existence, and return if it doesn't exist - if (!Files.exists(dirPath)) { - System.out.println("Dir does not exist. Creating a new one..."); - try { - Files.createDirectories(dirPath); - } catch (IOException e) { - System.out.println("Error creating directory: " + e.getMessage()); - return; - } - } + /** + * Checks text file for different Tasks objects and loads them. + * Each Task Starts with the Task letter, with their parameters separated by a '/' + * Non denoted Task is the exception and isnt marked. + * @throws IOException + */ - // Ensure the file exists before reading. If not, create it. - if (!Files.exists(filePath)) { - System.out.println("File does not exist. Creating a new one..."); - try { - Files.createFile(filePath); - } catch (IOException e) { - System.out.println("Error creating file: " + e.getMessage()); - return; - } - } + + public static void loadFileObjects() throws IOException { + // Check for file's existence, and create one if it doesn't exist + checkFileExists(); try (Scanner s = new Scanner(filePath)) { while (s.hasNext()) { + //entry is the task on each line. String entry = s.nextLine(); + //Separate the Tasks into components. String[] parts = entry.split("/"); + //Get the first word as keyword. String keyword = parts[0]; keyword = keyword.toUpperCase(); + switch (keyword) { case ("D"): + //Is marked, is if a task is finished and is shown in the txt file as 'X' String isMarked = parts[1]; if (!Objects.equals(isMarked, "X")) { //The X should be a space @@ -149,7 +160,35 @@ public static void loadFileObjects() throws IOException { } } - //Only writes once Savefile is called in Duke + /** + * Default check to see if text file data/tasks.txt exists. If not create it. + */ + private static void checkFileExists(){ + if (!Files.exists(dirPath)) { + System.out.println("Dir does not exist. Creating a new one..."); + try { + Files.createDirectories(dirPath); + } catch (IOException e) { + System.out.println("Error creating directory: " + e.getMessage()); + return; + } + } + + // Ensure the file exists before reading. If not, create it. + if (!Files.exists(filePath)) { + System.out.println("File does not exist. Creating a new one..."); + try { + Files.createFile(filePath); + } catch (IOException e) { + System.out.println("Error creating file: " + e.getMessage()); + return; + } + } + } + + + + //Called with Save file. Appends latest task to text file. public static void writeToFile(String textToAdd) throws IOException { // Ensure the directory exists if (!Files.exists(dirPath)) { @@ -160,6 +199,7 @@ public static void writeToFile(String textToAdd) throws IOException { } } + //Clears Text file public static void clearFile() throws IOException { if (!Files.exists(dirPath)) { Files.createDirectories(dirPath); @@ -171,6 +211,7 @@ public static void clearFile() throws IOException { } } + //Saves tasks from this run to text file. public static void saveFile() { try { Storage.printFileContents(); @@ -187,7 +228,7 @@ public static void saveFile() { } } - + //Use for removing different tasks from text file. public static void removeEntryAtIndex(int index) throws IOException { List lines = new ArrayList<>(); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index b834553fe..f2358eb01 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,3 +1,8 @@ +/** + * Task stores the users task description and done status.Specific Task types are extended from this class. + * @author Isaiah Cerven + * @version 1.0 + */ public class Task { String description; protected boolean isDone; @@ -6,6 +11,7 @@ public Task(String description) { this.description = description; this.isDone = false; } + // Mark tasks as done public String getStatusIcon() { return (isDone ? "X" : " "); // mark done task with X } @@ -14,7 +20,7 @@ public void setDone(boolean done) { isDone = done; } - + // getDescription prints human-readable tasks when called. public String getDescription() { return "[" + getStatusIcon() + "] " + description; } @@ -22,6 +28,8 @@ public String getDescription() { public String getFileDescriptionStatus(){ return "/" + getStatusIcon() + "/" + description; } + + //getFileReadableString() prints tasks and their parameters. Separates them by a '/' to be parsed in txt file. public String getFileReadableString(){ //This is in place of the normal getDescription that is returned with the List command return "/" + getStatusIcon() + "/" + description; diff --git a/src/main/java/TasksList.java b/src/main/java/TasksList.java index e724340ae..b9e93f54a 100644 --- a/src/main/java/TasksList.java +++ b/src/main/java/TasksList.java @@ -2,6 +2,12 @@ import java.util.ArrayList; import java.util.Arrays; +/** + * Contains a list of all commands to instantiate different tasks. + * UI directly uses this to input tasks. + * @author Isaiah Cerven + * @version 1.0 + */ public class TasksList { static ArrayList tasks = new ArrayList<>(100); @@ -22,34 +28,17 @@ public static void removeTaskFromFile(int index) { } } - public static void setCommandNames(ArrayList commandNames) { - TasksList.commandNames = commandNames; - } - - public static void setTasksToBeSaved(ArrayList tasksToBeSaved) { - TasksList.tasksToBeSaved = tasksToBeSaved; - } - - public static void setExitProgram(boolean exitProgram) { - TasksList.exitProgram = exitProgram; - } public static ArrayList getTasks() { return tasks; } - public static ArrayList getCommandNames() { - return commandNames; - } - - public static ArrayList getTasksToBeSaved() { - return tasksToBeSaved; - } - + //Sets a variable to false if program can be exited public static boolean isExitProgram() { return exitProgram; } + //Prints all commands public static void showCommands(){ System.out.println("Here is a list of commands you can use: "); for (String command: commandNames){ @@ -57,7 +46,10 @@ public static void showCommands(){ } } - + /** + * Handles parsing UI commands and creating tasks from them + * @param input + */ public static void chooseCommand(String input) { //checkInput(input); @@ -179,8 +171,11 @@ public static void chooseCommand(String input) { } + /** + * Use for find case. Finds specific tasks with keyword + * @param keyword + */ public static void searchAndDisplayTasks(String keyword) { - System.out.println("____________________________________________________________"); System.out.println("Here are the matching tasks in your list:"); int count = 1; diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 641b39589..b0e63d262 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -1,3 +1,8 @@ +/** + * Todo is an extension of the Task object. Use to make task and due date. + * @author Isaiah Cerven + * @version 1.0 + */ public class Todo extends Task{ protected String by; diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index a45d8f676..550219ffa 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,5 +1,7 @@ import java.util.Scanner; import java.util.ArrayList; + +//UI captures user input and talks to the TasksList class to interpret command. public class Ui { private final Scanner scanner; diff --git a/storage/tasks.txt b/storage/tasks.txt index 333791aec..e69de29bb 100644 --- a/storage/tasks.txt +++ b/storage/tasks.txt @@ -1,4 +0,0 @@ -/ /hi -/ /fa -/ /hope -/ /hope to From 412181f4efd526b99ea78e8ea448e189146a1f2c Mon Sep 17 00:00:00 2001 From: Your Date: Thu, 12 Oct 2023 07:38:38 -0600 Subject: [PATCH 11/13] Update readme --- docs/README.md | 74 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..ec2001b85 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,71 @@ -# User Guide +# Duke Chatbot -## Features +[User Guide](#user-guide) | [About Us](#about-us) | [View on GitHub](https://github.com/your-github-link-here) -### Feature-ABC +## User Guide -Description of the feature. +### Introduction +The Duke Chatbot is a desktop app optimized for managing tasks and events, making use of a Command Line Interface (CLI) whilst offering the benefits of a Graphical User Interface (GUI). If you're a fast typer, our chatbot will help you manage your tasks more efficiently than traditional GUI apps. -### Feature-XYZ +#### Quick Start: -Description of the feature. +1. Ensure you have Java 11 or above installed on your computer. +2. Download the latest jar file. +3. Copy the file to the folder you want to use as the home directory for your Chatbot. +4. Open a command terminal, navigate to the folder containing the jar file, and run the chatbot using the `java -jar chatbot.jar` command. -## Usage +#### Features -### `Keyword` - Describe action +:information_source: **Notes about the command format:** +- Commands are not case-sensitive. For instance, `list` and `LIST` will function identically. +- Parameters that need to be supplied by the user are in UPPER_CASE. For example, in the `find KEYWORD`, KEYWORD is a parameter to be provided, like `find homework`. -Describe the action and its outcome. +#### Commands -Example of usage: +- **List**: Shows all tasks. + - Format: `list` -`keyword (optional arguments)` +- **Mark**: Marks a task as done. + - Format: `mark TASK_INDEX` + - Example: `mark 2` marks the second task as done. -Expected outcome: +- **Unmark**: Unmarks a task. + - Format: `unmark TASK_INDEX` + - Example: `unmark 2` unmarks the second task. -Description of the outcome. +- **Delete**: Deletes a task. + - Format: `delete TASK_INDEX` + - Example: `delete 2` deletes the second task. + +- **Deadline**: Adds a task with a deadline. + - Format: `deadline TASK_NAME /by DATE_TIME` + - Example: `deadline Submit Homework /by 2023-10-15 1800` + +- **Event**: Adds an event. + - Format: `event EVENT_NAME /at DATE_TIME` + - Example: `event Team Meeting /at 2023-10-20 1400` + +- **Todo**: Adds a to-do task. + - Format: `todo TASK_NAME` + - Example: `todo Read Book` + +- **Find**: Searches tasks containing the keyword. + - Format: `find KEYWORD` + - Example: `find meeting` returns all tasks containing the word 'meeting'. + +#### FAQ +- **Q: How can I backup my tasks?** + - A: All tasks are automatically saved in the hard drive after every command that modifies data. To backup, simply copy the saved data file and store it in a safe location. + +#### Command Summary +| Action | Format, Examples | +|-----------|-----------------------------------------------------------------------------------| +| List | `list` | +| Mark | `mark TASK_INDEX` e.g., `mark 2` | +| Unmark | `unmark TASK_INDEX` e.g., `unmark 2` | +| Delete | `delete TASK_INDEX` e.g., `delete 2` | +| Deadline | `deadline TASK_NAME /by DATE_TIME` e.g., `deadline Submit Homework /by 2023-10-15`| +| Event | `event EVENT_NAME /at DATE_TIME` e.g., `event Team Meeting /at 2023-10-20` | +| Todo | `todo TASK_NAME` e.g., `todo Read Book` | +| Find | `find KEYWORD` e.g., `find meeting` | -``` -expected output -``` From f4eb8e38e55fc7b08f7e9f6849e0f396a4d71c62 Mon Sep 17 00:00:00 2001 From: Your Date: Mon, 23 Oct 2023 01:40:46 -0600 Subject: [PATCH 12/13] fix exceptions in commands such as no input. Clarify no commands specified --- data/tasks.txt | 8 --- src/main/java/Commands.java | 133 ----------------------------------- src/main/java/Duke.java | 14 +++- src/main/java/TasksList.java | 87 +++++++++++++++-------- src/main/java/Ui.java | 13 +++- 5 files changed, 81 insertions(+), 174 deletions(-) delete mode 100644 data/tasks.txt delete mode 100644 src/main/java/Commands.java diff --git a/data/tasks.txt b/data/tasks.txt deleted file mode 100644 index 682ab9507..000000000 --- a/data/tasks.txt +++ /dev/null @@ -1,8 +0,0 @@ -/ /hi -/ / -/ /listioew -/ / -/ / -/ / -/ /clearfile() -/ /FileSave.clearfile() diff --git a/src/main/java/Commands.java b/src/main/java/Commands.java deleted file mode 100644 index 83ae9d790..000000000 --- a/src/main/java/Commands.java +++ /dev/null @@ -1,133 +0,0 @@ -import java.util.List; - -// 1. Create a Command Interface -interface Command { - void execute(String input, List tasks); -} - -class ListCommand implements Command { - public void execute(String input, List tasks) { - int numOfTasks = 0; - for (Task task : tasks) { - numOfTasks++; - System.out.println(numOfTasks + ": " + task.getDescription()); - } - } -} - -class HelpCommand implements Command { - public void execute(String input, List tasks) { - showCommands(); - } - - private void showCommands() { - // Implement the details of showCommands here. - } -} - -class MarkCommand implements Command { - public void execute(String input, List tasks) { - String[] parts = input.split(" "); - int markedObjectInt = Integer.parseInt(parts[1]); - try { - Task markedTask = tasks.get(markedObjectInt - 1); - markedTask.isDone = true; - System.out.println("Congrats! I marked this task as done: " + markedTask.getDescription()); - } catch (IndexOutOfBoundsException e) { - System.out.println("That task doesn't exist."); - } - } -} - -class UnmarkCommand implements Command { - public void execute(String input, List tasks) { - String[] parts = input.split(" "); - int markedObjectInt = Integer.parseInt(parts[1]); - try { - Task unmarkedTask = tasks.get(markedObjectInt - 1); - unmarkedTask.isDone = false; - System.out.println("I unmarked this task as done: " + unmarkedTask.getDescription()); - } catch (IndexOutOfBoundsException e) { - System.out.println("That task doesn't exist."); - } - } -} - - - -class DeleteCommand implements Command { - public void execute(String input, List tasks) { - String[] parts = input.split(" "); - int taskToDelete = Integer.parseInt(parts[1]); - - // Remove task from file (assuming a method exists for this) - //removeTaskFromFile(taskToDelete - 1); - - try { - Task deleteTask = tasks.get(taskToDelete - 1); - tasks.remove(taskToDelete - 1); - System.out.println("I deleted this task: " + deleteTask.getDescription()); - } catch (IndexOutOfBoundsException e) { - System.out.println("That task doesn't exist"); - } - } -} - -class DeadlineCommand implements Command { - public void execute(String input, List tasks) { - try { - String[] toDoSplit = input.split("/"); - String desc = toDoSplit[0].substring(9).trim(); - Deadline deadline = new Deadline(desc, toDoSplit[1].trim()); - tasks.add(deadline); - System.out.println(deadline.getDescription()); - } catch (IndexOutOfBoundsException e) { - System.out.println("Put a / after your task if you want to add a todo"); - } - } -} - -class EventCommand implements Command { - public void execute(String input, List tasks) { - try { - String[] toDoSplit = input.split("/"); - String desc = toDoSplit[0].substring(6).trim(); - Event event = new Event(desc, toDoSplit[1].trim(), toDoSplit[2].trim()); - tasks.add(event); - System.out.println(event.getDescription()); - } catch (IndexOutOfBoundsException e) { - System.out.println("Put a /time after description for start and a /time for end"); - } catch (NullPointerException e) { - System.out.println("Please enter an input"); - } - } -} - -class TodoCommand implements Command { - public void execute(String input, List tasks) { - try { - String desc = input.substring(4).trim(); - Todo todo = new Todo(desc); - tasks.add(todo); - } catch (Exception e) { - System.out.println("An error occurred while adding the todo."); - } - } -} - -class CommandFactory { - public static Command getCommand(String keyword) { - switch(keyword) { - case "list": return new ListCommand(); - case "help": return new HelpCommand(); - case "mark": return new MarkCommand(); - case "unmark": return new UnmarkCommand(); - case "delete": return new DeleteCommand(); - case "deadline": return new DeadlineCommand(); - case "event": return new EventCommand(); - case "todo": return new TodoCommand(); - //... other cases ... - default: return null; - } - } -} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 86b9ad510..8cd2752c1 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -21,14 +21,22 @@ public Duke() { } public void run() throws IOException { - storage.loadFileObjects(); + //Add all previous run tasks + Storage.loadFileObjects(); ArrayList fileTasks = Storage.getFileTasksArray(); - TasksList.getTasks().addAll(fileTasks); + + ui.showWelcome(); while (!TasksList.isExitProgram()){ - taskslist.chooseCommand(ui.getUserInput()); + String input = ui.getUserInput(); + if (ui.checkUserInput(input)) { + taskslist.chooseCommand(input); + } + } Storage.saveFile(); + + //yo TasksList.tasksToBeSaved.clear(); ui.showGoodbye(); } diff --git a/src/main/java/TasksList.java b/src/main/java/TasksList.java index b9e93f54a..870fcbe81 100644 --- a/src/main/java/TasksList.java +++ b/src/main/java/TasksList.java @@ -40,7 +40,7 @@ public static boolean isExitProgram() { //Prints all commands public static void showCommands(){ - System.out.println("Here is a list of commands you can use: "); + System.out.print("Here is a list of commands you can use: "); for (String command: commandNames){ System.out.println(command); } @@ -51,7 +51,6 @@ public static void showCommands(){ * @param input */ public static void chooseCommand(String input) { - //checkInput(input); String[] getKeyword = input.split(" "); @@ -66,18 +65,28 @@ public static void chooseCommand(String input) { case ("list"): int numOfTasks = 0; - for (Task task : tasks) { - numOfTasks++; - System.out.println(numOfTasks + ": " + task.getDescription()); + + if (!tasks.isEmpty()){ + for (Task task : tasks) { + numOfTasks++; + System.out.println(numOfTasks + ": " + task.getDescription()); + } + } else if (parts.length > 1) { + System.out.println("No other command is needed besides 'list'"); + } else { + System.out.println("You currently have no tasks."); } + break; case("help"): + System.out.println("Disclaimer: No command entered will result in the input to be "); + System.out.println("entered as a task without a deadline. (Clone Assignment) "); showCommands(); break; case ("mark"): - int markedObjectInt = Integer.parseInt(parts[1]); - try { + try { + int markedObjectInt = Integer.parseInt(parts[1]); Task markedTask = tasks.get(markedObjectInt - 1); markedTask.isDone = true; @@ -87,8 +96,8 @@ public static void chooseCommand(String input) { } break; case ("unmark"): - markedObjectInt = Integer.parseInt(parts[1]); try { + int markedObjectInt = Integer.parseInt(parts[1]); Task unmarkedTask = tasks.get(markedObjectInt - 1); unmarkedTask.isDone = false; System.out.println("I unmarked this class as done: " + unmarkedTask.getDescription()); @@ -97,17 +106,20 @@ public static void chooseCommand(String input) { } break; case("delete"): - int taskToDelete = Integer.parseInt(parts[1]); - tasks.get(taskToDelete - 1).isDone = false; + if (ensureHasParameters(parts)) { + try { + int taskToDelete = Integer.parseInt(parts[1]); + tasks.get(taskToDelete - 1).isDone = false; - removeTaskFromFile(taskToDelete - 1); - try { - Task deleteTask = tasks.get(taskToDelete - 1); - tasks.remove(taskToDelete - 1); + removeTaskFromFile(taskToDelete - 1); - System.out.println("I deleted this task this class as done: " + deleteTask.getDescription()); - } catch (Exception ArrayIndexOutOfBoundsException) { - System.out.println("That task doesnt exist"); + Task deleteTask = tasks.get(taskToDelete - 1); + tasks.remove(taskToDelete - 1); + + System.out.println("I deleted this task this class as done: " + deleteTask.getDescription()); + } catch (Exception ArrayIndexOutOfBoundsException) { + System.out.println("That task doesnt exist"); + } } break; case ("deadline"): @@ -141,20 +153,25 @@ public static void chooseCommand(String input) { } break; case("todo"): - try { - String desc = input.substring(4).trim(); - Todo todo = new Todo(desc); - - - tasks.add(todo); - tasksToBeSaved.add(todo); - - } catch (Exception e) { - System.out.println("An error occurred while adding the todo."); + if (ensureHasParameters(parts)){ + try { + String desc = input.substring(4).trim(); + Todo todo = new Todo(desc); + + System.out.println(todo.getDescription()); + tasks.add(todo); + tasksToBeSaved.add(todo); + + } catch (Exception e) { + System.out.println("An error occurred while adding the todo."); + } } + break; case("find"): - searchAndDisplayTasks(parts[1]); + if (ensureHasParameters(parts)){ + searchAndDisplayTasks(parts[1]); + } break; case("bye"): @@ -186,4 +203,18 @@ public static void searchAndDisplayTasks(String keyword) { } } } + + /** + * Make sure commands that have more than 1 parameter is handled + * @param parts + * @return + */ + static private boolean ensureHasParameters(String[] parts){ + if (!(parts.length >= 2)){ + System.out.println("Please entered the required parameters for the command"); + return false; + } + return true; + } + } diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 550219ffa..23a808ef2 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -12,8 +12,8 @@ public Ui() { // Display a welcome message to the user public void showWelcome() { - System.out.println("Hello my name is DUKE"); - System.out.println("What can I do for you today? Enter 'help' for a list of commands"); + System.out.println("Hello my name is DUKE. I am created by Isaiah Cerven"); + System.out.println("What can I do for you today? Enter 'help' for a list of commands. Say 'bye' to save tasks and exit"); } // Display a goodbye message when the user decides to exit @@ -34,6 +34,15 @@ public String getUserInput() { return scanner.nextLine(); } + public boolean checkUserInput(String input){ + + if (input.isEmpty()) { + System.out.println("Please input a command."); + return false; + } + return true; + } + public void showError(String message) { System.out.println("Error: " + message); } From f7403d7aaa9fa0ae11d7da9760963203475384b8 Mon Sep 17 00:00:00 2001 From: CerIsaiah <104468622+CerIsaiah@users.noreply.github.com> Date: Mon, 23 Oct 2023 01:53:47 -0600 Subject: [PATCH 13/13] Update README.md --- README.md | 95 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 8715d4d91..ec2001b85 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,71 @@ -# 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 - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +# Duke Chatbot + +[User Guide](#user-guide) | [About Us](#about-us) | [View on GitHub](https://github.com/your-github-link-here) + +## User Guide + +### Introduction +The Duke Chatbot is a desktop app optimized for managing tasks and events, making use of a Command Line Interface (CLI) whilst offering the benefits of a Graphical User Interface (GUI). If you're a fast typer, our chatbot will help you manage your tasks more efficiently than traditional GUI apps. + +#### Quick Start: + +1. Ensure you have Java 11 or above installed on your computer. +2. Download the latest jar file. +3. Copy the file to the folder you want to use as the home directory for your Chatbot. +4. Open a command terminal, navigate to the folder containing the jar file, and run the chatbot using the `java -jar chatbot.jar` command. + +#### Features + +:information_source: **Notes about the command format:** +- Commands are not case-sensitive. For instance, `list` and `LIST` will function identically. +- Parameters that need to be supplied by the user are in UPPER_CASE. For example, in the `find KEYWORD`, KEYWORD is a parameter to be provided, like `find homework`. + +#### Commands + +- **List**: Shows all tasks. + - Format: `list` + +- **Mark**: Marks a task as done. + - Format: `mark TASK_INDEX` + - Example: `mark 2` marks the second task as done. + +- **Unmark**: Unmarks a task. + - Format: `unmark TASK_INDEX` + - Example: `unmark 2` unmarks the second task. + +- **Delete**: Deletes a task. + - Format: `delete TASK_INDEX` + - Example: `delete 2` deletes the second task. + +- **Deadline**: Adds a task with a deadline. + - Format: `deadline TASK_NAME /by DATE_TIME` + - Example: `deadline Submit Homework /by 2023-10-15 1800` + +- **Event**: Adds an event. + - Format: `event EVENT_NAME /at DATE_TIME` + - Example: `event Team Meeting /at 2023-10-20 1400` + +- **Todo**: Adds a to-do task. + - Format: `todo TASK_NAME` + - Example: `todo Read Book` + +- **Find**: Searches tasks containing the keyword. + - Format: `find KEYWORD` + - Example: `find meeting` returns all tasks containing the word 'meeting'. + +#### FAQ +- **Q: How can I backup my tasks?** + - A: All tasks are automatically saved in the hard drive after every command that modifies data. To backup, simply copy the saved data file and store it in a safe location. + +#### Command Summary +| Action | Format, Examples | +|-----------|-----------------------------------------------------------------------------------| +| List | `list` | +| Mark | `mark TASK_INDEX` e.g., `mark 2` | +| Unmark | `unmark TASK_INDEX` e.g., `unmark 2` | +| Delete | `delete TASK_INDEX` e.g., `delete 2` | +| Deadline | `deadline TASK_NAME /by DATE_TIME` e.g., `deadline Submit Homework /by 2023-10-15`| +| Event | `event EVENT_NAME /at DATE_TIME` e.g., `event Team Meeting /at 2023-10-20` | +| Todo | `todo TASK_NAME` e.g., `todo Read Book` | +| Find | `find KEYWORD` e.g., `find meeting` | +