Skip to content

Commit

Permalink
Fix errors in Storage
Browse files Browse the repository at this point in the history
Commands unable to run properly when app is opened for the first
time.

Let's fix null pointer error in the Storage class.
  • Loading branch information
kkangs0226 committed Sep 18, 2020
1 parent f06286f commit 1e0756c
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 41 deletions.
53 changes: 40 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Below are instructions on how to use _KING BOB_.

### `todo` - Add a new Todo task
This command adds a new Todo task to the user's list of tasks.
Duplicate tasks will not be added to the list.

Format:
`todo TODO_DESCRIPTION`
Expand All @@ -32,12 +33,21 @@ Example of command:
Expected result:
```
Banana! Banana has been added to your list!
[T][✘] read book
Now you have 1 banana(s) in your list! Nom nom..
[T][✘] read book
Now you have 1 banana(s) in your list! Nom nom..
```

Example of command:
- `todo read book`

Expected result:
```
Banana! There is a duplicate in the list!
```

### `event` - Add a new Event task
This command adds a new Event task to the user's list of tasks.
Duplicate tasks will not be added to the list.

Format:
`event EVENT_DESCRIPTION /at EVENT_DATE`
Expand All @@ -48,13 +58,21 @@ Example of command:
Expected result:
```
Banana! Banana has been added to your list!
[E][✘] graduation night (at: Feb 19 2020)
Now you have 2 banana(s) in your list! Nom nom..
[E][✘] graduation night (at: Feb 19 2020)
Now you have 2 banana(s) in your list! Nom nom..
```

Example of command:
- `event graduation night /at 2020-02-19`

Expected result:
```
Banana! There is a duplicate in the list!
```

### `deadline` - Add a new Deadline task
This command adds a new Deadline task to the user's list of tasks.

Duplicate tasks will not be added to the list.

Format:
`deadline PROJECT_DESCRIPTION /by DEADLINE_DATE`
Expand All @@ -65,8 +83,16 @@ Example of command:
Expected result:
```
Banana! Banana has been added to your list!
[D][✘] project (by: Sep 30 2020)
Now you have 3 banana(s) in your list! Nom nom..
[D][✘] project (by: Sep 30 2020)
Now you have 3 banana(s) in your list! Nom nom..
```

Example of command:
- `deadline project /by 2020-09-30`

Expected result:
```
Banana! There is a duplicate in the list!
```

### `list` - Display list of tasks
Expand All @@ -78,6 +104,7 @@ Format:
Expected result:
```
Banana! So many tasks?
1. [T][✘] read book
2. [E][✘] graduation night (at: Feb 19 2020)
3. [D][✘] project (by: Sep 30 2020)
Expand All @@ -95,7 +122,7 @@ Example of command:
Expected result:
```
Banana! I’ve marked this task as done:
[T][✓] read book
[T][✓] read book
```

### `delete` - Delete a task
Expand All @@ -110,8 +137,8 @@ Example of command:
Expected result:
```
Banana! banana has been eaten. Burp!
[T][✓] read book
Now you have 2 banana(s) in your list! Nom nom..
[T][✓] read book
Now you have 2 banana(s) in your list! Nom nom..
```

### `date` - Find a task by its date
Expand All @@ -126,7 +153,7 @@ Example of command:
Expected result:
```
Banana! Here are your bananas..
[D][✘] project (by: Sep 30 2020)
[D][✘] project (by: Sep 30 2020)
```

### `find` - Find a task by its keyword
Expand All @@ -141,7 +168,7 @@ Example of command:
Expected result:
```
Banana! Here are your bananas..
[D][✘] project (by: Sep 30 2020)
[D][✘] project (by: Sep 30 2020)
```

Example of command:
Expand All @@ -150,7 +177,7 @@ Example of command:
Expected result:
```
Banana! Here are your bananas..
[E][✘] graduation night (at: Feb 19 2020)
[E][✘] graduation night (at: Feb 19 2020)
```

### `bye` - Exits application
Expand Down
3 changes: 0 additions & 3 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
E | 0 | graduation night | 2020-02-19
D | 0 | project | 2020-09-30
E | 0 | dskj | 2020-09-30
T | 0 | read book
57 changes: 42 additions & 15 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tasks (bananas)!

![Image of KING BOB](https://raw.githubusercontent.com/kkangs0226/ip/master/docs/Ui.png)

Below are instructions on how to use _KING BOB_.
#####Below are instructions on how to use _KING BOB_.

- Features
- todo
Expand All @@ -22,6 +22,7 @@ Below are instructions on how to use _KING BOB_.

### `todo` - Add a new Todo task
This command adds a new Todo task to the user's list of tasks.
Duplicate tasks will not be added to the list.

Format:
`todo TODO_DESCRIPTION`
Expand All @@ -32,12 +33,21 @@ Example of command:
Expected result:
```
Banana! Banana has been added to your list!
[T][✘] read book
Now you have 1 banana(s) in your list! Nom nom..
[T][✘] read book
Now you have 1 banana(s) in your list! Nom nom..
```

Example of command:
- `todo read book`

Expected result:
```
Banana! There is a duplicate in the list!
```

### `event` - Add a new Event task
This command adds a new Event task to the user's list of tasks.
Duplicate tasks will not be added to the list.

Format:
`event EVENT_DESCRIPTION /at EVENT_DATE`
Expand All @@ -48,13 +58,21 @@ Example of command:
Expected result:
```
Banana! Banana has been added to your list!
[E][✘] graduation night (at: Feb 19 2020)
Now you have 2 banana(s) in your list! Nom nom..
[E][✘] graduation night (at: Feb 19 2020)
Now you have 2 banana(s) in your list! Nom nom..
```

Example of command:
- `event graduation night /at 2020-02-19`

Expected result:
```
Banana! There is a duplicate in the list!
```

### `deadline` - Add a new Deadline task
This command adds a new Deadline task to the user's list of tasks.

Duplicate tasks will not be added to the list.

Format:
`deadline PROJECT_DESCRIPTION /by DEADLINE_DATE`
Expand All @@ -65,8 +83,16 @@ Example of command:
Expected result:
```
Banana! Banana has been added to your list!
[D][✘] project (by: Sep 30 2020)
Now you have 3 banana(s) in your list! Nom nom..
[D][✘] project (by: Sep 30 2020)
Now you have 3 banana(s) in your list! Nom nom..
```

Example of command:
- `deadline project /by 2020-09-30`

Expected result:
```
Banana! There is a duplicate in the list!
```

### `list` - Display list of tasks
Expand All @@ -78,6 +104,7 @@ Format:
Expected result:
```
Banana! So many tasks?
1. [T][✘] read book
2. [E][✘] graduation night (at: Feb 19 2020)
3. [D][✘] project (by: Sep 30 2020)
Expand All @@ -95,7 +122,7 @@ Example of command:
Expected result:
```
Banana! I’ve marked this task as done:
[T][✓] read book
[T][✓] read book
```

