Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
60a88c0
Level-0: Greet
zh1huang Aug 15, 2021
8747f62
Level-1
zh1huang Aug 25, 2021
ab4602c
Level 2
zh1huang Aug 25, 2021
b43adfa
Level-3
zh1huang Aug 25, 2021
68d69b3
A-CodingStandard
zh1huang Aug 26, 2021
c3cd436
Minor typo changes
zh1huang Aug 26, 2021
6b63884
Level-4
zh1huang Sep 2, 2021
9089498
A-CodeQuality
zh1huang Sep 2, 2021
5aab948
Level 5. Handle Errors
zh1huang Sep 8, 2021
5d11a58
bug fix
zh1huang Sep 8, 2021
aa34d61
Merge branch 'master' into branch-Level-5
zh1huang Sep 8, 2021
753e0a8
Formatting issues
zh1huang Sep 9, 2021
eea7087
Merge branch 'branch-Level-5'
zh1huang Sep 9, 2021
b6f0c99
Merge commit '753e0a8d9f752011003db89b100898f179545b01'
zh1huang Sep 9, 2021
326a6f2
Refactor packages
zh1huang Sep 10, 2021
04badc3
Merge branch 'branch-A-Packages'
zh1huang Sep 10, 2021
30ba786
Add Increment: Level-6 Delete
zh1huang Sep 14, 2021
22b68f0
Merge branch 'branch-Level-6'
zh1huang Sep 15, 2021
3a8a6f4
Cleaned up TaskManager
zh1huang Sep 15, 2021
793418f
Level-7: Save
zh1huang Sep 16, 2021
44695ee
Merge branch 'branch-Level-7'
zh1huang Sep 16, 2021
5cf8dd0
add manifest file
zh1huang Sep 16, 2021
6b52c9e
Bugfix of loading of tasks from file
zh1huang Sep 16, 2021
3d92406
Finalise and clean up Storage class
zh1huang Sep 28, 2021
054a4d6
Added Parser class
zh1huang Sep 28, 2021
770747e
Added Find
zh1huang Sep 28, 2021
99938ba
Added JavaDocs
zh1huang Sep 28, 2021
0b0382a
Merge pull request #1 from zh1huang/branch-Level-9
zh1huang Sep 28, 2021
258e217
Merge branch 'master' into A-JavaDoc
zh1huang Sep 28, 2021
25f9be6
Merge pull request #2 from zh1huang/A-JavaDoc
zh1huang Sep 28, 2021
433daa2
Testing user guide
zh1huang Sep 29, 2021
c89f1a9
test
zh1huang Sep 29, 2021
86057c2
test user guide
zh1huang Sep 29, 2021
60db3bb
Finalise User Guide
zh1huang Sep 29, 2021
b89640a
Final touching up
zh1huang Sep 30, 2021
8fbb849
Update README.md
zh1huang Oct 1, 2021
1e3f1a9
Update README.md
zh1huang Oct 1, 2021
e99c7f8
Update README.md
zh1huang Oct 1, 2021
ab2da15
Update README.md
zh1huang Oct 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions data/output.txt
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
145 changes: 134 additions & 11 deletions docs/README.md
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` |


10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

5 changes: 5 additions & 0 deletions src/main/java/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package duke;

public class DukeException extends Exception {

}
15 changes: 15 additions & 0 deletions src/main/java/duke/command/Duke.java
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();
}
}
48 changes: 48 additions & 0 deletions src/main/java/duke/command/Ui.java
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();
}
}
}
129 changes: 129 additions & 0 deletions src/main/java/duke/data/Storage.java
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) {
Copy link
Copy Markdown

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)

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();
}
}
}
Loading