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

## Features

### Feature-ABC
### Feature-Adding tasks

Description of the feature.
Duke can store your tasks to complete.

### Feature-XYZ
### Feature-Different types of tasks

Description of the feature.
Duke allows three different types of tasks: todo, deadline and event.

### Feature-Mark a task as done/ undone

Duke can change the completion status of a task.

### Feature-Viewing tasks

All the tasks and the corresponding type and completion status can be seen.

### Feature-Viewing tasks

Tasks can be deleted.

### Feature-Storing information

Duke can store your tasks locally when the programme is exited and loads the stored data whenever the programmed is run.

## Usage

### `Keyword` - Describe action
### command and details

To use Duke, you need to tell it the command keyword and the details of the command.

The format can be seen in the example below with the corresponding output.

#### **Adding a task**

Input the type of the task (todo, deadline, event) and follow the format given below:

```
todo study

deadline submit assignments /by fri

event lecture /from 4pm fri /to 6pm fri
```

**_Note: the "/" for deadline and event is very important for Duke to recognise the time/ duration!_**

#### **Listing all the tasks**

Simply enter list to see your tasks:

```
list
______________________________
1. [T][ ]study
2. [D][ ]submit assignments (by: fri)
3. [E][ ]lecture (from: 4pm fri to: 6pm fri)
______________________________
```

#### **Marking a task as done/ undone**

Describe the action and its outcome.
```
mark 1
```
```
______________________________
Nice! I've marked this task as done:
[T][X]study
______________________________
```
```
mark 2
```
```
______________________________
Nice! I've marked this task as done:
[D][X]submit assignments (by: fri)
______________________________
```

```
list
______________________________
1. [T][X]study
2. [D][X]submit assignments (by: fri)
3. [E][ ]lecture (from: 4pm fri to: 6pm fri)
______________________________
```

Example of usage:
#### **Finding a task**

`keyword (optional arguments)`
```
find study
______________________________
Here are the matching tasks in your list:
[T][X]study
______________________________
```
```
find submit
______________________________
Here are the matching tasks in your list:
[D][X]submit assignments (by: fri)
______________________________
```

Expected outcome:
#### **Deleting a task**

Description of the outcome.
```
list
______________________________
1. [T][X]study
2. [D][X]submit assignments (by: fri)
3. [E][ ]lecture (from: 4pm fri to: 6pm fri)
______________________________
```
```
delete 2
______________________________
deleted:
[D][X]submit assignments (by: fri)
______________________________

Now you have 2 tasks in the list
```
```
expected output
list
______________________________
1. [T][X]study
2. [E][ ]lecture (from: 4pm fri to: 6pm fri)
______________________________
```


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

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

/**
* A subclass Deadline of Task
* Represents a Deadline added by the user and contains the deadline info "by"
*/
public class Deadline extends Task{
protected String by;

/**
* Constructor to construct a Deadline
* @param description the details of the task
* @param by the time of the deadline
*/
public Deadline(String description, String by) {
super(description);
this.by = by;
}

/**
* gets the type of the task which is deadline
* @return a string representing the type ([D])
*/
@Override
public String getTypeIcon() {
return "[D]";
}

/**
* Returns all the information about the task
*
* @return a String with all the information about the task
*/
@Override
public String toString(){
return getTypeIcon() + super.getStatusIcon() +super.description + " (by: " + this.by + ")";
}
}
37 changes: 37 additions & 0 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package duke;


import java.util.Scanner;
import java.util.ArrayList;

