diff --git a/.gitignore b/.gitignore index f69985ef1..e113020ce 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ src/main/resources/docs/ # MacOS custom attributes files created by Finder .DS_Store *.iml +# class files generated by java +*.class bin/ /text-ui-test/ACTUAL.txt diff --git a/README.md b/README.md index 8715d4d91..5238ba4bf 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,105 @@ -# 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 - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +# JRobo | Personal Todo App + +## User Guide + +JRobo is a command line application that you can use as your personal task tracker assistant. + +JRobo consists of various different commands and three type of tasks, which are **todo**, **deadline**, and **event**. +

+**Todos** are tasks that do not have any specific time or duration. +
+**Deadlines** are tasks that have a specific deadline that can be specified while adding. +
+**Events** are tasks that have a specific time and duration that can be specified while adding. + +Note that, even if the application is terminated, JRobo will keep all tasks for you in his memory. + +## Commands + +### Add Task + +Tasks can be added using **todo**, **deadline**, **event** commands, or with their shortcut notations. + +#### Command format: + +`todo {description}`
+`deadline {description}/by {any time}`
+`event {description} /at {any time}` + +#### Shortcuts: + +`t {description}`
+`d {description} /by {any time}`
+`e {description} /at {any time}` + +### Remove Task + +Tasks can be removed using **delete** command, or with its shortcut **del**. + +#### Command format: + +`delete {task_number}` + +#### Shortcuts: + +`del {task_number}` + +### List All Tasks + +All tasks can be listed using **list** command, or with its shortcut **ls**. + +#### Command format: + +`list` + +#### Shortcuts: + +`ls` + +### Check Task + +Tasks can be marked as done using **mark** command, or with its shortcut **m**. + +#### Command format: + +`mark {task_number}` + +#### Shortcuts: + +`m {task_number}` + +### Uncheck Task + +Tasks can be marked as done using **unmark** command, or with its shortcut **um**. + +#### Command format: + +`unmark {task_number}` + +#### Shortcuts: + +`um {task_number}` + +### Find Specific Task + +All tasks can be searched and filtered using **find** command, or with its shortcut **f**. + +#### Command format: + +`find {search_key` + +#### Shortcuts: + +`f {search_key}` + +### Termination + +Application can be quited using **quit** command, or with its shortcut **q**. + +#### Command format: + +`quit` + +#### Shortcuts: + +`q` diff --git a/_config.yml b/_config.yml new file mode 100644 index 000000000..259a24e4d --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-tactile \ No newline at end of file diff --git a/data/tasks.txt b/data/tasks.txt new file mode 100644 index 000000000..cb32cef2a --- /dev/null +++ b/data/tasks.txt @@ -0,0 +1,2 @@ +[E][ ] Ege Demirkirkan attend CS2113 lecture (at: Friday 18 Feb 2022 from 4 to 6pm) +[D][ ] meet your girlfrind (by: tommorow) diff --git a/docs/README.md b/docs/README.md index 8077118eb..5238ba4bf 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,105 @@ -# User Guide +# JRobo | Personal Todo App -## Features +## User Guide -### Feature-ABC +JRobo is a command line application that you can use as your personal task tracker assistant. -Description of the feature. +JRobo consists of various different commands and three type of tasks, which are **todo**, **deadline**, and **event**. +

