Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6f0a7b6
Add a list and display the list
Wang-Jingwei Feb 13, 2022
557cb7f
Add a task class with description and isDone
Wang-Jingwei Feb 15, 2022
e6b45a1
Add a method to return task string.
Wang-Jingwei Feb 15, 2022
c4c9b4c
Add the ability to mark tasks as done and change the status back to n…
Wang-Jingwei Feb 15, 2022
f44a3e6
Add a deadline class.
Wang-Jingwei Feb 15, 2022
748b623
Revert "Add a deadline class."
Wang-Jingwei Feb 15, 2022
db0a7b1
Add three types of tasks-Deadline, Event and ToDo.
Wang-Jingwei Feb 15, 2022
6bd1236
Add quite a number of error handling.
Wang-Jingwei Feb 15, 2022
4c7f5d0
Add some error handlings.
Wang-Jingwei Feb 15, 2022
4d255af
Merge branch “branch-Level-5”.
Wang-Jingwei Feb 15, 2022
dd00d3d
Merge branch 'branch-Level-5'
Wang-Jingwei Feb 15, 2022
dc33bec
Revert "Merge branch “branch-Level-5”."
Wang-Jingwei Feb 15, 2022
e07aeec
Organise the classes into suitable java packages.
Wang-Jingwei Feb 15, 2022
61d7737
Organise several classes into packages.
Wang-Jingwei Feb 15, 2022
fedb164
Add the delete functionality.
Wang-Jingwei Feb 16, 2022
9fc8cb9
Add the functionality to load data from the file and save data into t…
Wang-Jingwei Feb 16, 2022
8fa79d6
Merge branch 'branch-Level-6'
Wang-Jingwei Feb 16, 2022
6fb28df
Merge branch 'branch-Level-7'
Wang-Jingwei Feb 16, 2022
cf92441
Add manifest.
Wang-Jingwei Feb 16, 2022
c2999c8
Push the design more towards the OOP approach.
Wang-Jingwei Feb 27, 2022
4bbced0
Add the find functionality.
Wang-Jingwei Feb 27, 2022
f28f851
Add javaDoc.
Wang-Jingwei Feb 27, 2022
c435249
Merge pull request #1 from Wang-Jingwei/branch-Level-9
Wang-Jingwei Feb 27, 2022
2fa433e
Merge branch 'master' of https://github.com/Wang-Jingwei/ip
Wang-Jingwei Feb 27, 2022
aab11b7
Merge branch 'master' into branch-A-JavaDoc
Wang-Jingwei Feb 27, 2022
6842078
Merge pull request #2 from Wang-Jingwei/branch-A-JavaDoc
Wang-Jingwei Feb 27, 2022
ac9ed1e
Merge branch 'master' of https://github.com/Wang-Jingwei/ip
Wang-Jingwei Feb 27, 2022
9c5aaa1
Update README.md
Wang-Jingwei Feb 27, 2022
34ce3a2
A change in "data.txt".
Wang-Jingwei Feb 27, 2022
06b8da6
Set theme jekyll-theme-minimal
Wang-Jingwei Feb 27, 2022
2d48dd9
Update README.md
Wang-Jingwei Feb 27, 2022
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
5 changes: 5 additions & 0 deletions data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
T,false,eat food
D,true,return book , Sunday
T,true,borrow book
E,false,haha , Monday
D,false,120 songs , Tomorrow
107 changes: 94 additions & 13 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,110 @@
# User Guide
# User Guide for Duke
**Duke** is a Personal Assistant Chatbot that helps a person to keep track of various tasks via a **Command Line Interface**.

## Features
1. Add a ToDo task
2. Add a Deadline task
3. Add an event task
4. delete a specific task
5. Mark a task as done
6. Mark a task as undone
7. Display the current task list
8. find the tasks with given keyword
9. Load and save the data automatically
10. Exit the program

### Feature-ABC
## Usage

Description of the feature.
### Add a task: `taskType description (time)`

### Feature-XYZ
**Format**:

- TODO: `TODO description`. **Example**: `TODO borrow book`

