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

[Xue Yushan] iP #197

Open
wants to merge 28 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
171 changes: 162 additions & 9 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,181 @@

## Features

### Feature-ABC
### 1. Add tasks

Description of the feature.
Add three types of tasks to the list (todo, deadline,event)

### Feature-XYZ
### 2. List tasks

Display all the tasks in the list

### 3. Delete task
Delete a task from the list with a given index

### 4. Mark task as done
Mark a task as done with a given index

### 5. Find task
Find a task in the list with a given key word

### 6. clear all the tasks
Clear all the tasks in the list

Description of the feature.

## Usage

### `Keyword` - Describe action
### 1. `todo` - add a simple task to the list

Describe the action and its outcome.
Format: `todo DESCRIPTION`

Example of usage:

`keyword (optional arguments)`
`todo do the online quiz`

Expected outcome:

```
Got it. I have added the task to your list.
[T][ ] do the online quiz
```

You have added the task to the list successfully.

### 2. `deadline` - add a deadline to the list

Format: `deadline DESCRIPTION /by TIME`

Example of usage:

`deadline submit individual project /by 1 Oct 23:59`

Expected outcome:

```
Got it. I have added the task to your list.
[D][ ] submit individual project (by: 1 Oct 23:59)
```

You have added the deadline to the list successfully.

### 3. `event` - add a event to the list

Format: `event DESCRIPTION /at TIME`

Example of usage:

`event online programming workshop /at Tuesday`

Expected outcome:

```
Got it. I have added the task to your list.
[E][ ] online programming workshop (by: Tuesday)
```

You have added the event to the list successfully.

### 4. `list` - list all the tasks

Format: `list`

Expected outcome:

```
Here are the tasks in your list:
1. [T][ ] read books
2. [E][X] online meeting (at: 30 Sept 22:00)
```

### 5. `done` - mark a task as done

Format: `done TARGET_INDEX`

Example of usage:

`done 1`

Expected outcome:

Description of the outcome.
```
Nice, I have marked this task as done:
[T][X] read books
```
The first task in the list has been marked as done

### 6. `delete` - delete a task from the list

Format: `delete TARGET_INDEX`

Example of usage:

`delete 2`

Expected outcome:

```
Got it. I have deleted the tasks in your list!
[E][X] online meeting (at: 30 Sept 22:00)
```
The second task in the list has been deleted

### 7. `clear` - clear all the tasks

Format: `clear`

Expected outcome:

```
The tasks in your list have been cleared.
```
The list is empty now

### 8. `find` - find a task containing the given key word(s)

Format: `find TARGET`

Example of usage:

`find read`

Expected outcome:

```
expected output
Here are the matching tasks in your list:
[T][ ] read books
[D][X] read lab manual (by: today 22:00)
```
All the tasks containing the key word have been displayed

### 9. `help` - show help information

Format: `help`

Expected outcome:

```
Here are the usage of all commands:

deadline: add a deadline task to the current list.
Parameters: DESCRIPTION, BY_TIME
Example: deadline take the quiz /by Tuesday

...(omitted)

list: display all tasks in the current list.
Example: list
```
The usages of all commands have been displayed

### 10. `bye` - exit the program

Format: `bye`

Expected outcome:

```
Bye. Hope to see you soon~
```
The program have been terminated, and the changes in each step have been saved, so you can
load the task list record when you start the program next time : )

8 changes: 8 additions & 0 deletions src/main/java/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/main/java/.idea/artifacts/main_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/main/java/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/main/java/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/main/java/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/main/java/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Deadline extends Task {
public String by;

public Deadline(String description, String by) {
super(description);
this.by = by;
}

@Override
public String toString() {
return "[D]" + super.toString() + "(by: " + this.by
+ ")";
}
}
53 changes: 46 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,49 @@
package Duke;

import Duke.Parser.Parser;
import Duke.DukeException.DukeException;
import Duke.Command.*;
import Duke.Storage.Storage;
import Duke.Ui.Ui;
import Duke.Tasks.TaskList;

public class Duke {
private Storage storage;
private TaskList tasks;
private Ui ui;

public Duke(String filePath) {
ui = new Ui();
storage = new Storage(filePath);
try {
tasks = new TaskList(storage.load());
} catch (DukeException e) {
ui.showLoadingError();
tasks = new TaskList();
}
}
/**
* Run the program.
*/
public void run() {
ui.showWelcome();
boolean isExit = false;
while (!isExit) {
try {
String fullCommand = ui.readCommand();
ui.showLine();
Command c = Parser.parse(fullCommand);
c.execute(tasks, ui, storage);
isExit = c.isExit();
} catch (DukeException e) {
ui.showError(e.getMessage());
} finally {
ui.showLine();
}
}
}

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

import Duke.Ui.Ui;
import Duke.Storage.Storage;
import Duke.Tasks.Deadline;
import Duke.Tasks.TaskList;

public class AddDeadlineCommand extends Command {
private final String description;
private final String by;

public static final String COMMAND_WORD = "deadline";
public static final String COMMAND_DESCRIPTION = COMMAND_WORD
+ ": add a deadline task to the current list.\n"
+ " Parameters: DESCRIPTION, BY_TIME\n"
+ " Example: " + COMMAND_WORD + " take the quiz /by Tuesday";

public AddDeadlineCommand(String description, String by) {
this.description = description;
this.by = by;
}

/**
* Execute the add deadline command by adding a new deadline task to TaskList
*
* @param tasks TaskList the command to be executed on
* @param ui Ui used for execution
* @param storage Storage which the command may make change on
*/
@Override
public void execute(TaskList tasks, Ui ui, Storage storage) {
ui.printAddTaskMessage(new Deadline(this.description, this.by));
tasks.addDeadline(this.description, this.by);
ui.printNumOfTasks(tasks);
storage.save(tasks.getTasks());
}
}
37 changes: 37 additions & 0 deletions src/main/java/Duke/Command/AddEventCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package Duke.Command;

import Duke.Ui.Ui;
import Duke.Storage.Storage;
import Duke.Tasks.Event;
import Duke.Tasks.TaskList;

public class AddEventCommand extends Command {
private final String description;
private final String at;

public static final String COMMAND_WORD = "event";
public static final String COMMAND_DESCRIPTION = COMMAND_WORD
+ ": add an event task to the current list.\n"
+ " Parameters: DESCRIPTION, AT_TIME\n"
+ " Example: " + COMMAND_WORD + "attend CS2113 lecture /at Dec 4";

/**
* Execute the add event command by adding a new event task to TaskList
*
* @param tasks TaskList the command to be executed on
* @param ui Ui used for execution
* @param storage Storage which the command may make change on
*/
public AddEventCommand(String description, String at) {
this.description = description;
this.at = at;
}

@Override
public void execute(TaskList tasks, Ui ui, Storage storage) {
ui.printAddTaskMessage(new Event(this.description, this.at));
tasks.addEvent(this.description, this.at);
ui.printNumOfTasks(tasks);
storage.save(tasks.getTasks());
}
}
Loading