+**Todos** are tasks that do not have any specific time or duration. +
+**Deadlines** are tasks that have a specific deadline that can be specified while adding. +
+**Events** are tasks that have a specific time and duration that can be specified while adding. -### Feature-XYZ +Note that, even if the application is terminated, JRobo will keep all tasks for you in his memory. -Description of the feature. +## Commands -## Usage +### Add Task -### `Keyword` - Describe action +Tasks can be added using **todo**, **deadline**, **event** commands, or with their shortcut notations. -Describe the action and its outcome. +#### Command format: -Example of usage: +`todo {description}`
+`deadline {description}/by {any time}`
+`event {description} /at {any time}` -`keyword (optional arguments)` +#### Shortcuts: -Expected outcome: +`t {description}`
+`d {description} /by {any time}`
+`e {description} /at {any time}` -Description of the outcome. +### Remove Task -``` -expected output -``` +Tasks can be removed using **delete** command, or with its shortcut **del**. + +#### Command format: + +`delete {task_number}` + +#### Shortcuts: + +`del {task_number}` + +### List All Tasks + +All tasks can be listed using **list** command, or with its shortcut **ls**. + +#### Command format: + +`list` + +#### Shortcuts: + +`ls` + +### Check Task + +Tasks can be marked as done using **mark** command, or with its shortcut **m**. + +#### Command format: + +`mark {task_number}` + +#### Shortcuts: + +`m {task_number}` + +### Uncheck Task + +Tasks can be marked as done using **unmark** command, or with its shortcut **um**. + +#### Command format: + +`unmark {task_number}` + +#### Shortcuts: + +`um {task_number}` + +### Find Specific Task + +All tasks can be searched and filtered using **find** command, or with its shortcut **f**. + +#### Command format: + +`find {search_key` + +#### Shortcuts: + +`f {search_key}` + +### Termination + +Application can be quited using **quit** command, or with its shortcut **q**. + +#### Command format: + +`quit` + +#### Shortcuts: + +`q` diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 000000000..259a24e4d --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-tactile \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334c..000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/JRobo.java b/src/main/java/JRobo.java new file mode 100644 index 000000000..55b17cfe0 --- /dev/null +++ b/src/main/java/JRobo.java @@ -0,0 +1,22 @@ +import jrobo.storage.Storage; +import jrobo.task.TaskManager; +import jrobo.ui.UI; + +import java.util.Scanner; + +public class JRobo { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + TaskManager manager = new TaskManager(); + Storage storage = new Storage(manager); + UI ui = new UI(scanner, manager); + run(storage, ui); + scanner.close(); + } + + public static void run(Storage storage, UI ui) { + storage.load(); + ui.setView(); + storage.save(); + } +} diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..924ce173d --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: JRobo + diff --git a/src/main/java/jrobo/command/InputParser.java b/src/main/java/jrobo/command/InputParser.java new file mode 100644 index 000000000..29129d654 --- /dev/null +++ b/src/main/java/jrobo/command/InputParser.java @@ -0,0 +1,149 @@ +package jrobo.command; + +import jrobo.exception.InvalidFormatException; + +/** + * InputParser is the class that receives and validate the input commands coming from CLI. + * + * @author Ege Demirkirkan + */ + +public class InputParser { + protected String[] args; + protected static String[] validCommands = {"mark", "m", "unmark", "um", "todo", "t", "deadline", "d", + "event", "e", "list", "ls", "bye", "exit", "quit", "q", "delete", "del", "find", "f"}; + + public InputParser(String input) { + this.args = input.split(" "); + } + + /** + * Returns the keyword of the user's command as a String object. + * + * @return the command's keyword + */ + public String getPrefix() { + for (String s : validCommands) { + String command = args[0]; + if (command.equalsIgnoreCase(s)) { + return command.toLowerCase(); + } + } + return null; + } + + /** + * Returns the description of the user's CLI task command + * + * @return the task commands' description + */ + public String getBody() { + int suffixIndex = findSuffixIndex(); + + StringBuilder description = new StringBuilder(); + int n = suffixIndex == -1 ? args.length : suffixIndex; + for (int i = 1; i < n; i++) { + description.append(" ").append(args[i]); + } + return description.toString(); + } + + /** + * Returns the time details of the user's CLI task command + * + * @return the task commands' details regarding time + */ + public String getSuffix() { + int suffixIndex = findSuffixIndex(); + if (suffixIndex == -1) { + return null; + } + + StringBuilder detail = new StringBuilder(); + for (int i = suffixIndex + 1; i < args.length; i++) { + detail.append(" ").append(args[i]); + } + return detail.toString(); + } + + /** + * Returns a boolean value that determines whether the CLI command is valid and properly formatted. + * + * @return a true or false according to correctness of command's format + */ + public boolean isValidCommand() { + return !(getPrefix() == null || ((getPrefix().equals("list") || getPrefix().equals("ls")) + && !getBody().equals(""))); + } + + /** + * Returns the type of the task given in the command + * + * @return "todo", "deadline", or "event" + * @throws InvalidFormatException if the format of the command is wrong, + * display the related error text + */ + public String getType() throws InvalidFormatException { + boolean isEvent = false; + boolean isDeadline = false; + for (String s : args) { + if (s.equals("/at")) { + isEvent = true; + } + if (s.equals("/by")) { + isDeadline = true; + } + } + + if (!isDeadline && !isEvent && (getPrefix().equals("todo") || getPrefix().equals("t"))) { + return "todo"; + } + if (isDeadline && (getPrefix().equals("deadline") || getPrefix().equals("d"))) { + return "deadline"; + } + if (isEvent && (getPrefix().equals("event") || getPrefix().equals("e"))) { + return "event"; + } + throw new InvalidFormatException("Invalid command format!"); + } + + /** + * Returns the necessary information to be able to recreate Task objects. + * + * @param taskStr String object extracted from the text file that is used as a storage + * @return three element array, in which, command's description, time detail, and type respectively. + * @see jrobo.task.Task + */ + public String[] strToTask(String taskStr) { + int index = taskStr.lastIndexOf(']'); + String prefix = taskStr.substring(0, index); + String body; + String suffix; + boolean isDeadline = prefix.contains("D"); + boolean isEvent = prefix.contains("E"); + if (isEvent) { + suffix = taskStr.substring(taskStr.indexOf("at:") + 3, taskStr.length() - 1); + body = taskStr.substring(index + 1, taskStr.indexOf('(') - 1); + return new String[] {body, suffix, "event"}; + } else if (isDeadline) { + suffix = taskStr.substring(taskStr.indexOf("by:") + 3, taskStr.length() - 1); + body = taskStr.substring(index + 1, taskStr.indexOf('(') - 1); + return new String[] {body, suffix, "deadline"}; + } else { + body = taskStr.substring(index + 1); + return new String[] {body, "", "todo"}; + } + } + + private int findSuffixIndex() { + int found = -1; + for (int i = 0; i < args.length; i++) { + String s = args[i]; + if (s.equals("/at") || s.equals("/by")) { + found = i; + break; + } + } + return found; + } +} diff --git a/src/main/java/jrobo/exception/InvalidFormatException.java b/src/main/java/jrobo/exception/InvalidFormatException.java new file mode 100644 index 000000000..77dea8383 --- /dev/null +++ b/src/main/java/jrobo/exception/InvalidFormatException.java @@ -0,0 +1,7 @@ +package jrobo.exception; + +public class InvalidFormatException extends Exception { + public InvalidFormatException(String errorMessage) { + super(errorMessage); + } +} \ No newline at end of file diff --git a/src/main/java/jrobo/exception/InvalidTypeException.java b/src/main/java/jrobo/exception/InvalidTypeException.java new file mode 100644 index 000000000..e68c420a7 --- /dev/null +++ b/src/main/java/jrobo/exception/InvalidTypeException.java @@ -0,0 +1,7 @@ +package jrobo.exception; + +public class InvalidTypeException extends Exception { + public InvalidTypeException(String errorMessage) { + super(errorMessage); + } +} \ No newline at end of file diff --git a/src/main/java/jrobo/storage/Storage.java b/src/main/java/jrobo/storage/Storage.java new file mode 100644 index 000000000..f493ee56b --- /dev/null +++ b/src/main/java/jrobo/storage/Storage.java @@ -0,0 +1,73 @@ +package jrobo.storage; + +import jrobo.command.InputParser; +import jrobo.exception.InvalidTypeException; +import jrobo.task.Task; +import jrobo.task.TaskManager; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Scanner; + +/** + * Storage is the class that provides save and load functionalities on each run of the program. + * + * @author Ege Demirkirkan + */ +public class Storage { + TaskManager manager; + + public Storage(TaskManager manager) { + this.manager = manager; + } + + /** + * This method saves tasks to the storage + */ + public void save() { + try { + FileWriter fileWriter = new FileWriter("./ip/data/tasks.txt", true); + clear(); + for (Task task : manager.getTaskList()) { + fileWriter.write(task.toString() + "\n"); + } + fileWriter.close(); + } catch (IOException e) { + manager.printWithSeparator(e.getMessage()); + } + } + + /** + * This method loads tasks from the storage + */ + public void load() { + try { + File file = new File("./ip/data/tasks.txt"); + + Scanner scanner = new Scanner(file); + + while (scanner.hasNext()) { + String taskStr = scanner.nextLine(); + InputParser parser = new InputParser(taskStr); + String[] taskDetails = parser.strToTask(taskStr); + manager.addTask(taskDetails[0], taskDetails[1], taskDetails[2], true); + } + } catch (IOException | InvalidTypeException e) { + manager.printWithSeparator(e.getMessage()); + } + } + + private void clear() { + try { + FileWriter fwOb = new FileWriter("./ip/data/tasks.txt", false); + PrintWriter pwOb = new PrintWriter(fwOb, false); + pwOb.flush(); + pwOb.close(); + fwOb.close(); + } catch (IOException e) { + manager.printWithSeparator(e.getMessage()); + } + } +} diff --git a/src/main/java/jrobo/task/Deadline.java b/src/main/java/jrobo/task/Deadline.java new file mode 100644 index 000000000..3e4d19a2d --- /dev/null +++ b/src/main/java/jrobo/task/Deadline.java @@ -0,0 +1,26 @@ +package jrobo.task; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +public class Deadline extends Task { + + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + try { + LocalDate date = LocalDate.parse(by.trim()); + this.by = " " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } catch (DateTimeParseException e) { + this.by = by; + } + } + + @Override + public String toString() { + return "[D]" + super.toString() + " (by:" + by + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/jrobo/task/Event.java b/src/main/java/jrobo/task/Event.java new file mode 100644 index 000000000..eb9b8afab --- /dev/null +++ b/src/main/java/jrobo/task/Event.java @@ -0,0 +1,25 @@ +package jrobo.task; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +public class Event extends Task { + + protected String at; + + public Event(String description, String at) { + super(description); + try { + LocalDate date = LocalDate.parse(at.trim()); + this.at = " " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")); + } catch (DateTimeParseException e) { + this.at = at; + } + } + + @Override + public String toString() { + return "[E]" + super.toString() + " (at:" + at + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/jrobo/task/Task.java b/src/main/java/jrobo/task/Task.java new file mode 100644 index 000000000..9e8f72c56 --- /dev/null +++ b/src/main/java/jrobo/task/Task.java @@ -0,0 +1,60 @@ +package jrobo.task; + +/** + * Task is the parent class of Deadline, Event, Todo. + * + * @author Ege Demirkirkan + */ +public class Task { + protected String description; + protected boolean isDone; + protected static int taskCount = 0; + + public Task(String description) { + this.description = description; + this.isDone = false; + taskCount++; + } + + /** + * Returns task's status icon. + * + * @return "X" or " " according to the done status of the task + */ + public String getStatusIcon() { + return (isDone ? "X" : " "); + } + + /** + * Returns the main text of the task. + * + * @return description of the task + */ + public String getDescription() { + return description; + } + + /** + * Setter for isDone field. + */ + public void markAsDone() { + this.isDone = true; + } + + /** + * Setter for isDone field. + */ + public void markAsUndone() { + this.isDone = false; + } + + /** + * Returns a String object representing the Task + * + * @return the String that represents the task in the following format; [{status_icon}]{description} + */ + @Override + public String toString() { + return "[" + getStatusIcon() + "]" + getDescription(); + } +} diff --git a/src/main/java/jrobo/task/TaskManager.java b/src/main/java/jrobo/task/TaskManager.java new file mode 100644 index 000000000..6cbddc4e4 --- /dev/null +++ b/src/main/java/jrobo/task/TaskManager.java @@ -0,0 +1,181 @@ +package jrobo.task; + +import jrobo.exception.InvalidTypeException; + +import java.util.ArrayList; + +/** + * TaskManager is the class that manages everything regarding Task, Deadline, Event, Todo classes + * + * @author Ege Demirkirkan + */ + +public class TaskManager { + ArrayList tasks; + + + public TaskManager() { + this.tasks = new ArrayList<>(); + } + + public void printWithSeparator(String... strings) { + System.out.println("\t____________________________________________________________"); + for (String s : strings) { + System.out.println("\t" + s); + } + System.out.println("\t____________________________________________________________"); + } + + public void welcomeUser() { + printWithSeparator("Hello from JRobo! I'm your personal assistant!", + "Nice to meet you. What can I do for you?"); + } + + /** + * This method displays all the tasks kept in the storage. + */ + public void displayTaskList() { + if (tasks.size() == 0) { + printWithSeparator("You have no tasks to list."); + return; + } + System.out.println("\t____________________________________________________________"); + System.out.println("\tHere are the tasks in your list:"); + int taskCount = tasks.size(); + for (int i = 0; i < taskCount; i++) { + Task t = tasks.get(i); + System.out.println("\t" + (i + 1) + "." + t); + } + System.out.println("\t____________________________________________________________"); + } + + /** + * This method is used for handle 'mark' command. It changes the status icon of the task. + * + * @param input String object representing the command in the following format; 'mark {int}' + */ + public void markTask(String input) { + String numberString = input.trim(); + try { + int taskNumber = Integer.parseInt(numberString); + Task task = tasks.get(taskNumber - 1); + if (task.getStatusIcon().equals("X")) { + printWithSeparator("This task is already marked"); + return; + } + task.markAsDone(); + printWithSeparator("Nice! I've marked this task as done:", "\t[" + task.getStatusIcon() + "] " + + task.getDescription()); + } catch (NumberFormatException e) { + printWithSeparator("Invalid command"); + } catch (IndexOutOfBoundsException e) { + printWithSeparator("Please enter a valid task number to mark"); + } + } + + /** + * This method is used for handle 'unmark' command. It changes the status icon of the task. + * + * @param input String object representing the command in the following format; 'unmark {int}' + */ + public void unmarkTask(String input) { + String numberString = input.trim(); + try { + int taskNumber = Integer.parseInt(numberString); + Task task = tasks.get(taskNumber - 1); + if (!task.getStatusIcon().equals("X")) { + printWithSeparator("This task is already unmarked"); + return; + } + task.markAsUndone(); + printWithSeparator("Nice! I've marked this task as undone:", "\t[" + task.getStatusIcon() + "] " + + task.getDescription()); + } catch (NumberFormatException e) { + printWithSeparator("Invalid command"); + } catch (IndexOutOfBoundsException e) { + printWithSeparator("Please enter a valid task number to unmark"); + } + } + + /** + * This method add a task to the storage of the program. + * + * @param description main text of the task + * @param detail time detail of the task, null if the command is not the type deadline or event. + * @param type type of the task + * @param loadFlag boolean value that represents whether the task should be loaded + * @throws InvalidTypeException if the type of the command is wrong, + * displays the related error text + */ + public void addTask(String description, String detail, String type, boolean loadFlag) + throws InvalidTypeException { + Task task; + switch (type) { + case "todo": + task = new Todo(description); + break; + case "deadline": + task = new Deadline(description, detail); + break; + case "event": + task = new Event(description, detail); + break; + default: + throw new InvalidTypeException("Invalid command!"); + } + tasks.add(task); + if (!loadFlag) { + printWithSeparator("Got it. I've added this task:", "\t" + task, + "Now, you have " + tasks.size() + " in the list."); + } + } + + /** + * This method delete a task from the storage of the program. + * + * @param index specifies the task to remove + */ + public void deleteTask(int index) { + if (tasks.size() == 0) { + printWithSeparator("Invalid command! Nothing to delete."); + return; + } + printWithSeparator("Noted. I've removed this task:", "\t" + tasks.get(index - 1).toString(), + "Now you have " + (tasks.size() - 1) + " tasks in the list."); + tasks.remove(index - 1); + } + + public void farewellUser() { + printWithSeparator("Bye. Hope to see you again soon!"); + } + + public void giveError() { + printWithSeparator("Invalid command!"); + } + + /** + * Getter for the tasks field. + * + * @return ArrayList + */ + public ArrayList getTaskList() { + return tasks; + } + + /** + * This method search through the storage to find the related task to the search key + * + * @param toFind search key + */ + public void findTask(String toFind) { + System.out.println("\t____________________________________________________________"); + System.out.println("\tHere are the matching tasks in your list:"); + int index = 1; + for (Task t : tasks) { + if (t.getDescription().toLowerCase().contains(toFind.toLowerCase())) { + System.out.println("\t" + (index++) + "." + t); + } + } + System.out.println("\t____________________________________________________________"); + } +} diff --git a/src/main/java/jrobo/task/Todo.java b/src/main/java/jrobo/task/Todo.java new file mode 100644 index 000000000..7adcdcb7c --- /dev/null +++ b/src/main/java/jrobo/task/Todo.java @@ -0,0 +1,14 @@ +package jrobo.task; + +public class Todo extends Task { + + + public Todo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/jrobo/ui/UI.java b/src/main/java/jrobo/ui/UI.java new file mode 100644 index 000000000..5f5f13b70 --- /dev/null +++ b/src/main/java/jrobo/ui/UI.java @@ -0,0 +1,76 @@ +package jrobo.ui; + +import jrobo.command.InputParser; +import jrobo.task.TaskManager; + +import java.util.Scanner; + +/** + * UI is the class that provides the program with the CLI view. + * + * @author Ege Demirkirkan + */ + +public class UI { + Scanner scanner; + TaskManager manager; + + public UI(Scanner scanner, TaskManager manager) { + this.scanner = scanner; + this.manager = manager; + } + + /** + * This method creates and maintain the CLI view of the program. + */ + public void setView() { + manager.welcomeUser(); + label: + while (true) { + String input = scanner.nextLine(); + InputParser parser = new InputParser(input); + + if (!parser.isValidCommand()) { + manager.giveError(); + continue; + } + String command = parser.getPrefix(); + try { + switch (command) { + case "mark": + case "m": + manager.markTask(parser.getBody()); + break; + case "unmark": + case "um": + manager.unmarkTask(parser.getBody()); + break; + case "list": + case "ls": + manager.displayTaskList(); + break; + case "delete": + case "del": + manager.deleteTask(Integer.parseInt(parser.getBody().trim())); + break; + case "find": + case "f": + manager.findTask(parser.getBody()); + break; + case "bye": + case "b": + case "quit": + case "q": + break label; + default: + + manager.addTask(parser.getBody(), parser.getSuffix(), parser.getType(), false); + break; + } + } catch (jrobo.exception.InvalidFormatException | jrobo.exception.InvalidTypeException | NumberFormatException e) { + manager.printWithSeparator(e.getMessage()); + } + } + manager.farewellUser(); + } +} diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..003ae5f22 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,93 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - + ____________________________________________________________ + Hello from JRobo! I'm your personal assistant! + Nice to meet you. What can I do for you? + ____________________________________________________________ + ____________________________________________________________ + Got it. I've added this task: + [T][ ] get a good grade from CS2113 + Now, you have 1 in the list. + ____________________________________________________________ + ____________________________________________________________ + Got it. I've added this task: + [D][ ] work hard (by: May) + Now, you have 2 in the list. + ____________________________________________________________ + ____________________________________________________________ + Got it. I've added this task: + [E][ ] attend group meeting (at: Thursday 10PM) + Now, you have 3 in the list. + ____________________________________________________________ + ____________________________________________________________ + Nice! I've marked this task as done: + [X] attend group meeting + ____________________________________________________________ + ____________________________________________________________ + This task is already marked + ____________________________________________________________ + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][ ] get a good grade from CS2113 + 2.[D][ ] work hard (by: May) + 3.[E][X] attend group meeting (at: Thursday 10PM) + ____________________________________________________________ + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][ ] get a good grade from CS2113 + 2.[D][ ] work hard (by: May) + 3.[E][X] attend group meeting (at: Thursday 10PM) + ____________________________________________________________ + ____________________________________________________________ + Got it. I've added this task: + [E][ ] attend lecture (at: Friday 4PM) + Now, you have 4 in the list. + ____________________________________________________________ + ____________________________________________________________ + This task is already unmarked + ____________________________________________________________ + ____________________________________________________________ + Nice! I've marked this task as done: + [X] attend lecture + ____________________________________________________________ + ____________________________________________________________ + Nice! I've marked this task as undone: + [ ] attend lecture + ____________________________________________________________ + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][ ] get a good grade from CS2113 + 2.[D][ ] work hard (by: May) + 3.[E][X] attend group meeting (at: Thursday 10PM) + 4.[E][ ] attend lecture (at: Friday 4PM) + ____________________________________________________________ + ____________________________________________________________ + Invalid command! + ____________________________________________________________ + ____________________________________________________________ + Invalid command! + ____________________________________________________________ + ____________________________________________________________ + Invalid command! + ____________________________________________________________ + ____________________________________________________________ + Invalid command! + ____________________________________________________________ + ____________________________________________________________ + Got it. I've added this task: + [D][ ] everything seems fine (by: now) + Now, you have 5 in the list. + ____________________________________________________________ + ____________________________________________________________ + Here are the tasks in your list: + 1.[T][ ] get a good grade from CS2113 + 2.[D][ ] work hard (by: May) + 3.[E][X] attend group meeting (at: Thursday 10PM) + 4.[E][ ] attend lecture (at: Friday 4PM) + 5.[D][ ] everything seems fine (by: now) + ____________________________________________________________ + ____________________________________________________________ + Nice! I've marked this task as done: + [X] everything seems fine + ____________________________________________________________ + ____________________________________________________________ + Bye. Hope to see you again soon! + ____________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..68bcd3345 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,20 @@ +todo get a good grade from CS2113 +deadline work hard /by May +event attend group meeting /at Thursday 10PM +mark 3 +m 3 +list +ls +e attend lecture /at Friday 4PM +unmark 4 +mark 4 +um 4 +ls +deadline test /at wrong format +event test /by wrong format +todo test /by wrong format +todo test /at wrong format +deadline everything seems fine /by now +ls +m 5 +quit diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 087374464..52821ac1a 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -classpath ..\bin JRobo < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index c9ec87003..31c1c7cc4 100644 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -20,7 +20,7 @@ then fi # run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ../bin Duke < input.txt > ACTUAL.TXT +java -classpath ../bin JRobo < input.txt > ACTUAL.TXT # convert to UNIX format cp EXPECTED.TXT EXPECTED-UNIX.TXT @@ -28,6 +28,7 @@ dos2unix ACTUAL.TXT EXPECTED-UNIX.TXT # compare the output to the expected output diff ACTUAL.TXT EXPECTED-UNIX.TXT +# shellcheck disable=SC2181 if [ $? -eq 0 ] then echo "Test result: PASSED"