Description of the feature.
- DEADLINE: `DEADLINE description /by deadlineTime`. **Example**: `DEADLINE return book /by Sunday`

- EVENT: `EVENT description /at eventTime`. **Example**: `EVENT project meeting /at Mon 2-4pm`

**Expected outcome (Deadline as an example)**:

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

## Usage
### Delete a task: `delete`

Delete certain task based on its index.

**Format**: `delete taskIndex`

**Expected outcome**:
```
Noted. I've removed this task:
[D][ ] return book (by: Sunday)
Now you have 5 tasks in the list.
```

### Mark a task as done/undone: `mark/unmark`

Mark a task as done/undone based on given index. The default status of a task is **undone**.

**Format**:

- mark: `mark taskIndex`. **Example**: `mark 2`

- unmark: `unmark taskIndex`. **Example**: `unmark 2`

**Expected outcome (mark as example)**:
```
Nice! I've marked this task as done:
3. [T][X] borrow book
```

### Display the current task list: `list`

### `Keyword` - Describe action
**Format**: `list`

Describe the action and its outcome.
**Expected outcome**:
```
Here are the tasks in your list:
1. [T][ ] eat food
2. [D][X] return book (by: Sunday)
3. [T][X] borrow book
4. [E][ ] study CS2113 (at: Monday)
```

Example of usage:
### Find the tasks with given keyword: `find`

`keyword (optional arguments)`
**Format**: `find keyword`

**Example**: `find book`

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

Expected outcome:
### Exit the program: `bye`

Description of the outcome.
**Format**: `bye`

**Expected outcome**:
```
expected output
Bye.Have a nice day!
```

## FAQ
Q: How do I know if the data are successfully loaded/saved from/into the file?

A: Duke will display corresponding message and show error message in case the loading/saving process is unsuccessful.

Q: What if my input format is wrong?

A: Duke will give hint message and allow users to type in again.



1 change: 1 addition & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-minimal
139 changes: 132 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,135 @@
import Tasks.*;
import java.io.IOException;
import java.util.Scanner;
import java.util.ArrayList;

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
private Storage storage;
private ArrayList<Task> todolist = new ArrayList<Task>();
private Ui ui;

/**
* Initialize the Duke.
* @param filePath
*/
public Duke(String filePath){
ui = new Ui();
storage = new Storage(filePath);
Storage.create(filePath);
try {
todolist = new ArrayList<Task>(storage.load());
} catch (IOException e) {
ui.showLoadingError();
todolist = new ArrayList<Task>();
}
}

public void run() throws IOException {
String task;
ui.greetings();
Scanner in = new Scanner(System.in);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe you should consider a more descriptive name for the Scanner object like "scanner"?

task=in.nextLine();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please make sure the spaces between operators are consistent.

while(true){
if(task.equalsIgnoreCase("bye"))
break;
String[] words = task.split(" ",2);
switch (words[0].toLowerCase()){
case "list":{
ui.displayTasks(todolist);
break;
}
case "mark":{
if (words.length==1)
ui.incompleteMessage("mark");
else{
try{
int index = Integer.parseInt(words[1]);
if(index>todolist.size()||index<=0) System.out.println("No task found.");
else ui.markAndDisplayTask(todolist,index);
}
catch (NumberFormatException ex){
ui.showNumberError();
}
}
break;
}
case "unmark":{
if (words.length==1)
ui.incompleteMessage("unmark");
else{
try{
int index = Integer.parseInt(words[1]);
if(index>todolist.size()||index<=0) System.out.println("No task found.");
else ui.unmarkAndDisplayTask(todolist,index);
}
catch (NumberFormatException ex){
ui.showNumberError();
}
}
break;
}
case "todo": {
if (words.length == 1) ui.incompleteMessage("todo");
else ui.addToDo(todolist,words[1]);
break;
}
case "deadline": {
if (words.length==1)
ui.incompleteMessage("deadline");
else{
try{
ui.addDeadline(todolist,words[1]);
}
catch(ArrayIndexOutOfBoundsException e){
ui.showFormattingError("deadline");
}
}
break;
}
case "event": {
if (words.length==1)
ui.incompleteMessage("event");
else{
try{
ui.addEvent(todolist,words[1]);
}
catch(ArrayIndexOutOfBoundsException e){
ui.showFormattingError("event");
}
}
break;
}
case "delete":{
if (words.length==1)
ui.incompleteMessage("delete");
else{
try{
int index = Integer.parseInt(words[1]);
if(index>todolist.size()||index<=0) System.out.println("No task found.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe you should consider having the if block in two lines.

else ui.deleteTask(todolist,index);
}
catch (NumberFormatException ex){
ui.showNumberError();
}
}
break;
}
case "find": {
if (words.length == 1) ui.incompleteMessage("find");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe you could place the if and else blocks in more than a line.

else ui.displayFoundTasks(todolist, words[1]);
break;
}
default:
ui.displayDefaultMessage();
}
task=in.nextLine();
}
Storage.save(Storage.format(todolist),"data.txt");
ui.goodBye();
}

public static void main(String[] args) throws IOException {
new Duke("data.txt").run();
}
}

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

