Skip to content
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

[Sebastian Soewanto] iP #205

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
160 changes: 147 additions & 13 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,163 @@
# User Guide
Duke is an application for managing task list via a **Command Line Interface (CLI)** that helps you to remember the tasks that you do not wish to forget.

## Features
+ [Quick Start](#quick-start)
+ [Features](#features)
+ [Create a ToDo task: `todo`](#create-a-todo-task--todo)
+ [Create a Deadline task: `deadline`](#create-a-deadline-task--deadline)
+ [Create an Event task: `event`](#create-an-event-task--event)
+ [Mark a task as done: `mark`](#mark-a-task-as-done--mark)
+ [Mark a task as not done: `unmark`](#mark-a-task-as-not-done--unmark)
+ [List out the tasks: `list`](#list-out-the-tasks--list)
+ [Delete a specific task: `delete`](#delete-a-specific-task--delete)
+ [Find a task by keyword: `find`](#find-a-task-by-keyword--find)
+ [Exit the application: `bye`](#exit-the-application--bye)

### Feature-ABC
### Quick Start
1. Ensure that you have Java 11 installed.
2. Download the latest duke.jar from [here]().
3. Copy the file to the folder you want your Duke to be in.
4. Open a command terminal, navigate into the folder using `cd`
5. Run the application using `-jar duke.jar`

Description of the feature.
### Features
#### Create a ToDo Task: `todo`
Adds a todo task into the list.

### Feature-XYZ
Format: `todo TASK_NAME`

Description of the feature.
Example: `todo borrow book`

## Usage
Output:
```
____________________________________________________
Got it. I've added this tasks:
[T][ ] borrow book
Now you have 1 tasks in the list.
____________________________________________________
```
#### Create a Deadline Task: `deadline`
Adds a deadline task into the list that includes the date of the deadline.

Format: `deadline TASK_NAME /by DATE`

### `Keyword` - Describe action
Example: `deadline return book /by Sunday`

Output:
```
____________________________________________________
Got it. I've added this tasks:
[D][ ] return book(by: Sunday)
Now you have 2 tasks in the list.
____________________________________________________
```

Describe the action and its outcome.
#### Create an Event Task: `event`
Adds an event task into the list that include the start and end time of the event.

Format: `event TASK_NAME /from START_TIME /to END_TIME`

Example: `event project meeting /from Mon 2pm /to 4pm`

Output:
```
____________________________________________________
Got it. I've added this tasks:
[E][ ] project meeting(from: Mon 2pm to: 4pm)
Now you have 3 tasks in the list.
____________________________________________________
```

Example of usage:
#### Mark a task as done: `mark`
Mark an existing task in the list as completed.

Format: `mark TASK_NUMBER`

Example: `mark 1`

Output:
```
____________________________________________________
Nice! I've marked this task as done:
[T][X] borrow book
____________________________________________________
```

#### Mark a task as not done: `unmark`
Mark an existing task in the list as not completed.

Format: `unmark TASK_NUMBER`

Example: `unmark 1`

Output:
```
____________________________________________________
Nice! I've marked this task as not done yet:
[T][ ] borrow book
____________________________________________________
```

#### List out the tasks: `list`
List out the tasks in the order it was added.

Format: `list`

Example: `list`

Output:
```
____________________________________________________
Here are the tasks in your list:
1.[T][ ] borrow book
2.[D][ ] return book(by: Sunday)
3.[E][ ] project meeting(from: Mon 2pm to: 4pm)
____________________________________________________
```


#### Delete a specific task: `delete`
Remove a specific task by its number in the list.

Format: `delete TASK_NUMBER`

Example: `delete 3`

Output:
```
____________________________________________________
Noted. I've removed this task:
[E][ ] project meeting(from: Mon 2pm to: 4pm)
Now you have 2 tasks in the list.
____________________________________________________
```

#### Find a task by keyword: `find`
Find the tasks containing the keyword.

Format: `find KEYWORD`

Example: `find book`

Output:
```
____________________________________________________
Here are the matching tasks in your list:
1.[T][ ] borrow book
2.[D][ ] return book(by: Sunday)
____________________________________________________
```

`keyword (optional arguments)`
#### Exit the application: `bye`
Exits the application Duke.

Expected outcome:
Format: `bye`

Description of the outcome.
Example: `bye`

Output:
```
expected output
____________________________________________________
Bye. Hope to see you again soon!
____________________________________________________
```
73 changes: 73 additions & 0 deletions src/main/java/Data.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import duke.task.Task;

import java.io.File;
import java.io.FileWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;
import java.io.IOException;

public class Data {

protected String filePath;
protected String fileDirectory;


public Data(String filePath, String fileDirectory) {
this.filePath = filePath;
this.fileDirectory = fileDirectory;
}

/**
* Checks if the directory exists and creates one if it does not.
* Then it will check if the file exists and creates one if it does not.
*
* @throws IOException if there is an error in creating the directory or file.
*/
public void checkFile() throws IOException {
File file = new File(filePath);
File directory = new File(fileDirectory);
if (!directory.isDirectory()) {
Path path = Paths.get(String.valueOf(directory));
Files.createDirectories(path);
}
if (!file.isFile()) {
Files.createFile(Path.of(filePath));
}
}
/**
* Reads in the file duke.txt and categorise into its respective task: Todo, Deadline or Event.
*
* @param taskList taskList contains the functions to read and create the tasks correspondingly
* @throws IOException if there is and error when reading in the file.
*/
public void readFile(TaskList taskList) throws IOException {
File file = new File(filePath);
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String input = scanner.nextLine();
String[] substring = input.split("-|\\|");
if (substring[0].trim().equals("T")) {
taskList.readTodoTask(substring[1].trim(), substring[2].trim());
} else if (substring[0].trim().equals("D")) {
taskList.readDeadlineTask(substring[1].trim(), substring[2].trim(), substring[3].trim());
} else if (substring[0].trim().equals("E")) {
taskList.readEventTask(substring[1].trim(), substring[2].trim(), substring[3].trim(), substring[4].trim());
}
}
}

/**
* Writes the updated of tasks in the ArrayList back into the file duke.txt
*
* @throws IOException if there is an error in writing the file.
*/
public void writeFile() throws IOException {
FileWriter fileWriter = new FileWriter(filePath);
for (Task task : TaskList.tasks) {
fileWriter.write(task.saveToFile());
}
fileWriter.close();
}
}
64 changes: 58 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,62 @@
import duke.exception.CommandNotFoundException;
import duke.exception.DukeException;
import duke.exception.IllegalFormatException;
import duke.exception.InvalidInputException;
import duke.exception.MissingInputException;

import java.io.FileNotFoundException;
import java.io.IOException;

public class Duke {

protected UI ui = new UI();
protected TaskList taskList = new TaskList();
protected Parser parser = new Parser();
protected Data data = new Data("data/duke.txt", "data");

public void run(){
ui.printHelloMessage();
boolean proceedToNextCommand = true;
try {
data.readFile(taskList);
} catch (FileNotFoundException e) {
try {
data.checkFile();
} catch (IOException checkException) {
ui.printErrorMessage("File not found. I will be creating one for you.");
}
} catch (IOException readException) {
ui.printErrorMessage("I'm sorry, but there is an error in reading the file.");
}
while (proceedToNextCommand) {
String userInput = UI.readCommand();
ui.printDivider();
try {
proceedToNextCommand = parser.executeCommand(userInput);
if (userInput.equals("bye")) {
data.writeFile();
break;
}
} catch (CommandNotFoundException e) {
ui.printErrorMessage("I'm sorry, but I don't know what that means.");
} catch (MissingInputException e) {
ui.printErrorMessage("Description of the command is empty.");
} catch (IllegalFormatException e) {
ui.printErrorMessage("Please check the format of command in the user guide.");
} catch (InvalidInputException e) {
ui.printErrorMessage("Please check if the input is correct.");
} catch (NumberFormatException e) {
ui.printErrorMessage("Task number should be an integer.");
} catch (IOException e) {
ui.printErrorMessage("I'm sorry, but there is an error in writing the file.");
} catch (DukeException e) {
ui.printErrorMessage("Error...");
}
ui.printDivider();
}
}

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
new Duke().run();
}
}
44 changes: 44 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import duke.exception.CommandNotFoundException;
import duke.exception.DukeException;

import java.io.IOException;

public class Parser {
protected TaskList tasklist = new TaskList();
protected UI ui = new UI();

protected Data data = new Data("data/duke.txt", "data");

/**
* Interprets the command that was given by the user input and execute the commands accordingly to its specified usage.
*
* @return false if "bye" executed to close the loop and exit the application
* @param userInput Input string that is provided by user in the CLI.
* @throws CommandNotFoundException if command is not found.
*/
public boolean executeCommand(String userInput) throws DukeException {
if (userInput.equals("bye")) {
ui.printByeMessage();
return false;
} else if (userInput.equals("list")) {
tasklist.showList();
} else if (userInput.startsWith("todo")) {
tasklist.createTodo(userInput);
} else if (userInput.startsWith("deadline")) {
tasklist.createDeadline(userInput);
} else if (userInput.startsWith("event")) {
tasklist.createEvent(userInput);
} else if (userInput.startsWith("mark")) {
tasklist.markTask(userInput);
} else if (userInput.startsWith("unmark")) {
tasklist.unmarkTask(userInput);
} else if (userInput.startsWith("delete")) {
tasklist.deleteTask(userInput);
} else if (userInput.startsWith("find")) {
tasklist.findTask(userInput);
} else {
throw new CommandNotFoundException();
}
return true;
}
}
Loading