Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
cf226b9
Level-0 Greetings
alwaysnacy Aug 15, 2020
661419a
Level-1
alwaysnacy Aug 26, 2020
5dd0af7
Level-2
alwaysnacy Aug 26, 2020
d805700
Level-3
alwaysnacy Aug 26, 2020
d6076c7
A-CodingStandard
alwaysnacy Aug 26, 2020
ce3009c
Level-4
alwaysnacy Sep 2, 2020
b870f6e
Level-4: Further Refine
alwaysnacy Sep 3, 2020
cd3bd7b
A-TextUiTesting
alwaysnacy Sep 3, 2020
48aca69
A-CodeQuality
alwaysnacy Sep 16, 2020
c3f7286
Level-5
alwaysnacy Sep 16, 2020
87dfd42
A-Exceptions
alwaysnacy Sep 16, 2020
f2d8a8b
Merge branch 'branch-Level-5' into master
alwaysnacy Sep 16, 2020
f03f60c
A-Packages
alwaysnacy Sep 16, 2020
92231d6
Further A-Packages Modify: Move Duke.java to java.duke.main
alwaysnacy Sep 16, 2020
beaafda
Merge branch 'branch-A-Packages' into master
alwaysnacy Sep 16, 2020
038dbce
Level-6
alwaysnacy Sep 16, 2020
e9fd8cd
Merge branch 'branch-Level-6' into master
alwaysnacy Sep 16, 2020
c16b076
Level-7
alwaysnacy Sep 16, 2020
9673382
Level-7-parallel
alwaysnacy Sep 16, 2020
3a18266
Level-6-branch-parallel
alwaysnacy Sep 16, 2020
39e651d
Level-6-parallel-2
alwaysnacy Sep 16, 2020
eddc369
Merge branch 'branch-Level-6' into master
alwaysnacy Sep 16, 2020
f23e836
Merge branch 'branch-Level-7' into master
alwaysnacy Sep 16, 2020
c6412d8
Modify 'Delete' and change List to ArrayList in TaskManager
alwaysnacy Sep 23, 2020
0a70e7c
A-MoreOOP
alwaysnacy Sep 29, 2020
7adc640
add Storage class
alwaysnacy Sep 30, 2020
8262d7e
Level-9
alwaysnacy Sep 30, 2020
d2a17cb
Level-8
alwaysnacy Sep 30, 2020
fe30f57
A-JavaDoc
alwaysnacy Oct 2, 2020
93bb434
A-UserGuide
alwaysnacy Oct 2, 2020
7b45a8e
edit README.md
alwaysnacy Oct 2, 2020
2f67e3d
edit UserGuide
alwaysnacy Oct 2, 2020
3af1f2a
edit Storage and Parser
alwaysnacy Oct 2, 2020
883a5a5
add datetime
alwaysnacy Oct 2, 2020
993b2f7
add more OOP
alwaysnacy Oct 2, 2020
b2e4663
add comments
alwaysnacy Oct 2, 2020
e0efef5
Merge branch 'branch-Level-8' into master
alwaysnacy Oct 2, 2020
1772ef0
Merge branch 'branch-Level-9' into master
alwaysnacy Oct 2, 2020
fe37213
further modify
alwaysnacy Oct 2, 2020
fbf539d
more OOP
alwaysnacy Oct 2, 2020
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
119 changes: 93 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,93 @@
# Duke project template

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.

## Setting up in Intellij

Prerequisites: JDK 11, update Intellij to the most recent version.