104 changes: 104 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import Tasks.*;
import java.io.*;
import java.util.*;

/**
* Include all the file operations such as loading tasks from the file and saving tasks in the file.
*/
public class Storage {
protected String filePath;
public Storage(String filePath) {
this.filePath = filePath;
}

/**
* Find the file according to the given filepath. If the file has not been created, create the file/
* @param filePath
*/
public static void create(String filePath){
try {
File data = new File(filePath);
if (data.createNewFile()) {
System.out.println("No data file detected, I have created a new data file for you!");
} else {
System.out.println("I have found the file and loading the data for you!");
}
} catch (IOException e) {
System.out.println("An error occurred during file searching.");
}
}

/**
* Save the information into the file.
* @param textToAdd Texts going to be saved in the file.
* @param filePath
* @throws IOException
*/

public static void save(String textToAdd,String filePath) throws IOException {
FileWriter fw = new FileWriter(filePath,false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe you should consider a more descriptive name for the object like fileWriter.

try {
fw.write(textToAdd+System.lineSeparator());
} catch (IOException e) {
System.out.println("Something went wrong, the data is not successfully saved in the file.");
}
fw.close();
}

/**
* Add the information in the given file into an arraylist.
* @return Arraylist loaded from the file.
* @throws IOException
*/
public ArrayList<Task> load() throws IOException {
ArrayList<Task> todolist = new ArrayList<Task>();
BufferedReader br = new BufferedReader(new FileReader(this.filePath));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Name like "bufferedReader" would be better in this case.

String taskLine;
while ((taskLine = br.readLine())!=null) {
String[] t = taskLine.split(",");
switch (t[0]) {
case "T":
ToDo todo = new ToDo(t[2]);
todolist.add(todo);
break;
case "D":
Deadline deadline = new Deadline(t[2], t[3]);
todolist.add(deadline);
break;
case "E":
Event event = new Event(t[2], t[3]);
todolist.add(event);
break;
}
if (t.length>1&&t[1].equals("true"))
todolist.get(todolist.size() - 1).markAsDone();
}
br.close();
System.out.println("I have successfully loaded the file for you!");
return todolist;
}

/**
* format the information in the arraylist into a string.
* @param taskList Arraylist going to be formatted.
* @return String formatted from the tasklist.
*/

public static String format(ArrayList<Task> taskList){
String taskAllInfo="";
for(Task k: taskList){
String taskInfo = k.getType()+","+k.getStatus()+","+k.getDescription();
if(k.getType()=="D") {
Deadline d = (Deadline) k;
taskInfo = taskInfo + "," + d.getBy();
}
else if(k.getType()=="E"){
Event e = (Event) k;
taskInfo = taskInfo + "," + e.getAt();
}
taskAllInfo+=taskInfo+"\n";
}
if (taskAllInfo!=null) taskAllInfo=taskAllInfo.substring(0, taskAllInfo.length() - 1);
return taskAllInfo;
}
}
Loading