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
160 changes: 153 additions & 7 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,174 @@

## Features

### Feature-ABC
### Feature - Adding of Task - Todo, Event, Deadline

Description of the feature.
You can now add a task of any one of the three types.

### Feature-XYZ

Description of the feature.
### Feature - Deletion of Task

Delete any task according to its index in the list of tasks.

### Feature - Unmark/mark any task.

Mark or unmark any task in the list of task.

### Feature - List all tasks.

List all the current tasks in the list.

### Feature - Find a task, given a specific search word.

Enter a word and search for all tasks that contain this word.

## Usage

### `Keyword` - Describe action
### `todo` - Describe action

Describe the action and its outcome.

Example of usage:

`todo enter description here`

Expected outcome:

Description of the outcome.

```
Got it. I've added this task:
[T][ ]enter description here
Now you have 1 tasks in the list.
```

### `deadline` - Describe action

Describe the action and its outcome.

Example of usage:

`keyword (optional arguments)`
`deadline ip assignment /by today 2359`

Expected outcome:

Description of the outcome.

```
expected output
Got it. I've added this task:
[D][ ]ip assignment (by today 2359)
Now you have 1 tasks in the list.
```

### `event` - Describe action

Describe the action and its outcome.

Example of usage:

`event final exam /at 29 February 9pm`

Expected outcome:

Description of the outcome.

```
Got it. I've added this task:
[E][ ]final exam (at 29 February 9pm)
Now you have 3 tasks in the list.
```


### `find` - Describe action

Describe the action and its outcome.

Example of usage:

`find final`

Expected outcome:

Description of the outcome.

```
Here are the matching tasks in your list:
3.[E][ ]final exam (at 29 February 9pm)
```

### `mark` - Describe action

Describe the action and its outcome.

Example of usage:

`mark 3`

Expected outcome:

Description of the outcome.

```
[T][ ]enter description here
[D][ ]ip assignment (by today 2359)
[E][X]final exam (at 29 February 9pm)
```

### `unmark` - Describe action

Describe the action and its outcome.

Example of usage:

`unmark 3`

Expected outcome:

Description of the outcome.

```
[T][ ]enter description here
[D][ ]ip assignment (by today 2359)
[E][ ]final exam (at 29 February 9pm)
```

### `list` - Describe action

Describe the action and its outcome.

Example of usage:

`list`

Expected outcome:

Description of the outcome.

```
Here are the tasks in your list :
1.[T][ ]enter description here
2.[D][ ]ip assignment (by today 2359)
3.[E][ ]final exam (at 29 February 9pm)
```

### `delete` - Describe action

Describe the action and its outcome.

Example of usage:

`delete 2`

Expected outcome:

Description of the outcome.

```
Noted. I've removed this task:
[D][ ]ip assignment (by today 2359)
Now you have 2 tasks in the list.
[T][ ]enter description here
[E][ ]final exam (at 29 February 9pm)

```

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

Binary file added src/main/java/duke/Duke.class
Binary file not shown.
42 changes: 42 additions & 0 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package duke;
import duke.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.loadTaskList());
} catch (DukeException e) {
ui.showLoadingError("Error in loading text file of tasks!");
tasks = new TaskList();
}
}
public void run() {
ui.showWelcome();
boolean endProgram = false;

while (!endProgram) {
try {
String command = ui.readCommand();
int continueProgram = Parser.parse(command,tasks,storage);
if (continueProgram == 0) {
endProgram = true;
}
} catch (DukeException e) {
e.printStackTrace();
}
}
}

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

}

Binary file added src/main/java/duke/DukeException.class
Binary file not shown.
9 changes: 9 additions & 0 deletions src/main/java/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package duke;
public class DukeException extends Exception{


public DukeException(String message) {
super(message);
}

}
4 changes: 4 additions & 0 deletions src/main/java/duke/File.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

142 changes: 142 additions & 0 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package duke;
import duke.Storage;
import duke.tasklist.*;

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

/**
* Parser helps to make sense of the user input and uses methods from TaskList to do operations on the ArrayList of tasks.
*/
public class Parser {
public static int parse(String userInput, TaskList l,Storage s) throws DukeException {
String desc;
int index;
String by;
switch (userInput.split(" ")[0]) {
case "find":
String keyword = userInput.split(" ")[1];
l.find(keyword);
return 1;


case "todo":
desc = userInput.substring(5);
if (desc.isEmpty() || desc.isBlank()) {
throw new DukeException("Oops! Description cannot be empty.");
}
desc = l.addTodo(desc);
try {
if (l.getTaskSize() == 1) {
s.writeToFile(desc);
}
else {
s.appendData(desc);
}
} catch (IOException e) {
System.out.println("Error while appending to text file.");
}

return 1;


case "event":
index = userInput.indexOf("/");
desc = userInput.substring(6,index);
if (desc.isEmpty() || desc.isBlank()) {
throw new DukeException("Oops! Description cannot be empty.");
}
index++;
by = userInput.substring(index);
if (by.isEmpty() || by.isBlank()) {
throw new DukeException("Oops! You need a date for event.");
}
desc = l.addEvent(desc,by);
try {
if (l.getTaskSize() == 1) {
s.writeToFile(desc);
}
else {
s.appendData(desc);
}

} catch (IOException e) {
System.out.println("Error while appending to text file.");
}
return 1;


case "deadline":
index = userInput.indexOf("/");
desc = userInput.substring(9,index);
if (desc.isEmpty() || desc.isBlank()) {
throw new DukeException("Oops! Description cannot be empty.");
}
index++;
by = userInput.substring(index);
if (by.isEmpty() || by.isBlank()) {
throw new DukeException("Oops! You need a date for deadline.");
}
desc = l.addDeadline(desc,by);
try {
if (l.getTaskSize() == 1) {
s.writeToFile(desc);
}
else {
s.appendData(desc);
}
} catch (IOException e) {
System.out.println("Error while appending to text file.");
}
return 1;



case "mark":
String[] arrOfStr = userInput.split(" ", 0);
String indexValue = arrOfStr[1];
int indexValue2 = Integer.parseInt(indexValue) - 1;
//index given is out of array size
if (indexValue2 > l.getTaskSize()-1 || indexValue2 < 0){
throw new DukeException("Index given is out of bounds.");
}
ArrayList<Task> taskList = l.markTask(indexValue2);
s.updateFile(taskList);
return 1;

case "unmark":
arrOfStr = userInput.split(" ", 0);
indexValue = arrOfStr[1];
indexValue2 = Integer.parseInt(indexValue) - 1;
//index given is out of array size
if (indexValue2 > l.getTaskSize()-1 || indexValue2 < 0){
throw new DukeException("Index given is out of bounds.");
}
taskList = l.unmarkTask(indexValue2);
s.updateFile(taskList);
return 1;

case "delete":
arrOfStr = userInput.split(" ", 0);
indexValue = arrOfStr[1];
indexValue2 = Integer.parseInt(indexValue) - 1;
//index given is out of array size
if (indexValue2 > l.getTaskSize()-1 || indexValue2 < 0){
throw new DukeException("Index given is out of bounds.");
}
taskList = l.deleteTask(indexValue2);
s.updateFile(taskList);
return 1;

case "list":
l.printList();
return 1;

case "bye":
return 0;

default:
throw new DukeException("Oops! I do not recognize this command. Please try again.");
}
}
}
Loading