-
Notifications
You must be signed in to change notification settings - Fork 191
[Wang Zhihuang] iP #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zh1huang
wants to merge
39
commits into
nus-cs2113-AY2122S1:master
Choose a base branch
from
zh1huang:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Wang Zhihuang] iP #181
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
60a88c0
Level-0: Greet
zh1huang 8747f62
Level-1
zh1huang ab4602c
Level 2
zh1huang b43adfa
Level-3
zh1huang 68d69b3
A-CodingStandard
zh1huang c3cd436
Minor typo changes
zh1huang 6b63884
Level-4
zh1huang 9089498
A-CodeQuality
zh1huang 5aab948
Level 5. Handle Errors
zh1huang 5d11a58
bug fix
zh1huang aa34d61
Merge branch 'master' into branch-Level-5
zh1huang 753e0a8
Formatting issues
zh1huang eea7087
Merge branch 'branch-Level-5'
zh1huang b6f0c99
Merge commit '753e0a8d9f752011003db89b100898f179545b01'
zh1huang 326a6f2
Refactor packages
zh1huang 04badc3
Merge branch 'branch-A-Packages'
zh1huang 30ba786
Add Increment: Level-6 Delete
zh1huang 22b68f0
Merge branch 'branch-Level-6'
zh1huang 3a8a6f4
Cleaned up TaskManager
zh1huang 793418f
Level-7: Save
zh1huang 44695ee
Merge branch 'branch-Level-7'
zh1huang 5cf8dd0
add manifest file
zh1huang 6b52c9e
Bugfix of loading of tasks from file
zh1huang 3d92406
Finalise and clean up Storage class
zh1huang 054a4d6
Added Parser class
zh1huang 770747e
Added Find
zh1huang 99938ba
Added JavaDocs
zh1huang 0b0382a
Merge pull request #1 from zh1huang/branch-Level-9
zh1huang 258e217
Merge branch 'master' into A-JavaDoc
zh1huang 25f9be6
Merge pull request #2 from zh1huang/A-JavaDoc
zh1huang 433daa2
Testing user guide
zh1huang c89f1a9
test
zh1huang 86057c2
test user guide
zh1huang 60db3bb
Finalise User Guide
zh1huang b89640a
Final touching up
zh1huang 8fbb849
Update README.md
zh1huang 1e3f1a9
Update README.md
zh1huang e99c7f8
Update README.md
zh1huang ab2da15
Update README.md
zh1huang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| T | 0 | add book | ||
| D | 1 | bye | 1040 | ||
| T | 0 | see book |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,152 @@ | ||
| # User Guide | ||
| toDoList is a Command Line Interface (CLI) application that | ||
| helps you to manage your tasks. | ||
|
|
||
| ## Contents of User Guide | ||
| - Features | ||
| 1. [`list` - List all tasks](#listing-all-tasks) | ||
| 2. [`todo` - Create a todo task](#adding-a-todo) | ||
| 3. [`deadline` - Create a deadline task](#adding-a-deadline) | ||
| 4. [`event` - Create an event task](#adding-an-event) | ||
| 5. [`done` - Mark task as done](#mark-as-done) | ||
| 6. [`delete` - Delete task from list](#delete-task) | ||
| 7. [`find` - Find tasks based on keyword](#find-task) | ||
| 8. [`bye` - Exit program](#exit-program) | ||
| - Command Summary | ||
|
|
||
| ## Features | ||
| toDoList supports 3 types of tasks: `To-Do`, `Deadline` and `Event`. | ||
|
|
||
| ### Listing all tasks | ||
|
|
||
| Shows a list of all tasks. | ||
|
|
||
| ### Feature-ABC | ||
| Format: `list` | ||
|
|
||
| Example of usage: | ||
| ``` | ||
| list | ||
| ``` | ||
| Expected outcome: | ||
| ``` | ||
| Here are the tasks in your list: | ||
| 1.[T][ ] add book | ||
| 2.[E][X] see book (at: 29/09/21 2359) | ||
| 3.[D][ ] submit work (by: 30/10/21 1800) | ||
| ``` | ||
|
|
||
| Description of the feature. | ||
| ### Adding a Todo | ||
| Adds a Todo task | ||
|
|
||
| ### Feature-XYZ | ||
| Format: `todo <TASK_NAME>` | ||
|
|
||
| Description of the feature. | ||
| Example of usage: | ||
| ``` | ||
| todo add book | ||
| ``` | ||
| Expected outcome: | ||
| ``` | ||
| Got it. I've added this task: | ||
| [T][ ] add book | ||
| Now you have 6 tasks in the list. | ||
| ``` | ||
|
|
||
| ## Usage | ||
| ### Adding a Deadline | ||
| Adds a Deadline task, followed by date | ||
|
|
||
| ### `Keyword` - Describe action | ||
| Format: `deadline <TASK_NAME> /by <DATE>` | ||
|
|
||
| Describe the action and its outcome. | ||
| Example of usage: | ||
| ``` | ||
| deadline finish assignment /by 29/09/21 2359 | ||
| ``` | ||
| Expected outcome: | ||
| ``` | ||
| Got it. I've added this task: | ||
| [D][ ] finish assignment (by: 29/09/21 2359) | ||
| Now you have 7 tasks in the list. | ||
| ``` | ||
|
|
||
| Example of usage: | ||
| ### Adding an Event | ||
| Adds an Event task, followed by date | ||
|
|
||
| `keyword (optional arguments)` | ||
| Format: `event <TASK_NAME> /at <DATE>` | ||
|
|
||
| Example of usage: | ||
| ``` | ||
| event birthday party /at 30/10/21 1800 | ||
| ``` | ||
| Expected outcome: | ||
| ``` | ||
| Got it. I've added this task: | ||
| [E][ ] birthday party (at: 30/10/21 1800) | ||
| Now you have 8 tasks in the list. | ||
| ``` | ||
|
|
||
| ### Mark as done | ||
| Marks a task as done | ||
|
|
||
| Description of the outcome. | ||
| Format: `done <TASK_INDEX>` | ||
|
|
||
| Example of usage: | ||
| ``` | ||
| expected output | ||
| done 3 | ||
| ``` | ||
| Expected outcome: | ||
| ``` | ||
| Nice! I've marked this task as done: | ||
| [D][X] finish assignment (by: 29/09/21 2359) | ||
| ``` | ||
|
|
||
| ### Delete task | ||
| Deletes a task from the list. | ||
|
|
||
| Format: `delete <TASK_INDEX>` | ||
|
|
||
| Example of usage: | ||
| ``` | ||
| delete 2 | ||
| ``` | ||
| Expected outcome: | ||
| ``` | ||
| Noted. I've removed this task: | ||
| [E][ ] birthday party (at: 30/10/21 1800) | ||
| Now you have 3 tasks in the list. | ||
| ``` | ||
|
|
||
| ### Find task | ||
| Finds tasks given keyword | ||
|
|
||
| Format: `find <KEYWORD>` | ||
|
|
||
| Example of usage: | ||
| ``` | ||
| find book | ||
| ``` | ||
| Expected outcome: | ||
| ``` | ||
| Here are the matching tasks in your list: | ||
| 1.[D][ ] throw book (by: 01/01/22) | ||
| 2.[T][ ] buy new book | ||
| ``` | ||
|
|
||
|
|
||
| ### Exit program | ||
| Exits from toDoList. | ||
|
|
||
| Format: `bye` | ||
|
|
||
| ## Command Summary | ||
|
|
||
| |Commands |Format, Examples | | ||
| | ---- | ---- | | ||
| |**List** | `list` | | ||
| |**Todo** | `todo <TASK_NAME>` <br> eg: `todo add book` | | ||
| |**Deadline**| `deadline <TASK_NAME> /by <DATE>` <br> eg: `deadline finish assignment /by 29/09/21 2359`| | ||
| |**Event** | `event <TASK_NAME> /at <DATE>` <br> eg: `event birthday party /at 30/10/21 1800` | | ||
| |**Done** | `done <TASK_INDEX>` <br> eg: `done 3` | | ||
| |**Delete** | `delete <TASK_INDEX>` <br> eg: `delete 2` | | ||
| |**Find** | `find <KEYWORD>` <br> eg: `find book` | | ||
| |**Bye** | `bye` | | ||
|
|
||
|
|
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package duke; | ||
|
|
||
| public class DukeException extends Exception { | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package duke.command; | ||
|
|
||
| import duke.task.TaskManager; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class Duke { | ||
|
|
||
| public static void main(String[] args) { | ||
| TaskManager taskManager = new TaskManager(); | ||
| Scanner scanner = new Scanner(System.in); | ||
| Ui ui = new Ui(taskManager, scanner); | ||
| ui.start(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package duke.command; | ||
|
|
||
| import duke.data.Storage; | ||
| import duke.task.Parser; | ||
| import duke.task.TaskManager; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class Ui { | ||
| private TaskManager taskManager; | ||
| private Scanner scanner; | ||
|
|
||
| private static final String LINE = " ____________________________________________________________\n"; | ||
| private static final String LOGO = "\n" + | ||
| " \n" + | ||
| " ,--. ,------. ,--. ,--. ,--. \n" + | ||
| ",-' '-.,---.| .-. \\ ,---.| | `--',---,-' '-. \n" + | ||
| "'-. .-| .-. | | \\ | .-. | | ,--( .-'-. .-' \n" + | ||
| " | | ' '-' | '--' ' '-' | '--| .-' `)| | \n" + | ||
| " `--' `---'`-------' `---'`-----`--`----' `--' \n" + | ||
| " \n"; | ||
| private static final String GREETINGS = LINE | ||
| + LOGO | ||
| + " Welcome to the toDoList Chatbot\n" | ||
| + " What would you like to do today?\n" | ||
| + LINE; | ||
|
|
||
| public Ui(TaskManager taskManager, Scanner scanner) { | ||
| this.taskManager = taskManager; | ||
| this.scanner = scanner; | ||
| } | ||
|
|
||
| /** | ||
| * Starts the program. | ||
| */ | ||
| public void start() { | ||
| Storage.loadData(); | ||
| System.out.println(GREETINGS); | ||
| boolean isExit = false; | ||
| while (!isExit) { | ||
| String input = scanner.nextLine(); | ||
| System.out.print(LINE); | ||
| isExit = Parser.parse(input); | ||
| System.out.print(LINE); | ||
| Storage.saveData(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| package duke.data; | ||
|
|
||
| import duke.task.Deadline; | ||
| import duke.task.Event; | ||
| import duke.task.Task; | ||
| import duke.task.TaskManager; | ||
|
|
||
| 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.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Storage { | ||
|
|
||
| private static final String PATH_NAME = "data/output.txt"; | ||
| private static final String FILE_CREATION_ERROR = "Error in creating file"; | ||
| private static final String SEPARATOR = " | "; | ||
|
|
||
| /** | ||
| * Creates file inside its directory. | ||
| */ | ||
| public static void createFile(){ | ||
| try { | ||
| Path path = Paths.get(PATH_NAME); | ||
| Files.createDirectories(path.getParent()); | ||
| } catch (IOException e) { | ||
| System.out.println(FILE_CREATION_ERROR); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Reads content from file and adds into TaskList. | ||
| * | ||
| * @param filePath Path where file is read from. | ||
| * @throws FileNotFoundException If file not found. | ||
| */ | ||
| public static void readFromFile(String filePath) throws FileNotFoundException { | ||
| File file = new File(filePath); | ||
| Scanner scanner = new Scanner(file); | ||
| while (scanner.hasNext()) { | ||
| String line = scanner.nextLine(); | ||
| String[] details = line.split("\\|"); | ||
| String taskType = details[0].trim(); | ||
| boolean isDone = details[1].trim().equals("1"); | ||
| String description = details[2].trim(); | ||
| String timing; | ||
| switch (taskType) { | ||
| case "T": | ||
| TaskManager.loadToDoFromFile(description, isDone); | ||
| break; | ||
| case "D": | ||
| timing = details[3].trim(); | ||
| TaskManager.loadDeadlineFromFile(description, timing, isDone); | ||
| break; | ||
| case "E": | ||
| timing = details[3].trim(); | ||
| TaskManager.loadEventFromFile(description, timing, isDone); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Appends to end of file. | ||
| * | ||
| * @param filePath Path to append file to. | ||
| * @param textToAppend Text to be appended. | ||
| * @throws IOException If an I/O exception has occurred. | ||
| */ | ||
| public static void appendToFile(String filePath, String textToAppend) throws IOException { | ||
| FileWriter fw = new FileWriter(filePath, true); // create a FileWriter in append mode | ||
| fw.write(textToAppend); | ||
| fw.close(); | ||
| } | ||
|
|
||
| /** | ||
| * Writes to file. | ||
| * | ||
| * @param filePath Path to write file to. | ||
| * @throws IOException If an I/O exception has occurred. | ||
| */ | ||
| public static void writeToFile(String filePath) throws IOException { | ||
| String textToAppend; | ||
| FileWriter fw = new FileWriter(filePath, false); | ||
| fw.write(""); //clear the file | ||
| fw.close(); | ||
| for (Task task: TaskManager.taskList) { | ||
| String taskType = task.getIcon(); | ||
| String status = task.getStatus(); | ||
| String description = task.getDescription(); | ||
| String timing = task.getTime(); | ||
|
|
||
| textToAppend = taskType + SEPARATOR + status + SEPARATOR + description; | ||
| if (task instanceof Event || task instanceof Deadline) { | ||
| textToAppend += SEPARATOR + timing; | ||
| } | ||
| textToAppend += "\n"; | ||
| appendToFile(filePath, textToAppend); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Saves data into file. | ||
| */ | ||
| public static void saveData() { | ||
| try { | ||
| Path path = Paths.get(PATH_NAME); | ||
| Files.createDirectories(path.getParent()); | ||
| writeToFile(PATH_NAME); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Loads data from file. | ||
| */ | ||
| public static void loadData() { | ||
| try { | ||
| readFromFile(PATH_NAME); | ||
| } catch (FileNotFoundException e) { | ||
| createFile(); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid complicated expressions, is there any way you can extract it out or make this more streamlined? (hint: use booleans)