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

[ngyongjian] iP #208

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
108 changes: 89 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,94 @@
# Duke project template
# Duke - User Guide

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.
Duke is a personal task manager designed to help you stay organized and on top of your to-do list. With its automated features, Duke streamlines task management and can significantly improve your productivity.

## Setting up in Intellij
## Features

Prerequisites: JDK 11, update Intellij to the most recent version.
### 3 Types of Tasks
- `todo` - Adds a simple todo task
- `deadline` - Adds a deadline task with a due date
- `event` - Adds an event task with a start time and an end time

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).<br>
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
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|
### Other Functions
- `mark` - Mark task as done
- `unmark` - Mark task as not done
- `list` - List all tasks
- `find` - Find task(s) containing certain substring
- `delete` - Delete a task
- `bye` - Exit program

## Usage

### todo {Task} - Add a Todo Task
Example: `todo study`
Expected outcome:
```
Got it. I've added this task:
[T][ ] study
```

### deadline {Task} /by {Date/Time} - Add a Deadline Task
Example: `deadline return book /by Sun`
Expected outcome:
```
Got it. I've added this task:
[D][ ] return book (by Sun)
```

### event {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task
Example: `event party /from Fri 6pm /to 8pm`
Expected outcome:
```
Got it. I've added this task:
[E][ ] party (from Fri 6pm to 8pm)
```

### mark {Task Index} - Mark Task as Done
Example: `mark 1`
Expected outcome:
```
Nice! I've marked this task as done:
[T][X] study
```

### unmark {Task Index} - Mark Task as Not Done
Example: `unmark 2`
Expected outcome:
```
OK, I've marked this task as not done yet:
[D][ ] return book (by Sun)
```

### list - List All Tasks
Example: `list`
Expected outcome:
```
1. [T][ ] study
2. [D][ ] return book (by Sun)
3. [E][ ] party (from Fri 6pm to 8pm)
```

### find {Keyword} - Find Task(s) Containing Certain Keyword
Example: `find book`
Expected outcome:
```
Here are the matching tasks in your list:
1. [T][ ] read book
2. [D][ ] return book (by Sun)
```

### delete {Task Index} - Delete Task
Example: `delete 4`
Expected outcome:
```
Noted. I've removed this task:
[T][ ] read book
```

### bye - Leave Program
Example: `bye`
Expected outcome:
```
Bye. Hope to see you again soon.
```

105 changes: 85 additions & 20 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,94 @@
# User Guide
# Duke - User Guide

## Features
Duke is a personal task manager designed to help you stay organized and on top of your to-do list. With its automated features, Duke streamlines task management and can significantly improve your productivity.

### Feature-ABC
## Features

Description of the feature.
### 3 Types of Tasks
- `todo` - Adds a simple todo task
- `deadline` - Adds a deadline task with a due date
- `event` - Adds an event task with a start time and an end time

### Feature-XYZ

Description of the feature.
### Other Functions
- `mark` - Mark task as done
- `unmark` - Mark task as not done
- `list` - List all tasks
- `find` - Find task(s) containing certain substring
- `delete` - Delete a task
- `bye` - Exit program

## Usage

### `Keyword` - Describe action

Describe the action and its outcome.

Example of usage:

`keyword (optional arguments)`

### todo {Task} - Add a Todo Task
Example: `todo study`
Expected outcome:
```
Got it. I've added this task:
[T][ ] study
```

### deadline {Task} /by {Date/Time} - Add a Deadline Task
Example: `deadline return book /by Sun`
Expected outcome:
```
Got it. I've added this task:
[D][ ] return book (by Sun)
```

Description of the outcome.

```
expected output
```
### event {Task} /from {Date/Time} /to {Date/Time} - Add a Event Task
Example: `event party /from Fri 6pm /to 8pm`
Expected outcome:
```
Got it. I've added this task:
[E][ ] party (from Fri 6pm to 8pm)
```

### mark {Task Index} - Mark Task as Done
Example: `mark 1`
Expected outcome:
```
Nice! I've marked this task as done:
[T][X] study
```

### unmark {Task Index} - Mark Task as Not Done
Example: `unmark 2`
Expected outcome:
```
OK, I've marked this task as not done yet:
[D][ ] return book (by Sun)
```

### list - List All Tasks
Example: `list`
Expected outcome:
```
1. [T][ ] study
2. [D][ ] return book (by Sun)
3. [E][ ] party (from Fri 6pm to 8pm)
```