1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project dialog first)
1. Set up the correct JDK version, as follows:
1. Click `Configure` > `Structure for New Projects` and then `Project Settings` > `Project` > `Project SDK`
1. If JDK 11 is listed in the drop down, select it. If it is not, click `New...` and select the directory where you installed JDK 11
1. Click `OK`
1. Import the project into Intellij as follows:
1. Click `Open or Import`.
1. Select the project directory, and click `OK`
1. If there are any further prompts, accept the defaults.
1. After the importing is complete, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()`. If the setup is correct, you should see something like the below:
```
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|
```
# User Guide



## Starting Duke program

### Using Command Line

2. Open Command Prompt (on Windows) or Terminal (on Mac)
3. Change directory to the folder where `ip.jar` file are stored by `cd` into `ip\out\artifacts\ip_jar`
4. Change the font in Command Prompt to NSimSan by typing `chcp 65001` in Command Prompt
6. Type in `java -Dfile.encoding=UTF-8 -jar ip.jar`, then enter to run Duke.




## Viewing possible actions: `help`
Format `help`

## Adding a task to Duke: `todo` `event` `deadline`
Words in `UPPERCASE` are the parameters

### Adding a Todo: `todo`
Adds a Todo to the Duke

_Format_: `todo DESCRIPTION`

__Example:__

- `todo borrow The kite runner`
- `todo return the pen get from Jen`

### Adding an Event
Adds an Event to the Duke

_Format_: `event DESCRIPTION /at YYYY-MM-DD HH:MM`

__Example:__

- `event project meeting /at 2020-09-23 12:00`
- `event join the BumbleBee Welcome Tea /at 2020-09-23 12:00`

### Adding a Deadline
Adds a Deadline to the Duke

_Format_: `deadline DESCRIPTION /by YYYY-MM-DD HH:MM`

__Example:__

- `deadline project report /by 2020-09-23 12:00`
- `deadline join the BumbleBee First Evaluation /by 2020-09-23 12:00`

## Listing all tasks: `list`
Shows a list of all tasks in Duke, along with their details, status and ID

_Format_: `list`

## Marking task as done: `done`
Marks a task specified by its ID as done. You have to list all the tasks first using `list` before using `done`

_Format_: `done ID`

__Example__:

- `list` `done 1`: will mark the first task in the last shown list as done
- `list` `done 3`: will mark the third task in the last shown list as done

## Deleting task: `delete`
Deletes a task specified by its ID. You have to list all the tasks first using `list` before using `delete`

_Format_: `delete ID`

__Example__:

- `list` `delete 1`: will delete the first task in the last shown list
- `list` `delete 3`: will delete the third task in the last shown list

## Find task: `find`
Finds tasks containing a given keyword

_Format:_ `find KEYWORD`

__Example:__:

- `find book`: will return all tasks having _book_ in their description
- `find project`: will return all tasks having _project_ in their description

## Exiting the program: `bye`
Exits the Duke

_Format:_ `bye`


4 changes: 4 additions & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[T][✘] join sports club[T][✘] read book[D][✘] return book (by: June 6th)[E][✘] project meeting (at: Aug 6th 2-4pm)[T][✘] read book
[D][✘] return book (by: June 6th)
[E][✘] project meeting (at: Aug 6th 2-4pm)
[T][✘] join sports club
5 changes: 5 additions & 0 deletions duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
T | 0 | read book
E | 0 | project meeting | 2020-11-13 19:00
T | 0 | borrow book
D | 0 | return book | 2020-11-24 03:00
E | 0 | project meeting | 2020-09-23 12:00
Empty file added null
Empty file.
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: duke.Duke

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

import duke.action.Action;
import duke.action.ActionResult;
import duke.action.ExitAction;
import duke.exception.DukeException;
import duke.parser.Parser;
import duke.storage.Storage;
import duke.task.TaskManager;
import duke.ui.TextUi;

public class Duke {

private TaskManager todayList;
private TextUi ui;
private String filePath = "duke.txt";
private Storage storage;

public static void main(String[] args) {
new Duke().run();
}

/**
* Runs the program until termination.
*/
public void run() {
loadData();
start();
runCommandLoopUntilExitCommand();
exit();
}

private void loadData() {
storage = new Storage(filePath);
try {
todayList = storage.loadFromStorage();
} catch (DukeException e) {
todayList = new TaskManager();
}
}

private void start() {
this.ui = new TextUi();
ui.printWelcomeMessage();
}

private void exit() {
ui.printGoodbyeMessage();
System.exit(0);
}

private void runCommandLoopUntilExitCommand() {
Action action;
do {
String userInput = ui.getUserInput();
action = new Parser().parseInput(userInput);
ActionResult result = executeCommand(action);
action.modifyFile();
ui.printActionResult(result);
} while (!ExitAction.isExit(action));
}

private ActionResult executeCommand(Action action) {
try {
action.setData(todayList);
ActionResult result = action.executeAction();
return result;
} catch (Exception e) {
ui.printScreen(e.getMessage());
throw new RuntimeException(e);
}
}
}

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

import duke.exception.DukeException;
import duke.storage.Storage;
import duke.task.TaskManager;
import java.nio.file.Paths;

public class Action {
protected TaskManager taskList;
private int taskID = -1;

protected Action() {
}

/**
* Executes the action and returns the result.
*/
public ActionResult executeAction() {
throw new UnsupportedOperationException("To be implemented by child classes");
}

/**
* Supplies the data the action will be executed on.
*/
public void setData(TaskManager taskList) {
this.taskList = taskList;
}

/**
* Extracts the task with target taskID in the last shown list
*/
public int getTargetIndex() {
return taskID;
}

/**
* modifies the default Storage file (duke.txt) whenever an action is executed
*/
public void modifyFile() {
try {
Storage.saveToStorage(taskList, Paths.get(Storage.DEFAULT_STORAGE_FILEPATH));
} catch (DukeException e) {
e.printStackTrace();
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/duke/action/ActionResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package duke.action;

public class ActionResult {

public final String outputToScreen;

/**
* constructs the ActionResult class
*
* @param outputToScreen a String to be printed out to the user as a result of an action
*/
public ActionResult(String outputToScreen) {
this.outputToScreen = outputToScreen;
}

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

public abstract class AddAction extends Action {
public static final String MESSAGE = "Got it. I've added this task:\n %1$s\n"
+ "Now you have %2$d tasks in the list.";

public abstract ActionResult executeAction();

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

import duke.task.Deadline;
import duke.task.Task;

import java.time.LocalDateTime;

/**
* Adds a Deadline task to the TaskManager.
*/
public class AddDeadline extends AddAction{
public static final String ACTION = "deadline";
public static final String HELP_MESSAGE = ACTION + ": Adds a Deadline to the task list of DUKE.\n"
+ " Parameters: DESCRIPTION /by YYYY-MM-DD HH:MM\n"
+ " Example: " + ACTION
+ " submit the third Math homework /by 2020-10-03 23:59";
public static Task task;

public AddDeadline(String description, LocalDateTime byTime) {
task = new Deadline(description, getTargetIndex(), byTime);
}

@Override
public ActionResult executeAction() {
taskList.addTask(task);
return new ActionResult(String.format(MESSAGE, task, taskList.getNumTasks()));
}
}
29 changes: 29 additions & 0 deletions src/main/java/duke/action/AddEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package duke.action;

import duke.task.Event;
import duke.task.Task;

import java.time.LocalDateTime;

/**
* Adds an Event task to the TaskManager.
*/
public class AddEvent extends AddAction {
public static final String ACTION = "event";
public static Task task;
public static final String HELP_MESSAGE = ACTION + ": Adds an Event to the task list of DUKE.\n"
+ " Parameters: DESCRIPTION /at YYYY-MM-DD HH:MM\n"
+ " Example: " + ACTION
+ " meet with the CS2113 team /at 2020-10-12 16:00";

public AddEvent(String description, LocalDateTime atTime) {
task = new Event(description, getTargetIndex(), atTime);
}

@Override
public ActionResult executeAction() {
taskList.addTask(task);
return new ActionResult(String.format(MESSAGE, task, taskList.getNumTasks()));
}

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

import duke.task.Task;
import duke.task.ToDo;

/**
* Adds a Todo task to the TaskManager.
*/
public class AddTodo extends AddAction {
public static final String ACTION = "todo";
public static final String HELP_MESSAGE = ACTION + ": Adds a Todo to the task list of DUKE.\n"
+ " Parameters: DESCRIPTION\n"
+ " Example: " + ACTION
+ " return books to the Library";
public static Task task;

public AddTodo(String description) {
task = new ToDo(description, getTargetIndex());
}

@Override
public ActionResult executeAction() {
taskList.addTask(task);
return new ActionResult(String.format(MESSAGE, task, taskList.getNumTasks()));

}
}
Loading