Skip to content
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Duke project template
# chatbot.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.

Expand All @@ -13,7 +13,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version.
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:
3. After that, locate the `src/main/java/chatbot.Duke.java` file, right-click it, and choose `Run chatbot.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
____ _
Expand Down
3 changes: 3 additions & 0 deletions data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
true| concert | aer | thurs
false| Homework | Friday
false|event concert |now| thwn
107 changes: 98 additions & 9 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,117 @@

## Features

### Feature-ABC
### Feature: Add Todo, Deadline or Event

Description of the feature.
Use app to record todos, deadlines and events with a custom user description for each added entry. Deadlines support due dates and events support start and end dates. Todos, deadlines and events can be removed as well.

### Feature-XYZ
Can also search for tasks with keywords from their task description.

### Feature: Mark/unmark

Use app to mark/unmark todos/deadlines/events as done or not done yet.

### Feature: Find

Use app to find todos/deadlines/events by searching the task list for the relavent keyword in their descriptions

### Feature: List

List all todos, deadlines and events.

### Feature: Save

Todos, deadlines and events are saved in between running the program.

Description of the feature.

## Usage

### `Keyword` - Describe action
### `todo`/`deadline`/`event` - Add todo, deadline or event

How to add a Todo:

todo [description]


How to add a Deadline:

deadline [description] /by [due date]


How to add an Event:

event [description] /from [start date] /to [end date]

Describe the action and its outcome.

Example of usage:

`keyword (optional arguments)`
`deadline Homework /by Friday`

Expected outcome:

Adds a new deadline with description "go to school" with due date of "Friday"

```
Created new Deadline:
Homework (by: Friday)
```

### `mark`/`unmark` - Mark/unmark todo, deadline or event

Mark/unmark a todo/event/deadline as done or not done yet using the mark/unmark keyword:

mark [item position in list]

unmark [item position in list]


Example of usage:

`mark 1`

Expected outcome:

Marks todo/deadline/event in position 1 of list as done

```
Marked as done:
Homework
```

### `list` - Lists all todos, deadlines and events

Example of usage:

`list`

Expected outcome:

Description of the outcome.
```
[D][X] Homework (by: Friday)
```

### `find` - Lists all todos, deadlines and events that contain search term in the description

find [search term]

Example of usage:

`find Homework`

Expected outcome:

```
[D][X] Homework (by: Friday)
```

### `bye` - Exits program

Example of usage:

`bye`

Expected outcome:

```
expected output
Bye. Hope to see you again soon!
```
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: chatbot.Duke

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

import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

import exception.FattyException;
import tasks.Task;

/**
* This is the chatbot class. This contains an array of Task objects and contains functions to handle them.
*/

public class Duke {
public static ArrayList<Task> taskList;
private static Storage storage;
private static Ui ui;
private static Parser parser;

public Duke() {
taskList = new ArrayList<>();
ui = new Ui();
parser = new Parser();
storage = new Storage();
}

/**
* Main function creates new Duke object and calls run method
* @param args
* @throws FattyException
*/
public static void main(String[] args) throws FattyException, IOException {
new Duke().run();
}

/**
* Run function executes the main while loop of the program
* @throws FattyException
*/
public static void run() throws FattyException, IOException {

try {
storage.load();
} catch (IOException e) {
System.out.println(e.toString());
}

ui.printWelcomeMessage();

Scanner scanner = new Scanner(System.in);

while(true) {
String inputMessage = scanner.nextLine();

if (inputMessage.equals("bye")) {
ui.printGoodbyeMessage();
break;
}

try {
String keyword = parser.getKeyword(inputMessage);

switch (keyword) {
case "list":
list();
break;
case "mark":
mark(parser.getIndex(inputMessage));
break;
case "unmark":
unmark(parser.getIndex(inputMessage));
break;
case "delete":
delete(parser.getIndex(inputMessage));
break;
case "find":
find(parser.getSearchField(inputMessage));
break;
case "create":
Task newTask = parser.getTask(inputMessage);
taskList.add(parser.getTask(inputMessage));
ui.printNewTaskMessage();
newTask.show();
ui.printDivider();
break;
}

storage.save();

} catch (FattyException e) {
ui.printDivider();
System.out.println(e.toString());
ui.printDivider();
continue;
}
}
}

private static void add(Task task) {
taskList.add(task);
}

private static void delete(int index) throws FattyException {
if(index <= 0 || index > taskList.size()) {
throw new FattyException ("Please enter a valid index");
}

ui.printDeleteMessage();
taskList.get(index - 1).show();
ui.printDivider();

taskList.remove(index - 1);
}

private static void list() {
ui.printListMessage();

for(int i = 0; i < taskList.size(); i++) {
taskList.get(i).show();
}

ui.printDivider();
}

private static void mark(int index) throws FattyException {
if(index <= 0 || index > taskList.size()) {
throw new FattyException ("Please enter a valid index");
}

taskList.get(index - 1).mark();
}

private static void unmark(int index) throws FattyException {
if(index <= 0 || index > taskList.size()) {
throw new FattyException ("Please enter a valid index");
}

taskList.get(index - 1).unmark();
}

private static void find(String keyword) {
boolean found = false;

for(int i = 0; i < taskList.size(); i++) {
if(taskList.get(i).getDescription().contains(keyword)) {
taskList.get(i).show();
found = true;
}
}

if(found) {
ui.printFoundMessage();
} else {
ui.printNotFoundMessage();
}
}
}
Loading