public class Duke {

public static boolean shouldContinue = true;
public static int taskCount = 0;

public static void main(String[] args) {
Ui.greetUser();
ArrayList<Task> tasks = new ArrayList<>();
TaskData file = new TaskData("./duke.txt");
tasks = file.loadData(tasks, file);
taskCount = tasks.size();
Scanner in = new Scanner(System.in);
String action;
while (shouldContinue) {
action = in.nextLine();
try {
tasks = Parser.handleAction(tasks, action, file);
} catch (DukeException e) {
Ui.printWrongCommand();
} catch (DukeException.TaskEmpty e) {
Ui.printEmptyContent();
} catch (StringIndexOutOfBoundsException e) {
Ui.printWrongFormat();
} catch (NumberFormatException e) {
Ui.printWrongNumber();
} catch (IndexOutOfBoundsException e) {
Ui.printWrongNumber();
}
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package duke;

/**
* DukeException is for command word not recognised by Duke
* TaskEmpty is when the content of the command word recognised is empty
*/
public class DukeException extends Exception{
public static class TaskEmpty extends Exception{}

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

/**
* A subclass Event of Task
* Represents an event for the user containing info for the time period of the event
*/
public class Event extends Task{
protected String from;
protected String to;

/**
* Constructor to construct an event
* @param description details of the event
* @param from starting time
* @param to ending time
*/
public Event(String description, String from, String to){
super(description);
this.from = from;
this.to = to;
}

/**
* gets the type of the task which is deadline
* @return a string representing the type ([E])
*/
@Override
public String getTypeIcon() {
return "[E]";
}

/**
* Returns all the information about the task
*
* @return a String with all the information about the task
*/
@Override
public String toString(){
return getTypeIcon() + super.getStatusIcon() + super.description
+ " (from: " + this.from + " to: " + this.to + ")";
}
}
104 changes: 104 additions & 0 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package duke;

import java.util.ArrayList;

/**
* Deals with making sense of user command
*/
public class Parser {
protected static int TODO_OFFSET = 5;
protected static int DEADLINE_OFFSET = 9;
protected static int BY_OFFSET = 4;
protected static int EVENT_OFFSET = 6;
protected static int FROM_OFFSET = 6;
protected static int TO_OFFSET = 4;
protected static int FIND_OFFSET = 5;

/**
* Handles command(action) input by the user
* Returns updated tasks
*
* @param tasks all the tasks added
* @param action the input line by the user
* @param file the txt file storing the tasks
* @return tasks
* @throws DukeException when the command word is not recognised
* @throws DukeException.TaskEmpty when the content of task to be added is empty
*/
public static ArrayList<Task> handleAction(ArrayList<Task> tasks, String action, TaskData file
) throws DukeException, DukeException.TaskEmpty{
if (action.equals("bye")) {
Ui.exitProgram();
Duke.shouldContinue = false;

} else if (action.equals("list")) {
Ui.listTasks(tasks, Duke.taskCount);

} else if (action.equals("todo") || action.equals("deadline") || action.equals("event")) {
throw new DukeException.TaskEmpty();

} else if (action.startsWith("mark")){
int dividerPos = action.indexOf(" ");
int toBeMarked = Integer.parseInt(action.substring(dividerPos + 1)) - 1;
tasks.get(toBeMarked).markAsDone();
Ui.printMarked(tasks.get(toBeMarked), action.split(" ")[0]);
file.updateFile(tasks, file);

} else if (action.startsWith("unmark")) {
int dividerPos = action.indexOf(" ");
int toBeUnmarked = Integer.parseInt(action.substring(dividerPos + 1)) - 1;
tasks.get(toBeUnmarked).markAsUndone();
Ui.printMarked(tasks.get(toBeUnmarked), action.split(" ")[0]);
file.updateFile(tasks, file);

} else if (action.startsWith("delete")) {
int dividerPos = action.indexOf(" ");
int toBeDeleted = Integer.parseInt(action.substring(dividerPos + 1)) - 1;
Task removedTask = tasks.get(toBeDeleted);
tasks.remove(toBeDeleted);
Duke.taskCount -= 1;
Ui.printDeleted(removedTask);
Ui.printNumTask(Duke.taskCount);
file.updateFile(tasks, file);

} else if (action.startsWith("todo")){
Task tempTask = new Task(action.substring(TODO_OFFSET));
tasks.add(tempTask);
Ui.printAdded(tasks, Duke.taskCount);
Duke.taskCount += 1;
Ui.printNumTask(Duke.taskCount);
tasks = file.addTaskToFile(tasks, tempTask, file);

} else if (action.startsWith("deadline")) {
int dividerPosition = action.indexOf("/by");
Task tempTask = new Deadline(action.substring(DEADLINE_OFFSET,dividerPosition - 1),
action.substring(dividerPosition + BY_OFFSET));
tasks.add(tempTask);
Ui.printAdded(tasks, Duke.taskCount);
Duke.taskCount += 1;
Ui.printNumTask(Duke.taskCount);
tasks = file.addTaskToFile(tasks, tempTask, file);

} else if (action.startsWith("event")) {
int dividerPosition1 = action.indexOf("/from");
int dividerPosition2 = action.indexOf("/to");
//extract the event details
Task tempTask = new Event(action.substring(EVENT_OFFSET,dividerPosition1 - 1),
action.substring(dividerPosition1 + FROM_OFFSET, dividerPosition2 - 1),
action.substring(dividerPosition2 + TO_OFFSET));
tasks.add(tempTask);
Ui.printAdded(tasks, Duke.taskCount);
Duke.taskCount += 1;
Ui.printNumTask(Duke.taskCount);
tasks = file.addTaskToFile(tasks, tempTask, file);

} else if (action.startsWith("find")) {
String taskToFind = action.substring(FIND_OFFSET);
Ui.printFound(tasks, taskToFind);

} else {
throw new DukeException();
}
return tasks;
}
}
Loading