diff --git a/README.md b/README.md index 303bc3d19..37aa9b8c2 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,36 @@ -# Duke project template +# Duke Project +---------------------------------------------------------------------------------------- +#### By Noor Sarrah -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. +This program is named after Java mascot Duke. +Given below are the instructions on how to use it -## Setting up in Intellij + +## Table of Contents +1. [Quick Start](#Quickstart) -Prerequisites: JDK 11, update IntelliJ to the most recent version. + 1. [Setting up in Intellij](#SetUpIntellij) + 1. [Setting up Duke](#SetUpDuke) + +1. [Running Duke](#RunDuke) -### On IntelliJ version 2020.3.1 (latest) and beyond + 1. [Command: **`todo `**](#todo) + 2. [Command: **`deadline /by <...>`**](#deadline) + 3. [Command: **`event /at <...>`**](#event) + 4. [Command: **`done `**](#done) + 5. [Command: **`list`**](list) + 6. [Command: **`delete `**](#delete) + 7. [Command: **`find `**](#find) + 8. [Command: **`bye`**](#bye) + +1. [Command Summary](#Commandsummary) + + +## Quick Start + + +### Setting up in Intellij +#### On IntelliJ version 2020.3.1 (latest) and beyond 1. Open IntelliJ (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) 1. Import the project into IntelliJ as follows: @@ -14,13 +38,169 @@ Prerequisites: JDK 11, update IntelliJ to the most recent version. 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). -1. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()`. If the setup is correct, you should see something like the output below. + +### Setting up Duke +1. On the terminal, locate your home folder where you have saved the .jar file. + + 1. cd to change directory + 1. ls to view files in the current directory + +1. Once you have entered the home folder, type the following command: java -jar + + 1. You should see the Duke logo along with a welcome message. Duke is now ready to be used! + 1. You would see this greeting message, for example: + + ``` + Unable to access file at C:\Users\User\Desktop\ip final/duke.txt + To save your task locally, + A new file has been created at: + C:\Users\User\Desktop\ip final\duke.txt + +Hello from + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| + +-------------------------------------------------------------------------------- +Hello! I'm Duke +What can I do for you? +-------------------------------------------------------------------------------- ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` +Back to [Table of Contents](#table-of-contents) + + +## Running Duke + + +i. Command: `todo `
Adds a To-Do to your list
[T] symbol represents To-Do task
e.g. `todo read book` + +Output: +``` +-------------------------------------------------------------------------------- + Got it. I've added this task: + [T][ ] read book + Now you have 1 task in the list. +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +ii. Command `deadline /by <…>`
Adds a Deadline to your list
[D] symbol represents Deadline task
Time should be stated inside <…>
e.g. `deadline finish homework /by 2pm Monday` + +Output: +``` +-------------------------------------------------------------------------------- + Got it. I've added this task: + [D][ ] finish homework (by: 2pm Monday) + Now you have 2 tasks in the list. +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +iii. Command `event /at <…>`
Adds an Event to your list
[E] symbol represents Event task
Time should be stated inside <…>
e.g. `event family dinner/at 5-6pm Saturday` + +Output: +``` +-------------------------------------------------------------------------------- + Got it. I've added this task: + [E][ ] family dinner(at: 7-10pm Saturday) + Now you have 3 tasks in the list. +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +iv. Command `done `
Marks task with in list as 'done'
indicated by [X] in field beside task
e.g. `done 2` + +Output: +``` +-------------------------------------------------------------------------------- + Nice! I've marked this task as done: + [D][X] finish homework (by: 2pm Monday) +-------------------------------------------------------------------------------- + +``` + +Your *tasks.txt* file will look like this: +``` +T --> --> be happy +D --> X --> finish homework --> 2pm Monday +E --> --> family dinner --> 7-10pm Saturday + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +v. Command `list`
Prints all the tasks along with dates and times
e.g. `list` + +Output: +``` +-------------------------------------------------------------------------------- + Here are the tasks in your list: + 1. [T][ ] read book + 2. [D][ ] finish homework(by: 2pm Monday) + 3. [E][ ] book club(at: 11-12pm Tuesday) + 4. [E][ ] family dinner(at: 7-10pm Saturday) +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +vi. Command `delete `
Removes task with in list
e.g. `delete 2` + +Output: +``` +-------------------------------------------------------------------------------- + Noted. I've removed this task: + [D][X] finish homework (by: 2pm Moday) + Now you have 2 tasks in the list. +--------------------------------------------------------------------------------- +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +vii. Command `find `
Finds and filters out the tasks with
e.g. `find book` + +Output: +``` +--------------------------------------------------------------------------------- + Here are the matching tasks in your list: + 1. [T][X] read book + 2. [E][X] book club (at: 11-12pm Tuesday) +--------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +viii. Command `bye`
Exits the program.
e.g. `bye` + +Output: +``` +-------------------------------------------------------------------------------- +Bye. Hope to see you again soon! +-------------------------------------------------------------------------------- +``` +NOTE: Before ending the program, all the tasks will be saved in *tasks.txt* file. + + +## Command Summary +Command |Function +------------ | ------------- +`todo `| Adds a To-Do to your list +`deadline /by <...>` | Adds a Deadline to your list +`event /at <...>` | Adds an Event to your list +`done ` |Marks a task at task number in list as done +`delete ` | Removes a task at task number from list +`list` | Prints all the tasks along with dates and times +`find ` | Finds and filters out the tasks with a desired keyword +`bye` | Exits the program. + diff --git a/docs/README.md b/docs/README.md index fd4406959..00ad1f9bd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,20 +1,206 @@ -# User Guide +# Duke Project +---------------------------------------------------------------------------------------- +#### By Noor Sarrah -## Features +This program is named after Java mascot Duke. +Given below are the instructions on how to use it -### Feature 1 -Description of feature. + +## Table of Contents +1. [Quick Start](#Quickstart) -## Usage + 1. [Setting up in Intellij](#SetUpIntellij) + 1. [Setting up Duke](#SetUpDuke) -### `Keyword` - Describe action +1. [Running Duke](#RunDuke) -Describe action and its outcome. + 1. [Command: **`todo `**](#todo) + 2. [Command: **`deadline /by <...>`**](#deadline) + 3. [Command: **`event /at <...>`**](#event) + 4. [Command: **`done `**](#done) + 5. [Command: **`list`**](list) + 6. [Command: **`delete `**](#delete) + 7. [Command: **`find `**](#find) + 8. [Command: **`bye`**](#bye) -Example of usage: +1. [Command Summary](#Commandsummary) -`keyword (optional arguments)` + +## Quick Start -Expected outcome: + +### Setting up in Intellij +#### On IntelliJ version 2020.3.1 (latest) and beyond + +1. Open IntelliJ (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) +1. Import 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). + + +### Setting up Duke +1. On the terminal, locate your home folder where you have saved the .jar file. + + 1. cd to change directory + 1. ls to view files in the current directory + +1. Once you have entered the home folder, type the following command: java -jar + + 1. You should see the Duke logo along with a welcome message. Duke is now ready to be used! + 1. You would see this greeting message, for example: + + ``` + Unable to access file at C:\Users\User\Desktop\ip final/duke.txt + To save your task locally, + A new file has been created at: + C:\Users\User\Desktop\ip final\duke.txt + +Hello from + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| + +-------------------------------------------------------------------------------- +Hello! I'm Duke +What can I do for you? +-------------------------------------------------------------------------------- + ``` +Back to [Table of Contents](#table-of-contents) + + +## Running Duke + + +i. Command: `todo `
Adds a To-Do to your list
[T] symbol represents To-Do task
e.g. `todo read book` + +Output: +``` +-------------------------------------------------------------------------------- + Got it. I've added this task: + [T][ ] read book + Now you have 1 task in the list. +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +ii. Command `deadline /by <…>`
Adds a Deadline to your list
[D] symbol represents Deadline task
Time should be stated inside <…>
e.g. `deadline finish homework /by 2pm Monday` + +Output: +``` +-------------------------------------------------------------------------------- + Got it. I've added this task: + [D][ ] finish homework (by: 2pm Monday) + Now you have 2 tasks in the list. +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +iii. Command `event /at <…>`
Adds an Event to your list
[E] symbol represents Event task
Time should be stated inside <…>
e.g. `event family dinner/at 5-6pm Saturday` + +Output: +``` +-------------------------------------------------------------------------------- + Got it. I've added this task: + [E][ ] family dinner(at: 7-10pm Saturday) + Now you have 3 tasks in the list. +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +iv. Command `done `
Marks task with in list as 'done'
indicated by [X] in field beside task
e.g. `done 2` + +Output: +``` +-------------------------------------------------------------------------------- + Nice! I've marked this task as done: + [D][X] finish homework (by: 2pm Monday) +-------------------------------------------------------------------------------- + +``` + +Your *tasks.txt* file will look like this: +``` +T --> --> be happy +D --> X --> finish homework --> 2pm Monday +E --> --> family dinner --> 7-10pm Saturday + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +v. Command `list`
Prints all the tasks along with dates and times
e.g. `list` + +Output: +``` +-------------------------------------------------------------------------------- + Here are the tasks in your list: + 1. [T][ ] read book + 2. [D][ ] finish homework(by: 2pm Monday) + 3. [E][ ] book club(at: 11-12pm Tuesday) + 4. [E][ ] family dinner(at: 7-10pm Saturday) +-------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +vi. Command `delete `
Removes task with in list
e.g. `delete 2` + +Output: +``` +-------------------------------------------------------------------------------- + Noted. I've removed this task: + [D][X] finish homework (by: 2pm Moday) + Now you have 2 tasks in the list. +--------------------------------------------------------------------------------- +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +vii. Command `find `
Finds and filters out the tasks with
e.g. `find book` + +Output: +``` +--------------------------------------------------------------------------------- + Here are the matching tasks in your list: + 1. [T][X] read book + 2. [E][X] book club (at: 11-12pm Tuesday) +--------------------------------------------------------------------------------- + +``` +Back to [Table of Contents](#table-of-contents)
Back to [Command Summary](#Commandsummary) + + +viii. Command `bye`
Exits the program.
e.g. `bye` + +Output: +``` +-------------------------------------------------------------------------------- +Bye. Hope to see you again soon! +-------------------------------------------------------------------------------- +``` +NOTE: Before ending the program, all the tasks will be saved in *tasks.txt* file. + + +## Command Summary +Command |Function +------------ | ------------- +`todo `| Adds a To-Do to your list +`deadline /by <...>` | Adds a Deadline to your list +`event /at <...>` | Adds an Event to your list +`done ` |Marks a task at task number in list as done +`delete ` | Removes a task at task number from list +`list` | Prints all the tasks along with dates and times +`find ` | Finds and filters out the tasks with a desired keyword +`bye` | Exits the program. -`outcome` diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..ec050c094 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,31 @@ +public class Deadline extends Task{ + protected String by; + + /** + * + * @param description + * @param by + */ + public Deadline(String description, String by) { + super(description); + this.by = by; + this.SYMBOL = "D"; + } + + public String getDescription() { + return this.description; + } + public String getBy() { + return this.by; + } + + @Override + public String toString() { + return "\t[" + SYMBOL+ "]" + super.toString() + "(" + "by:" + by + ")"; + } + + @Override + public String stringToSave() { + return SYMBOL + getStatusIcon() + ARROW + getDescription() + ARROW + getBy(); + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..5bb8f9de9 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,68 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + public class Duke { + static int TODO_LENGTH = 4; + static int DEADLINE_LENGTH = 9; + static int EVENT_LENGTH = 6; + static int FIND_LENGTH = 5; + + protected Storage storage; + protected TaskList taskList; + protected Ui ui; + + public Duke(String filePath) { + ui = new Ui(filePath); + storage = new Storage(filePath); + try { + taskList = new TaskList(storage.uploadTasks()); + } catch (FileNotFoundException e) { + ui.showLoadingError(); + taskList = new TaskList(storage.createNewFile()); + } + } + public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + String pathOfFile = new File("").getAbsolutePath(); + new Duke(pathOfFile+"/duke.txt").run(); + + } + + public void run() { + Ui.printGreetMessage(); + Scanner myObj = new Scanner(System.in); + String command = myObj.nextLine(); + while (!command.equals("bye")) { + // prints a checklist + if (command.equals("list")) { + taskList.printList(); + + // marks current task as completed + } else if (command.contains("done")) { + taskList.taskCompleted(command); + + // adds tasks into list + } else if (command.contains("delete")) { + taskList.deleteTasks(command); + + // finds task + } else if (command.contains("find")) { + taskList.filterList(command.substring(FIND_LENGTH)); + + // add tasks to list + } else if (command.contains("todo") + || command.contains("deadline") + || command.contains("event")) { + taskList.addTasks(command); + } else { + Ui.printDash(); + System.out.println("\tOOPS!!! Please enter a valid command."); + Ui.printDash(); + } + command = myObj.nextLine(); + } + storage.exitProgram(); } } + diff --git a/src/main/java/EmptyLineException.java b/src/main/java/EmptyLineException.java new file mode 100644 index 000000000..7f324c9e9 --- /dev/null +++ b/src/main/java/EmptyLineException.java @@ -0,0 +1,9 @@ +public class EmptyLineException extends Exception { + public EmptyLineException() { + /*switch (type) { + case "whitespace": + System.out.println("\tOOPS!!! Please enter valid description for Todo"); + break; + }*/ + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..78ad5a841 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,31 @@ +public class Event extends Task{ + protected String by; + + /** + * + * @param description + * @param by + */ + public Event(String description, String by) { + super(description); + this.by = by; + this.SYMBOL = "E"; + } + + public String getDescription() { + return this.description; + } + public String getBy() { + return this.by; + } + + @Override + public String toString() { + return "\t[" + SYMBOL + "]" + super.toString() + "(" + "at:" + by + ")"; + } + + @Override + public String stringToSave() { + return SYMBOL + ARROW + getStatusIcon() + ARROW + getDescription() + ARROW + getBy(); + } +} diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 000000000..ecea45ca9 --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,96 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +public class Storage { + protected String filepath; + protected ArrayList tasks = new ArrayList<>(); + public Storage(String filepath) { + this.filepath = filepath; + } + + /** + * creates new file + * + * @return tasks array + */ + public ArrayList createNewFile() { + + String pathOfFile = new File("").getAbsolutePath(); + File tasksFile = new File(pathOfFile + "/duke.txt"); + try { + if (tasksFile.createNewFile()) { + System.out.println("\tTo save your task locally,\n" + + "\tA new file has been created at:\n\t" + + tasksFile.getAbsolutePath() + "\n"); + } + } catch (IOException e) { + System.out.println("\tThere was an I/O error:\nBye!\n"); + e.printStackTrace(); + } + return tasks; + } + + public String getFilepath() { + return this.filepath; + } + + /** + * + * @return tasks + * @throws FileNotFoundException + */ + public ArrayList uploadTasks() throws FileNotFoundException { + File f = new File(getFilepath()); + Scanner s = new Scanner(f); + while (s.hasNext()) { + String[] task = s.nextLine().split(" ==> "); + if (task[0].equals("T")) { + tasks.add(new Todo(task[2])); + } else if (task[0].equals("D")) { + tasks.add(new Deadline(task[2], task[3])); + } else { + tasks.add(new Event(task[2], task[3])); + } + if (task[1].equals("[X]")) { + tasks.get(tasks.size() - 1).markAsDone(); + } + } + return tasks; + } + + /** + * saves tasks into file + * + * @throws IOException + */ + public void saveTasks() throws IOException { + FileWriter fw = new FileWriter(getFilepath()); + for (Task task : tasks) { + fw.write(task.stringToSave()); + fw.write(System.lineSeparator()); + } + fw.close(); + } + + /** + * exits program + * + * saves tasks into duke.txt + */ + public void exitProgram() { + Ui.printDash(); + System.out.println("Bye. Hope to see you again soon!"); + Ui.printDash(); + try { + saveTasks(); + } catch (IOException e) { + System.out.println("No file was saved due to an I/O error.\n"); + } + } + +} + diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..00c9a70ba --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,35 @@ +public class Task { + protected String description; + protected boolean isDone; + protected String SYMBOL; + protected String ARROW = " ==> "; + + /** + * + * @param description + */ + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String toString() { + return getStatusIcon() + this.description; + } + + public String getStatusIcon() { + return (isDone ? "[X] " : "[ ] " ); //return tick or X symbols + } + + public void markAsDone(){ + this.isDone = true; + } + + public String stringToSave() { + return ""; + } + + public String getDescription() { + return this.description; + } +} diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 000000000..c42a6ba42 --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,177 @@ +import java.util.ArrayList; + +public class TaskList { + protected ArrayList tasks; + public TaskList(ArrayList tasks) { + this.tasks = tasks; + } + + /** + * print list as a checklist when command=list + */ + public void printList() { + Ui.printDash(); + if (tasks.size() != 0) { + Ui.validListMessage(); + for (int i = 1; i <= tasks.size(); ++i) { + System.out.println("\t" + i + "." + tasks.get(i - 1).toString()); + } + } else { + Ui.emptyListMessage(); + } + Ui.printDash(); + } + + /** + * finds keyword from list of tasks + * + * @param filterString + */ + public void filterList(String filterString) { + Ui.printDash(); + tasks.stream() + .filter((s) -> s.getDescription().contains(filterString)) + .forEach(s -> System.out.println(s.toString())); + Ui.printDash(); + } + + /** + * adds tasks into Array List + * @param line + */ + public void addTasks(String line) { + Ui.printDash(); + String[] action = line.split(" "); + if (action[0].equals("todo")) { + try { + line = line.substring(Duke.TODO_LENGTH).trim(); + runTodo(line); + } catch (NullPointerException | EmptyLineException | StringIndexOutOfBoundsException | ArrayIndexOutOfBoundsException e) { + System.out.println("\tOOPS!!! Please enter a valid command."); + Ui.printDash(); + return; + } + } else if (action[0].equals("deadline")) { + try { + line = line.substring(Duke.DEADLINE_LENGTH); + runDeadline(line); + } catch (EmptyLineException | StringIndexOutOfBoundsException | ArrayIndexOutOfBoundsException e) { + System.out.println("\tOOPS!!! Please enter a valid command."); + Ui.printDash(); + return; + } + } else if (action[0].contains("event")) { + try { + line = line.substring(Duke.EVENT_LENGTH); + runEvent(line); + } catch (EmptyLineException | StringIndexOutOfBoundsException | ArrayIndexOutOfBoundsException e) { + System.out.println("\tOOPS!!! Please enter a valid command."); + Ui.printDash(); + return; + } + } else { + Ui.invalidCommandMessage(); + Ui.printDash(); + return; + } + Ui.addedTaskMessage(); + System.out.println(tasks.get(tasks.size()-1).toString()); + System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); + Ui.printDash(); + } + + /** + * remove tasks from Array List + * + * @param command + */ + public void deleteTasks(String command) { + Ui.printDash(); + command = command.replace("delete", " "); + command = command.strip(); + try { + int count = Integer.parseInt(command); + --count; // array starts from 0 + System.out.println("\tNoted. I've removed this task:\n" + tasks.get(count).toString()); + + tasks.remove(tasks.get(count)); + System.out.println("\tNow you have " + tasks.size() + " tasks in the list"); + Ui.printDash(); + } catch (NumberFormatException e) { + Ui.invalidTaskNumberMessage(); + Ui.printDash(); + } + } + + /** + * update list when tasks are done + * + * @param command + */ + public void taskCompleted(String command) { + Ui.printDash(); + int count; + command = command.replace("done", " "); + command = command.strip(); + count = Integer.parseInt(command); + --count; // array starts from 0 + tasks.get(count).markAsDone(); + + try { + count = Integer.parseInt(command); // convert string 2 into int 2 + } catch (NumberFormatException e) { + Ui.emptyTaskNumberMessage(); + Ui.printDash(); + return; + } + try { + --count; // array starts from 0 + tasks.get(count).markAsDone(); + Ui.taskIsDoneMessage(); + System.out.println(tasks.get(count).toString()); + } catch (NullPointerException e) { + Ui.invalidTaskNumberMessage(); + Ui.printDash(); + return; + } + Ui.printDash(); + } + + /** + * + * @param description + */ + public void runDeadline(String description) throws EmptyLineException { + String[] details = description.trim().split("/by"); + if (details.length != 2 || details[0].trim().isEmpty() || details[1].trim().isEmpty()) { + throw new EmptyLineException(); + } + tasks.add(new Deadline(details[0], details[1])); + } + + /** + * + * @param description + * @throws EmptyLineException + */ + public void runTodo(String description) throws EmptyLineException { + if (description.length() == 0) { + throw new EmptyLineException(); + } + tasks.add(new Todo(description)); + } + + /** + * + * @param description + */ + public void runEvent(String description) throws EmptyLineException { + String[] details = description.split("/at"); + if (details.length != 2 || details[0].trim().isEmpty() || details[1].trim().isEmpty()) { + throw new EmptyLineException(); + } + tasks.add(new Event(details[0].trim(), details[1])); + } + + +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..a942450d5 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,21 @@ +public class Todo extends Task{ + /** + * + * @param description + */ + public Todo(String description) { + super(description); + this.SYMBOL = "T"; + } + @Override + public String toString() { return "\t[" + SYMBOL + "]" + super.toString(); + } + public String getDescription() { + return this.description; + } + @Override + public String stringToSave() { + return SYMBOL + ARROW + getStatusIcon() + ARROW + getDescription(); + } + +} diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 000000000..250288d9d --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,88 @@ +public class Ui { + protected String filepath; + public Ui (String filepath) { + this.filepath = filepath; + } + + public static void printDash() { + System.out.println("-".repeat(80)); + } + + public String getFilePath() { + return filepath; + } + + /** + * print welcome message + */ + static void printGreetMessage() { + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + + System.out.println("Hello from\n" + logo); + printDash(); + System.out.println("\tHello! I'm Duke"); + System.out.println("\tWhat can I do for you?"); + printDash(); + } + + /** + * print loading error message + */ + public void showLoadingError() { + System.out.println("\tUnable to access file at "+ getFilePath()); + } + + /** + * print empty task number message + */ + public static void emptyTaskNumberMessage() { + System.out.println("\tOOPS!!! Please indicate task number"); + } + + /** + * print list message + */ + public static void validListMessage() { + System.out.println("\ttHere are the tasks in your list: "); + } + + /** + * print empty list message + */ + public static void emptyListMessage() { + System.out.println("\tYou do not have any pending task."); + } + + /** + * print invalid command message + */ + public static void invalidCommandMessage() { + System.out.println("\tOOPS!!! I'm sorry, but I don't know what that means :-("); + } + + /** + * print added task message + */ + public static void addedTaskMessage() { + System.out.println("\tGot it. I've added this task: "); + } + + /** + * print invalid task number message + */ + public static void invalidTaskNumberMessage() { + System.out.println("\tOOPS!!! Please enter valid task number"); + } + + /** + * print completed task message + */ + public static void taskIsDoneMessage() { + System.out.println("\tNice! I've marked this task as done: "); + } + +}