diff --git a/docs/README.md b/docs/README.md index 8077118eb..afeafc40f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,28 +2,193 @@ ## Features -### Feature-ABC +### Feature-Add tasks -Description of the feature. +Add "todo", "deadline" or "event" tasks to the task list. -### Feature-XYZ +### Feature-Mark as done -Description of the feature. +Mark a specific task in the task list as done + +### Feature-Delete tasks + +Delete a specific task in the task list + +### Feature-Find tasks + +Find tasks with the keyword ## Usage -### `Keyword` - Describe action +### `todo` - Add a todo task + +Add a todo task to the task list. -Describe the action and its outcome. +`todo DESCRIPTION` Example of usage: -`keyword (optional arguments)` +`todo make a call` + +Expected outcome: + +A todo task added. + +``` + _________________________________ + |Got it. I've added this task: | + |[T][ ]make a call | + |Now you have 1 tasks in the list.| + |_________________________________| +``` + +### `deadline` - Add a deadline task + +Add a deadline task to the task list. + +`deadline DESCRIPTION /by TIME` + +Example of usage: + +`deadline finish the task /by tomorrow` + +Expected outcome: + +A deadline task added. + +``` + ____________________________________ + |Got it. I've added this task: | + |[D][ ]finish the task(by: tomorrow)| + |Now you have 1 tasks in the list. | + |____________________________________| +``` + +### `event` - Add a event task + +Add a event task to the task list. + +`event DESCRIPTION /at TIME` + +Example of usage: + +`event go for big meal /at 6pm` + +Expected outcome: + +A event task added. + +``` + _________________________________ + |Got it. I've added this task: | + |[E][ ]go for big meal(at: 6pm) | + |Now you have 1 tasks in the list.| + |_________________________________| +``` + +### `done` - Mark a task as done + +Mark the task with a specific index number as done. + +`done NUMBER` + +Example of usage: + +`done 1` + +Expected outcome: + +The first task in the list marked as done. + +``` + _____________________________________ + |Nice! I've marked this task as done: | + |[E][X]go for big meal(at: 6pm) | + |_____________________________________| +``` + +### `delete` - Delete a task + +Delete the task with the specific index number. + +`delete NUMBER` + +Example of usage: + +`delete 1` + +Expected outcome: + +The first task is deleted from the list. + +``` + _________________________________ + |Noted. I've removed this task: | + |[E][X]go for big meal(at: 6pm) | + |Now you have 0 tasks in the list.| + |_________________________________| +``` + +### `list` - List all the tasks + +List all the tasks in the list. + +`list` + +Example of usage: + +`list` + +Expected outcome: + +The whole list of tasks. + +``` + _______________________________________ + |Here are the tasks in your list: | + |1. [T][ ]make a call | + |2. [D][ ]finish the task(by: tomorrow)| + |3. [E][ ]go for big meal(at: 6pm) | + |_______________________________________| +``` + +### `find` - Find tasks with the keyword + +The tasks with the keyword will be found. + +`find KEYWORD` + +Example of usage: + +`find meal` Expected outcome: Description of the outcome. ``` -expected output + _________________________________________ + |Here are the tasks in your list: | + |1. [E][ ]go for big meal(at: 6pm) | + |_________________________________________| +``` + +### `bye` - Exit programme + +The programme exit with saving the list to the file. + +`bye` + +Example of usage: + +`bye` + +Expected outcome: + +Greeting from the programme. + +``` + ________________________________ + |Bye. Hope to see you again soon!| + |________________________________| ``` diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 000000000..c4192631f --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-cayman \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..562812e9e 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,222 @@ +import duke.exception.*; +import duke.task.*; + +import java.util.ArrayList; +import java.util.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +//try fix + +/** + * Duke is a reminder programme for users to store the things they want to do at what time + */ public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" + public static void main(String[] args) throws AssignException, TypingException, FormatException, EventStringException, DeadlineStringException, TodoStringException, IOException { + /*String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + System.out.println("Hello from\n" + logo);*/ + int MAX_TASK = 100; + TaskList Tasks = new TaskList(); + Ui ui = new Ui(); + ui.greet(); + String file = "data/tasks.txt"; + Storage storage = new Storage(file); + Tasks = storage.getFile(); + Scanner sc= new Scanner(System.in); //System.in is a standard input stream + boolean isExit = true; + int maxlength = 0; + for(; Tasks.size() < 100 && isExit;){ + String str= sc.nextLine(); + try { + switch (Parser.processCommand(str)) { + case BYE: + ui.bye(); + isExit = false; + break; + case LIST: + checkList(Tasks.size()); + ui.printList(Tasks, maxlength); + break; + case FIND: + str = str.substring(5, str.length()); + ui.printFoundTask(Tasks, str, maxlength); + break; + case TODO: + checkTodoString(str); + maxlength = checkLength(str, maxlength, -5 + 9);//- length of "todo " + "1. [X][X]" + str = str.substring(5, str.length()); + Todo t = new Todo(str); + addToList(t, Tasks); + ui.printTask(t, Tasks.size()); + break; + case DEADLINE: + checkDeadlineString(str); + checkFormat(str); + String timeD = str.substring(str.indexOf("/") + 3, str.length()); + maxlength = checkLength(str, maxlength, -9 + 11);//- length of "deadline " + "1. [X][X]" + "(xx:" + ")" + Deadline d = new Deadline(str.substring(9, str.indexOf("/") - 1), timeD); + addToList(d, Tasks); + ui.printTask(d, Tasks.size()); + break; + case EVENT: + checkEventString(str); + checkFormat(str); + String timeE = str.substring(str.indexOf("/") + 3, str.length()); + maxlength = checkLength(str, maxlength, -6 + 11); + Event e = new Event(str.substring(6, str.indexOf("/") - 1), timeE); + addToList(e, Tasks); + ui.printTask(e, Tasks.size()); + break; + case DELETE: + int num = getStringNumber(str); + checkNum(num, Tasks.size()); + Task task = Tasks.get(num - 1); + Tasks.remove(num - 1); + ui.printDelete(task, Tasks.size()); + break; + case DONE:; + int num2 = getStringNumber(str); + checkNum(num2, Tasks.size()); + Tasks.get(num2 - 1).setDone(true); + ui.printDone(Tasks.get(num2 - 1)); + break; + case UNKNOWN: + FormatError(); + break; + default: + break; + } + } catch (AssignException e){ + ui.printString("OOPS! not assigned"); + } catch (DeadlineStringException e){ + ui.printString("OOPS! the deadline description cannot be empty"); + } catch (EventStringException e) { + ui.printString("OOPS! the event description cannot be empty"); + } catch (FormatException e) { + ui.printString("OOPS! what's the time?"); + } catch (TodoStringException e) { + ui.printString("OOPS! the todo description cannot be empty"); + } catch (TypingException e) { + ui.printString("OOPS! what do u mean?"); + } catch (EmptyListException e) { + ui.printString("OOPS! empty list"); + } + } + storage.writeFile(Tasks); + } + + /** + * get the number in the string + * @param str the string + * @return the number in the string + */ + private static int getStringNumber(String str){ + String numberOnly = str.replaceAll("[^0-9]", ""); + if(numberOnly.length() == 0) numberOnly = "0"; // to avoid empty string error + int num = Integer.parseInt(numberOnly); + return num; + } + + /** + * check whether string length is bigger than the maxlength + * @param str the string + * @param maxlength the maximum string length + * @param num the number that needed to be added for the type + * @return maximum string length + */ + private static int checkLength(String str, int maxlength, int num){ + if (str.length() + num > maxlength) { + maxlength = str.length() + num; + } + return maxlength; + } + + /** + * check the user typed in a proper number + * @param num the number the user typed in + * @param j the number of tasks + * @throws AssignException + */ + public static void checkNum(int num, int j) throws AssignException { + if(num > j || num <= 0) + throw new AssignException(); + } + + /** + * check whether the list is empty + * @param num the number of tasks in the list + * @throws EmptyListException + */ + public static void checkList(int num) throws EmptyListException { + if(num < 1) + throw new EmptyListException(); + } + + /** + * check whether the todo string is proper + * @param str the string the user typed in + * @throws TodoStringException + */ + public static void checkTodoString(String str) throws TodoStringException { + str = str.replaceAll(" ", ""); + if(str.length() <= 4) + throw new TodoStringException(); + } + + /** + * check whether the deadline string is proper + * @param str the string the user typed in + * @throws DeadlineStringException + */ + public static void checkDeadlineString(String str) throws DeadlineStringException { + str = str.replaceAll(" ", ""); + if(str.length() <= 8) + throw new DeadlineStringException(); + } + + /** + * check whether the event string is proper + * @param str the string the user typed in + * @throws EventStringException + */ + public static void checkEventString(String str) throws EventStringException { + str = str.replaceAll(" ", ""); + if(str.length() <= 5) + throw new EventStringException(); + } + + /** + * check whether the user typed in a good deadline or event format + * @param str the string the user typed in + * @throws FormatException + */ + public static void checkFormat(String str) throws FormatException { + if(!str.contains("/by") && !str.contains("/at")) + throw new FormatException(); + } + + /** + * check whether the user typed in a proper command + * @throws TypingException + */ + public static void FormatError() throws TypingException { + throw new TypingException(); + } + + /** + * add the task to the list + * @param t the task + * @param list the list + */ + public static void addToList(Task t, TaskList list){ + list.add(t); } } 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/Parser.java b/src/main/java/Parser.java new file mode 100644 index 000000000..5d8ddc23f --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,36 @@ +import duke.exception.*; +import duke.task.*; + +/** + * Parser deals with the command that user typed in + */ +public class Parser { + /** + * process the user command + * @param str the string the user typed in + * @return the command type + */ + public static Commandtype processCommand(String str) { + Commandtype type; + if (str.equals("bye")) { + type = Commandtype.BYE; + } else if (str.equals("list")) { + type = Commandtype.LIST; + } else if (str.contains("find")) { + type = Commandtype.FIND; + } else if (str.contains("todo")) { + type = Commandtype.TODO; + } else if (str.contains("deadline")) { + type = Commandtype.DEADLINE; + } else if (str.contains("event")) { + type = Commandtype.EVENT; + } else if (str.contains("delete")) { + type = Commandtype.DELETE; + } else if (str.contains("done")) { + type = Commandtype.DONE; + } else { + type = Commandtype.UNKNOWN; + } + return type; + } +} diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 000000000..fe2facb61 --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,161 @@ +import duke.task.Deadline; +import duke.task.Event; +import duke.task.Task; +import duke.task.Todo; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +/** + * Storage read in the file and send it to the database + */ +public class Storage { + private static String path; + + /** + * initialise storage + * @param filePath the storage path + */ + public Storage (String filePath) { + this.path = filePath; + } + + /** + * get the file + * @return the task list in the file + */ + public static TaskList getFile(){ + final TaskList taskLists = new TaskList(); + //ArrayList Tasks = new ArrayList<>(MAX_TASK); + try { + File dukeFile = new File(path); + File directory = dukeFile.getParentFile(); + if(!directory.exists()){ + directory.mkdir(); + } + if(!dukeFile.exists()){ + dukeFile.createNewFile(); + } + readFile(taskLists,path); + printFileContents(path); + } catch (FileNotFoundException e) { + System.out.println("File not found"); + } catch (IOException e) { + e.printStackTrace(); + } + return taskLists; + } + + /** + * read and convert the task list in the file + * @param Tasks the task list to read + * @param path the file path + * @return the task list + * @throws FileNotFoundException + */ + public static TaskList readFile(TaskList Tasks, String path) throws FileNotFoundException{ + File f = new File(path); + Scanner s = new Scanner(f); // create a Scanner using the File as the source + while (s.hasNext()) { + String str = s.nextLine(); + switch (str.substring(0,1)) { + case "T": + String[] strT = str.split(" \\| "); + //for(String st: strT) System.out.println(st); + Todo t = new Todo(strT[2]); + if(Integer.parseInt(strT[1]) == 1) t.setDone(true); + addToList(t, Tasks); + break; + case "D": + String[] strD = str.split(" \\| "); + //for(String st: strD) System.out.println(st); + Deadline d = new Deadline(strD[2], strD[3]); + if(Integer.parseInt(strD[1]) == 1) d.setDone(true); + addToList(d, Tasks); + break; + case "E": + String[] strE = str.split(" \\| "); + //for(String st: strE) System.out.println(st); + Event e = new Event(strE[2], strE[3]); + if(Integer.parseInt(strE[1]) == 1) e.setDone(true); + addToList(e, Tasks); + break; + } + } + return Tasks; + } + + /** + * write the task list to the file + * @param Tasks the task list + */ + public static void writeFile(TaskList Tasks){ + try { + FileWriter fileWriter =new FileWriter(path); + fileWriter.write(""); + fileWriter.flush(); + fileWriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + String textToAdd = ""; + for(int i = 0; i < Tasks.size(); i++){ + switch (Tasks.get(i).getType()){ + case TODO: + textToAdd += "T | " + (Tasks.get(i).isDone() ? "1" : "0") + " | " + Tasks.get(i).getDescription() + System.lineSeparator(); + break; + case DEADLINE: + textToAdd += "D | " + (Tasks.get(i).isDone() ? "1" : "0") + " | " + Tasks.get(i).getDescription() + " | " + Tasks.get(i).getBy() + System.lineSeparator(); + break; + case EVENT: + textToAdd += "E | " + (Tasks.get(i).isDone() ? "1" : "0") + " | " + Tasks.get(i).getDescription() + " | " + Tasks.get(i).getBy() + System.lineSeparator(); + break; + } + } + try { + writeToFile(path, textToAdd); + } catch (IOException e) { + System.out.println("Something went wrong: " + e.getMessage()); + } + } + + /** + * print out the file contents + * @param path the file path + * @throws FileNotFoundException + */ + private static void printFileContents(String path) throws FileNotFoundException { + File f = new File(path); // create a File for the given file path + Scanner s = new Scanner(f); // create a Scanner using the File as the source + System.out.println("Tasks recorded: "); + while (s.hasNext()) { + System.out.println(s.nextLine()); + } + } + + /** + * write the task to the file + * @param path the file path + * @param textToAdd the text to add in the file + * @throws IOException + */ + private static void writeToFile(String path, String textToAdd) throws IOException { + FileWriter fw = new FileWriter(path); + fw.write(textToAdd); + fw.close(); + } + + /** + * add task to the list + * @param t the task + * @param list the task list + */ + public static void addToList(Task t, TaskList list){ + list.add(t); + } +} diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 000000000..c8d82e2b7 --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,45 @@ +import duke.task.Task; + +import java.util.ArrayList; + +/** + * TaskList is the type to store the tasks + */ +public class TaskList { + private final ArrayList taskList = new ArrayList<>(); + + public TaskList() {} + + /** + * add task + * @param toAdd task to add + */ + public void add(Task toAdd) { + taskList.add(toAdd); + } + + /** + * get task + * @param toGet the index of the task to get + * @return + */ + public Task get(int toGet) { + return taskList.get(toGet); + } + + /** + * remove task + * @param toRemove the index of the task to remove + */ + public void remove(int toRemove) { + taskList.remove(toRemove); + } + + /** + * get the task size + * @return the task size + */ + public int size() { + return taskList.size(); + } +} diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 000000000..74be45d64 --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,194 @@ +import duke.task.Task; + +/** + * Ui deals with the user interface and print out the feedbacks + */ +public class Ui { + /** + * greet the user + */ + public static void greet(){ + String greetings = " Hello! I'm Duke\n" + " What can I do for you?\n"; + System.out.println(greetings); + } + + /** + * say bye to user + */ + public static void bye(){ + String str = "Bye. Hope to see you again soon!"; + printString(str); + } + + /** + * print a normal string + * @param str the string to print + */ + public static void printString(String str){ + int length = str.length(); + System.out.print(" "); + for(int i = 0; i < length; i++) System.out.print("_"); + System.out.println(""); + System.out.println(" |" + str + "|"); + System.out.print(" |"); + for(int i = 0; i < length; i++) System.out.print("_"); + System.out.println("|"); + } + + /** + * print the task done + * @param t the task + */ + public static void printDone(Task t){ + String str = "Nice! I've marked this task as done: "; + int length = Math.max(t.getLength(), str.length()); + System.out.print(" "); + for(int i = 0; i < length; i++) System.out.print("_"); + System.out.println(""); + System.out.print(" |" + str); + for(int n = 0; n < length - str.length(); n++) System.out.print(" "); + System.out.println("|"); + switch(t.getType()){ + case TODO: + System.out.print(" |[T][" + t.getStatusIcon() + "]"+ t.getDescription()); + break; + case DEADLINE: + System.out.print(" |[D][" + t.getStatusIcon() + "]" + t.getDescription() + "(by: " + t.getBy() + ")"); + break; + case EVENT: + System.out.print(" |[E][" + t.getStatusIcon() + "]" + t.getDescription() + "(at: " + t.getBy() + ")"); + break; + } + for(int n = 0; n < length - t.getLength(); n++) System.out.print(" "); + System.out.println("|"); + System.out.print(" |"); + for(int i = 0; i < length; i++) System.out.print("_"); + System.out.println("|"); + } + + /** + * print the delete task + * @param t the task + * @param num the number of tasks in the list + */ + public static void printDelete(Task t, int num){ + String str = "Noted. I've removed this task: "; + String str2 = "Now you have " + num + " tasks in the list."; + int length = Math.max(t.getLength(), Math.max(str.length(), str2.length())); + System.out.print(" "); + for(int i = 0; i < length; i++) System.out.print("_"); + System.out.println(""); + System.out.print(" |" + str); + for(int n = 0; n < length - str.length(); n++) System.out.print(" "); + System.out.println("|"); + switch(t.getType()){ + case TODO: + System.out.print(" |[T][" + t.getStatusIcon() + "]"+ t.getDescription()); + break; + case DEADLINE: + System.out.print(" |[D][" + t.getStatusIcon() + "]" + t.getDescription() + "(by: " + t.getBy() + ")"); + break; + case EVENT: + System.out.print(" |[E][" + t.getStatusIcon() + "]" + t.getDescription() + "(at: " + t.getBy() + ")"); + break; + } + for(int n = 0; n < length - t.getLength(); n++) System.out.print(" "); + System.out.println("|"); + System.out.print(" |" + str2); + for(int n = 0; n < length - str2.length(); n++) System.out.print(" "); + System.out.println("|"); + System.out.print(" |"); + for(int i = 0; i < length; i++) System.out.print("_"); + System.out.println("|"); + } + + /** + * print the matching tasks + * @param list the task list + * @param str the string to find + * @param num the maximum string length + */ + public static void printFoundTask(TaskList list, String str, int num){ + TaskList foundTasks = new TaskList(); + for(int i = 1; i <= list.size(); i++){ + if(list.get(i - 1).getDescription().contains(str)){ + foundTasks.add(list.get(i - 1)); + } + } + if(foundTasks.size() > 0) { + printList(foundTasks, num); + } else { + printString("OOPS! failed to find"); + } + } + + /** + * print the task list + * @param list the task list + * @param num the maximum string length + */ + public static void printList(TaskList list, int num){ + String listing = "Here are the tasks in your list:"; + if(listing.length() > num) num = listing.length(); + System.out.print(" "); + for(int i = 0; i < num; i++) System.out.print("_"); + System.out.println(""); + System.out.print(" |" + listing); + for(int n = 0; n < num - listing.length(); n++) System.out.print(" "); + System.out.println("|"); + for(int j = 1; j <= list.size(); j++) { + switch(list.get(j - 1).getType()){ + case TODO: + System.out.print(" |" + j + ". [T][" + list.get(j - 1).getStatusIcon() + "]"+ list.get(j - 1).getDescription()); + break; + case DEADLINE: + System.out.print(" |" + j + ". [D][" + list.get(j - 1).getStatusIcon() + "]" + list.get(j - 1).getDescription() + "(by: " + list.get(j - 1).getBy() + ")"); + break; + case EVENT: + System.out.print(" |" + j + ". [E][" + list.get(j - 1).getStatusIcon() + "]" + list.get(j - 1).getDescription() + "(at: " + list.get(j - 1).getBy() + ")"); + break; + } + for(int n = 0; n < num - list.get(j - 1).getLength() - 3 - (int)Math.log10(j); n++) System.out.print(" "); + System.out.println("|"); + } + System.out.print(" |"); + for(int i = 0; i < num; i++) System.out.print("_"); + System.out.println("|"); + } + + /** + * print a specific task + * @param t the task + * @param num the number of tasks in the list + */ + public static void printTask(Task t, int num){ + String str = "Got it. I've added this task: "; + String str2 = "Now you have " + num + " tasks in the list."; + int length = Math.max(t.getLength(), Math.max(str.length(), str2.length())); + System.out.print(" "); + for(int i = 0; i < length; i++) System.out.print("_"); + System.out.println(""); + System.out.print(" |" + str); + for(int n = 0; n < length - str.length(); n++) System.out.print(" "); + System.out.println("|"); + switch(t.getType()){ + case TODO: + System.out.print(" |[T][" + t.getStatusIcon() + "]"+ t.getDescription()); + break; + case DEADLINE: + System.out.print(" |[D][" + t.getStatusIcon() + "]" + t.getDescription() + "(by: " + t.getBy() + ")"); + break; + case EVENT: + System.out.print(" |[E][" + t.getStatusIcon() + "]" + t.getDescription() + "(at: " + t.getBy() + ")"); + break; + } + for(int n = 0; n < length - t.getLength(); n++) System.out.print(" "); + System.out.println("|"); + System.out.print(" |" + str2); + for(int n = 0; n < length - str2.length(); n++) System.out.print(" "); + System.out.println("|"); + System.out.print(" |"); + for(int i = 0; i < length; i++) System.out.print("_"); + System.out.println("|"); + } +} diff --git a/src/main/java/duke/exception/AssignException.java b/src/main/java/duke/exception/AssignException.java new file mode 100644 index 000000000..fb164f327 --- /dev/null +++ b/src/main/java/duke/exception/AssignException.java @@ -0,0 +1,6 @@ +package duke.exception; + +public class AssignException extends Exception { + //no other code needed +} + diff --git a/src/main/java/duke/exception/DeadlineStringException.java b/src/main/java/duke/exception/DeadlineStringException.java new file mode 100644 index 000000000..abc8ed540 --- /dev/null +++ b/src/main/java/duke/exception/DeadlineStringException.java @@ -0,0 +1,5 @@ +package duke.exception; + +public class DeadlineStringException extends Exception { + //no other code needed +} \ No newline at end of file diff --git a/src/main/java/duke/exception/EmptyListException.java b/src/main/java/duke/exception/EmptyListException.java new file mode 100644 index 000000000..d31b99996 --- /dev/null +++ b/src/main/java/duke/exception/EmptyListException.java @@ -0,0 +1,4 @@ +package duke.exception; + +public class EmptyListException extends Exception{ +} diff --git a/src/main/java/duke/exception/EventStringException.java b/src/main/java/duke/exception/EventStringException.java new file mode 100644 index 000000000..67e9e50f7 --- /dev/null +++ b/src/main/java/duke/exception/EventStringException.java @@ -0,0 +1,5 @@ +package duke.exception; + +public class EventStringException extends Exception { + //no other code needed +} diff --git a/src/main/java/duke/exception/FormatException.java b/src/main/java/duke/exception/FormatException.java new file mode 100644 index 000000000..d733bc4c6 --- /dev/null +++ b/src/main/java/duke/exception/FormatException.java @@ -0,0 +1,5 @@ +package duke.exception; + +public class FormatException extends Exception { + //no other code needed +} diff --git a/src/main/java/duke/exception/TodoStringException.java b/src/main/java/duke/exception/TodoStringException.java new file mode 100644 index 000000000..d3acb5877 --- /dev/null +++ b/src/main/java/duke/exception/TodoStringException.java @@ -0,0 +1,5 @@ +package duke.exception; + +public class TodoStringException extends Exception { + //no other code needed +} diff --git a/src/main/java/duke/exception/TypingException.java b/src/main/java/duke/exception/TypingException.java new file mode 100644 index 000000000..1d58aa7a6 --- /dev/null +++ b/src/main/java/duke/exception/TypingException.java @@ -0,0 +1,5 @@ +package duke.exception; + +public class TypingException extends Exception { + //no other code needed +} diff --git a/src/main/java/duke/task/Commandtype.java b/src/main/java/duke/task/Commandtype.java new file mode 100644 index 000000000..7975c3dc2 --- /dev/null +++ b/src/main/java/duke/task/Commandtype.java @@ -0,0 +1,8 @@ +package duke.task; + +/** + *the user command can have the following types + */ +public enum Commandtype { + BYE, LIST, FIND, TODO, DEADLINE, EVENT, DELETE, DONE, UNKNOWN +} diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java new file mode 100644 index 000000000..72565e276 --- /dev/null +++ b/src/main/java/duke/task/Deadline.java @@ -0,0 +1,73 @@ +package duke.task; + +/** + * deadline is something should be done before a specific time + * deadline is a type under todo, parallel to event + * a deadline format "deadline xx /by xx" + */ + +public class Deadline extends Todo { + protected String by; + + /** + * deadline initiation + * @param description the description of the task + * @param by the time for the task + */ + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + /** + * change time + * @param by the time for the task + */ + public void setBy(String by) { + this.by = by; + } + + /** + * get status + * @return status + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + /** + * get time + * @return the time for the task + */ + @Override + public String getBy() { + return by; + } + + /** + * get the description and time length + * @return description and time length + */ + @Override + public int getLength(){ + return description.length() + by.length() + 12; + } + + /** + * get the type + * @return DEADLINE + */ + @Override + public Tasktype getType(){ + return Tasktype.DEADLINE; + } + + /** + * output string + * @return string + */ + @Override + public String toString() { + return super.toString() + System.lineSeparator() + "do by: " + by; + } +} \ No newline at end of file diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java new file mode 100644 index 000000000..3896e34f3 --- /dev/null +++ b/src/main/java/duke/task/Event.java @@ -0,0 +1,73 @@ +package duke.task; + +/** + * event is something that happens at a specific time + * event is a type under todo, parallel to deadline + * a event format " event xx /at xx" + */ + +public class Event extends Todo { + protected String by; + + /** + * event initiation + * @param description the description of the task + * @param by the time for the task + */ + public Event(String description, String by) { + super(description); + this.by = by; + } + + /** + * change time + * @param by the time for the task + */ + public void setBy(String by) { + this.by = by; + } + + /** + * get status + * @return status + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + /** + * get time + * @return the time for the task + */ + @Override + public String getBy() { + return by; + } + + /** + * get the description and time length + * @return description and time length + */ + @Override + public int getLength(){ + return description.length() + by.length() + 12; + } + + /** + * get the type + * @return EVENT + */ + @Override + public Tasktype getType(){ + return Tasktype.EVENT; + } + + /** + * output string + * @return string + */ + @Override + public String toString() { + return super.toString() + System.lineSeparator() + "do by: " + by; + } +} \ No newline at end of file diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java new file mode 100644 index 000000000..5bc497cf6 --- /dev/null +++ b/src/main/java/duke/task/Task.java @@ -0,0 +1,85 @@ +package duke.task; + +/** + * Task is something that the user want to do + * Task carries the description and whether it is done + */ +public class Task { + protected String description; + protected boolean isDone; + + /** + * task initiation + * @param description the description of the task + */ + public Task(String description) { + this.description = description; + this.isDone = false; + } + + /** + * get status + * @return status + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + /** + * get description + * @return description + */ + public String getDescription() { + return description; + } + + /** + * get type + * @return TODO + */ + public Tasktype getType(){ + return Tasktype.TODO; + } + + /** + * get description length + * @return description length + */ + public int getLength(){ + return description.length() + 6; + } + + /** + * get time + * @return null + */ + public String getBy() { + return null; + } + + /** + * get status + * @return status + */ + public boolean isDone() { + return isDone; + } + + /** + * change description + * @param description the description of the task + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * change status + * @param done the status + */ + public void setDone(boolean done) { + isDone = done; + } + + //... +} diff --git a/src/main/java/duke/task/Tasktype.java b/src/main/java/duke/task/Tasktype.java new file mode 100644 index 000000000..c93543e10 --- /dev/null +++ b/src/main/java/duke/task/Tasktype.java @@ -0,0 +1,8 @@ +package duke.task; + +/** + * the task can have the following types + */ +public enum Tasktype { + TODO, DEADLINE, EVENT +} diff --git a/src/main/java/duke/task/Todo.java b/src/main/java/duke/task/Todo.java new file mode 100644 index 000000000..f58ab83f2 --- /dev/null +++ b/src/main/java/duke/task/Todo.java @@ -0,0 +1,74 @@ +package duke.task; + +/** + * Todo is a type under task + */ +public class Todo extends Task { + protected boolean isDone; + + /** + * todo initiation + * @param description the description of the task + */ + public Todo(String description) { + super(description); + isDone = false; + } + + /** + * change status + * @param done the status + */ + public void setDone(boolean done) { + isDone = done; + } + + /** + * get status + * @return status + */ + public boolean isDone() { + return isDone; + } + + /** + * get status + * @return status + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + /** + * get time + * @return null + */ + @Override + public String getBy() { + return null; + } + + /** + * get type + * @return TODO + */ + @Override + public Tasktype getType(){ + return Tasktype.TODO; + } + + /** + * output string + * @return string + */ + @Override + public String toString() { + String status = null; + if (isDone){ + status = "X"; + } else { + status = " "; + } + return "[" + status + "]" + super.toString(); + } +} \ No newline at end of file diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..03e85a403 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,40 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| + Hello! I'm Duke + What can I do for you? + _________________________________ + |Got it. I've added this task: | + |[E][ ]to do(at: c) | + |Now you have 1 tasks in the list.| + |_________________________________| + _________________________________ + |Got it. I've added this task: | + |[D][ ]1 2(by: c) | + |Now you have 2 tasks in the list.| + |_________________________________| + _________________________________ + |Got it. I've added this task: | + |[T][ ]ccc | + |Now you have 3 tasks in the list.| + |_________________________________| + __________ + |bad format| + |__________| + ________________________________ + |Here are the tasks in your list:| + |1. [E][ ]to do(at: c) | + |2. [D][ ]1 2(by: c) | + |3. [T][ ]ccc | + |________________________________| + _____________________________________ + |Nice! I've marked this task as done: | + |[E][X]to do(at: c) | + |_____________________________________| + ________________________________ + |Here are the tasks in your list:| + |1. [E][X]to do(at: c) | + |2. [D][ ]1 2(by: c) | + |3. [T][ ]ccc | + |________________________________| + ________________________________ + |Bye. Hope to see you again soon!| + |________________________________| \ No newline at end of file diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..107d57371 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,8 @@ +event to do /at c +deadline 1 2 /by c +todo ccc +deadline c +list +done 1 +list +bye \ No newline at end of file