### `delete` - Delete a task
Expand All @@ -110,8 +137,8 @@ Example of command:
Expected result:
```
Banana! banana has been eaten. Burp!
[T][✓] read book
Now you have 2 banana(s) in your list! Nom nom..
[T][✓] read book
Now you have 2 banana(s) in your list! Nom nom..
```

### `date` - Find a task by its date
Expand All @@ -126,7 +153,7 @@ Example of command:
Expected result:
```
Banana! Here are your bananas..
[D][✘] project (by: Sep 30 2020)
[D][✘] project (by: Sep 30 2020)
```

### `find` - Find a task by its keyword
Expand All @@ -141,7 +168,7 @@ Example of command:
Expected result:
```
Banana! Here are your bananas..
[D][✘] project (by: Sep 30 2020)
[D][✘] project (by: Sep 30 2020)
```

Example of command:
Expand All @@ -150,7 +177,7 @@ Example of command:
Expected result:
```
Banana! Here are your bananas..
[E][✘] graduation night (at: Feb 19 2020)
[E][✘] graduation night (at: Feb 19 2020)
```

### `bye` - Exits application
Expand All @@ -168,4 +195,4 @@ The app quits.
* Images retrieved from:
* [Background](https://www.pinterest.co.kr/pin/661114420275950559/)
* [User icon](https://www.pinterest.com/pin/484559241150248458/)
* [KING BOB icon](https://despicableme.fandom.com/wiki/Bob)
* [KING BOB icon](https://despicableme.fandom.com/wiki/Bob)
Binary file modified docs/Ui.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public List<Task> load() throws DukeException {
directory.mkdir();
try {
dataFile.createNewFile();
return null;
return tasks;
} catch (IOException e) {
throw new DukeException("File cannot be created");
}
} else if (!fileExists) {
try {
dataFile.createNewFile();
return null;
return tasks;
} catch (IOException e) {
throw new DukeException("File cannot be created");
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private void resetMessage() {
*/
public void setShowListMessage(List<Task> tasks) {
resetMessage();
responseMessage.append("Banana! So many tasks?\n");
responseMessage.append("Banana! So many tasks?\n\n");
Task task;
for (int i = 0; i < tasks.size(); i++) {
task = tasks.get(i);
Expand All @@ -49,8 +49,8 @@ public void setByeMessage() {
public void setAddedMessage(Task task, int tasksNumber) {
resetMessage();
responseMessage.append("Banana! Banana has been added to your list!\n"
+ " " + task.toString() + "\n"
+ " Now you have " + tasksNumber + " banana(s) in your list! Nom nom..");
+ " " + task.toString() + "\n"
+ "Now you have " + tasksNumber + " banana(s) in your list! Nom nom..");
}

/**
Expand All @@ -69,8 +69,8 @@ public void setDuplicateMessage() {
public void setDeletedMessage(Task task, int tasksNumber) {
resetMessage();
responseMessage.append("Banana! Banana has been eaten. Burp!\n"
+ " " + task.toString() + "\n"
+ " Now you have " + (tasksNumber - 1) + " banana(s) in your list! Nom nom..");
+ " " + task.toString() + "\n"
+ "Now you have " + (tasksNumber - 1) + " banana(s) in your list! Nom nom..");
}

/**
Expand All @@ -80,7 +80,7 @@ public void setDeletedMessage(Task task, int tasksNumber) {
public void setDoneMessage(Task task) {
resetMessage();
responseMessage.append("Banana! I've marked this task as done:\n"
+ " " + task.toString());
+ " " + task.toString());
}

/**
Expand All @@ -101,7 +101,7 @@ public void setFindTaskByDateMessage(LocalDate date, List<Task> tasks) {
responseMessage.append("Banana! Here are your bananas..\n");
for (Task t : tasks) {
if (t.getDate().equals(date)) {
responseMessage.append(t.toString() + "\n");
responseMessage.append(" " + t.toString() + "\n");
}
}
}
Expand All @@ -116,7 +116,7 @@ public void setFindTaskByKeywordMessage(String keyword, List<Task> tasks) {
responseMessage.append("Banana! Here are your bananas..\n");
for (Task t : tasks) {
if (t.toString().contains(keyword)) {
responseMessage.append(t.toString() + "\n");
responseMessage.append(" " + t.toString() + "\n");
}
}
}
Expand Down

0 comments on commit 1e0756c

Please sign in to comment.