Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ishitamandal06] iP #71

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[T][ ] read book
203 changes: 191 additions & 12 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,208 @@
# User Guide

Duke is a **Command Line Interface** (CLI) based desktop application which
will help the user plan their tasks. It allows users to add or delete three categories of tasks: todos, deadlines,
and events. They can mark these as done or not done and can also see a list of their tasks at
any particular point in time. Additionally, they can search for all tasks containing a particular keyword.
The application will save the tasks and reload them every time the user restarts the application so it can store the list as a memory.
## Features

### Feature-ABC
### Feature - add a task
Adds a task to the current list of tasks. The task could either be a todo, a deadline, or an event.

Description of the feature.
### Feature - delete a task

### Feature-XYZ
Deletes a task from the current list of tasks.

Description of the feature.
### Feature - list all tasks

## Usage
Lists all tasks present in the current list.

### `Keyword` - Describe action
### Feature - mark a task

Describe the action and its outcome.
Marks a particular task from the list as done

Example of usage:
### Feature - unmark a task

`keyword (optional arguments)`
Marks a particular task from the list as not done

Expected outcome:
### Feature - find tasks

Description of the outcome.
Finds all tasks present in the current list that contain the word entered by the user

## Usage (An example workflow)

## `todo` - Adds a todo to the collection of tasks

#### *General format of command*
todo DESCRIPTION_OF_TASK
#### *Example of usage:*

`todo read book`

#### *Expected outcome:*

'read book' will be added to the task list as a todo and currently be marked as not done

```
____________________________________________________________
Got it. I've added this task:
todo read book
Now you have 1 tasks in the list.
____________________________________________________________
```


## `deadline` - Adds a deadline to the collection of tasks

#### *General format of command*
deadline DESCRIPTION_OF_TASK /by DEADLINE_OF_TASK
#### *Example of usage:*

`deadline return book /by Tuesday`

#### *Expected outcome:*

'return book' will be added to the task list as a dealine and currently be marked as not done. The deadline of the event will be stored as 'Tuesday'

```
____________________________________________________________
Got it. I've added this task:
deadline return book /by Tuesday
Now you have 2 tasks in the list.
____________________________________________________________
```


## `event` - Adds an event to the collection of tasks

#### *General format of command*
event DESCRIPTION_OF_TASK /at TIME_OF_TASK
#### *Example of usage:*

`event go to party /at 6PM`

#### *Expected outcome:*

'go to party' will be added to the task list as an event and currently be marked as not done. The time of the event will be stored as '6PM'

```
____________________________________________________________
Got it. I've added this task:
event go to party /at 6PM
Now you have 3 tasks in the list.
____________________________________________________________
```

## `delete` - Deletes a task from the collection of tasks

#### *General format of command*
delete POSITION_TO_DELETE
#### *Example of usage:*

`delete 2`

#### *Expected outcome:*

Currently, the second task in the list is the deadline to 'return book' so this task will be deleted.

```
expected output
____________________________________________________________
Noted. I've removed this task:
[D][ ] return book (by: Tuesday)
Now you have 2 tasks in the list.
____________________________________________________________
```

## `list` - Lists all tasks in the collection

#### *General format of command*
list
#### *Example of usage:*

`list`

#### *Expected outcome:*

Currently, the collection has 2 tasks: 'todo read book' and 'event go to party /at 6PM' so these two tasks will be listed.

```
____________________________________________________________
[T][ ] read book
[E][ ] go to party (at: 6PM)
____________________________________________________________
```

## `mark` - marks a task in the collection as done

#### *General format of command*
mark POSITION_TO_MARK
#### *Example of usage:*

`mark 2`

#### *Expected outcome:*

The second task is currently 'go to party /at 6PM'. This will be marked as done.

```
____________________________________________________________
Nice! I've marked this task as done:
[E][X] go to party (at: 6PM)
____________________________________________________________
```

## `unmark` - marks a task in the collection as not done

#### *General format of command*
unmark POSITION_TO_UNMARK
#### *Example of usage:*

`unmark 2`

#### *Expected outcome:*

The second task is currently 'go to party /at 6PM'. This will be marked as not done.

```
____________________________________________________________
OK, I've marked this task as not done yet:
[E][ ] go to party (at: 6PM)
____________________________________________________________
```


## `find` - finds all tasks in the collection which contain the word entered by user