### find {Keyword} - Find Task(s) Containing Certain Keyword
Example: `find book`
Expected outcome:
```
Here are the matching tasks in your list:
1. [T][ ] read book
2. [D][ ] return book (by Sun)
```

### delete {Task Index} - Delete Task
Example: `delete 4`
Expected outcome:
```
Noted. I've removed this task:
[T][ ] read book
```

### bye - Leave Program
Example: `bye`
Expected outcome:
```
Bye. Hope to see you again soon.
```

Binary file added src/main/java/Duke.class
Binary file not shown.
128 changes: 121 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,124 @@
import java.io.IOException;
import java.util.Scanner;

import Exception.DukeException;
import Parser.Parser;
import Storage.DukeStorage;
import Task.Deadline;
import Task.Event;
import Task.Task;
import Task.TaskList;
import Task.Todo;
import UI.Ui;

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
/**
* Constructor to initiate the program
*
* @param filePath the path to the file
* @throws DukeException
* @throws IOException
*
*/
public Duke(String filePath) throws DukeException, IOException {
Ui.greet();
DukeStorage storage = new DukeStorage(filePath);
Task.numberOfTasks = 0;
TaskList taskList = new TaskList(storage);
try (Scanner scan = new Scanner(System.in)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the Java coding standards when using exceptions.

Suggested change
try (Scanner scan = new Scanner(System.in)) {
try {
Scanner scan = new Scanner(System.in)

String input = scan.nextLine();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Arrow Head" code, maybe you can consider avoiding deep nesting?

while (!input.equals("bye")) {
try {
if (input.equals("list")) {
Ui.printList(taskList.getTasks());

} else if (input.startsWith("mark")) {
String[] marks = Parser.processInput(input);
int index = Parser.checkActionInputValidity(marks);
if (index == -1) {
throw new Exception();
}
taskList.getTasks().get(index).markAsDone();
Ui.markMessage(taskList.getTasks(), index);
} else if (input.startsWith("unmark")) {
String[] marks = Parser.processInput(input);
int index = Parser.checkActionInputValidity(marks);
if (index == -1) {
throw new Exception();
}
taskList.getTasks().get(index).markAsNotDone();
Ui.unmarkMessage(taskList.getTasks(), index);
} else if (input.startsWith("find")) {
String findString = Parser.processFindString(input);
if (findString == "") {
throw new Exception();
}
Ui.findTask(taskList.getTasks(), findString);
} else if (input.startsWith("todo", 0)) {
String toDoDesc = Parser.processTodoString(input);
if (toDoDesc == "") {
throw new Exception();
}
Task toDo = new Todo(toDoDesc);
taskList.addTask(toDo);
Ui.printConfirmation(toDo, "TODO");
} else if (input.startsWith("deadline", 0)) {
String[] deadlineArray = Parser.processDeadlineString(input);
if (deadlineArray.length == 0) {
throw new Exception();
}
String deadlineDesc = deadlineArray[0];
String deadlineDay = deadlineArray[1];
Task deadline = new Deadline(deadlineDesc, deadlineDay);
taskList.addTask(deadline);
Ui.printConfirmation(deadline, "DEADLINE");
} else if (input.startsWith("event", 0)) {
String[] eventArray = Parser.processEventString(input);
if (eventArray.length == 0) {
throw new Exception();
}
String eventDesc = eventArray[0];
String start = eventArray[1];
String end = eventArray[2];
Task event = new Event(eventDesc, start, end);
taskList.addTask(event);
Ui.printConfirmation(event, "EVENT");
} else if (input.startsWith("delete")) {
String[] deleteStrings = Parser.processInput(input);
int toDelete = Parser.checkActionInputValidity(deleteStrings);
if (toDelete == -1) {
throw new Exception();
}
Task deleteTask = taskList.getTasks().get(toDelete);
taskList.removeTask(deleteTask);
Task.decrementNumberOfTasks();
Ui.printConfirmation(deleteTask, "DELETE");
} else {
Ui.printConfirmation(null, "UNRECOGNIZED");
;
}
} catch (Exception e) {
Ui.printIncompleteMessage();
}

input = scan.nextLine();
}
} catch (NumberFormatException e) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of exceptions here

e.printStackTrace();
}
Ui.bye();
storage.saveTaskList(taskList.getTasks());
}

/**
* main function
*
* @throws DukeException
* @throws IOException
*
*/
public static void main(String[] args) throws DukeException, IOException {
new Duke("data/duke.txt");
}

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

public class DukeException extends Exception {
/**
* This method throws an exception.
*
* @param message the exception message
*/
public DukeException(String message) {
super(message);
}
}
Loading