#### *General format of command*
find WORD_TO_FIND
#### *Example of usage:*

`find book`

#### *Expected outcome:*

The first task is the only task which contains the word 'book' so that will be displayed.

```
____________________________________________________________
[T][ ] read book
____________________________________________________________
```

## `bye` - closes the application

#### *General format of command*
bye
#### *Example of usage:*

`bye`

#### *Expected outcome:*
The application closes

```
____________________________________________________________
Bye. Hope to see you again soon!
____________________________________________________________
```
Binary file added src/main/ip.jar
Binary file not shown.
20 changes: 20 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Deadline class
* extends the Task class to store a particular type of task (deadline)
* contains a description of the task (String description)
* contains a deadline (String by)
*/
public class Deadline extends Task{
Copy link

Choose a reason for hiding this comment

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

The code does not comply with coding standards, perhaps you can consider adding space between Task and {.


protected String by;

public Deadline(String description, String by) {
super(description);
this.by = by;
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}
114 changes: 107 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,110 @@
/**
* Main Duke class
* runs the main operations of the Application
*/

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


public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
static String inputText = "";
static ArrayList<Task> tasks = new ArrayList<>();
static ArrayList<String> storedTasks = new ArrayList<>();
static int taskCount = 0;
static boolean isRunning = true;

public static void main(String[] args) throws NullCommandException, IOException {
File f = new File("data.txt");
if(f.exists()) {
Scanner s = new Scanner(f);
while(s.hasNext()) {
storedTasks.add(s.nextLine());
}
handleStoredTasks();
}
FileWriter fw = new FileWriter("data.txt");
UI.welcomeMessage();
handleUserInput();
for (Task task : tasks) {
fw.write(task.toString() + "\n");
}
fw.close();
}

public static void handleStoredTasks(){
TaskList.handleStoredTasks(storedTasks,tasks);
}

Choose a reason for hiding this comment

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

unnecessary empty line here

public static void handleListMessage(){
UI.listMessage(tasks);
}

/**
* Adds new task to collection based on command type.
* @param command which specifies whether it is todo, deadline, or an event
*/
public static void addNewTask(String command) {
TaskList.addTask(command, tasks, inputText);
}

/**
* Deletes task from the collection at the position specified by user
* @param position specifies which task number to delete
*/
public static void handleDeleteCommand(int position) {
TaskList.deleteTask(position,tasks);
}

/**
* handles any command from user to mark or unmark a task
* @param position specifies which task in the collection to mark
*/
public static void handleMarkMessage(int position){

if ((inputText.substring(0,4).equals("mark"))){
TaskList.markTask(position, tasks);
}else{
TaskList.unmarkTask(position, tasks);
}
}

/**
* handles a command from user to search for all tasks with a specific word
* @param word specifies which word to search for in collection
*/
public static void handleFindMessage(String word){
TaskList.findTask(tasks,word);
}

/**
* Runs the program, takes input from user and carries out all operations till the user enters bye
* when user enters bye, program is closed
* based on the type of command entered by the user, different functions are called.
*/
public static void handleUserInput() {
while(isRunning){
inputText = UI.getInput();
String command = Parser.parseCommand(inputText);
if(command.equals("bye")) {
isRunning = false;
UI.exitMessage();
} else if (command.equals("list")) {
handleListMessage();
}else if ((command.equals("mark")) || command.equals("unmark") ) {
int position = Parser.getPositionFromInput(inputText);
handleMarkMessage(position);
}else if(command.equals("delete")){
handleDeleteCommand(Parser.getDeletePosition(inputText));
} else if (command.equals("find")) {
String word = Parser.parseFindCommand(inputText);
handleFindMessage(word);
} else{
addNewTask(Parser.getTaskType(inputText));
}
}
}
}
20 changes: 20 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Event class
* extends the Task class to store a particular type of task (event)
* contains a description of the task (String description)
* contains a time when the event will take place (String at)
*/
public class Event extends Task{
protected String at;

public Event(String description, String at) {
super(description);
this.at = at;
}


@Override
public String toString() {
return "[E]" + super.toString() + " (at: " + at + ")";
}
}
2 changes: 2 additions & 0 deletions src/main/java/InvalidCommandException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class InvalidCommandException extends Exception{
}
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

2 changes: 2 additions & 0 deletions src/main/java/NullCommandException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class NullCommandException extends Exception {
}
Loading