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

[waiter-palypoo] ip #193

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
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
7faa1cb
Add HinaBot.java
waiter-palypoo Jan 26, 2023
0e9f153
Refactor greeting message and add handleCommand method to echo user i…
waiter-palypoo Jan 27, 2023
565a8e1
Add code for adding items to a list and printing the list
waiter-palypoo Jan 31, 2023
3d00890
Add Task class, add code to mark and unmark tasks
waiter-palypoo Feb 1, 2023
7e758c3
Add support for todo, deadline and event task types.
waiter-palypoo Feb 1, 2023
e13adce
no message
waiter-palypoo Feb 1, 2023
752a280
Merge commit '7e758c3a91d41d43006c379c502de1ceb83a4e1f' into HEAD
waiter-palypoo Feb 1, 2023
c47e253
Resolved error resulting from RCS mistake
waiter-palypoo Feb 1, 2023
e40dfd0
Add code to handle unknown command, insufficient detail exceptions.
waiter-palypoo Feb 14, 2023
203f936
Merge branch 'branch-Level-5'
waiter-palypoo Feb 14, 2023
367c9fd
Divide classes into packages
waiter-palypoo Feb 14, 2023
65eef30
Add method to delete tasks, fixed coding standard violations, change …
waiter-palypoo Feb 28, 2023
c890a60
Add functionality to save task list to a .txt file.
waiter-palypoo Feb 28, 2023
07e9a22
Merge branch 'branch-Level-6'
waiter-palypoo Feb 28, 2023
1071390
Merge branch 'branch-Level-7'
waiter-palypoo Feb 28, 2023
3b7e16a
Refactor functionality into Parser, Ui, Storage and TaskList classes.
waiter-palypoo Mar 1, 2023
b0dc677
Add date-time format support
waiter-palypoo Mar 2, 2023
2f02a85
Add method to search for items by matching substrings in Task descrip…
waiter-palypoo Mar 2, 2023
0e9aa9a
Merge pull request #1 from waiter-palypoo/branch-Level-8
waiter-palypoo Mar 2, 2023
4af6cef
Merge branch 'master' of https://github.com/waiter-palypoo/ip
waiter-palypoo Mar 2, 2023
da2844c
Merge branch 'master' into branch-Level-9
waiter-palypoo Mar 2, 2023
4c64d87
Merge pull request #2 from waiter-palypoo/branch-Level-9
waiter-palypoo Mar 2, 2023
bf6fe2d
Merge branch 'master' of https://github.com/waiter-palypoo/ip into br…
waiter-palypoo Mar 2, 2023
4e01561
Merge branch 'branch-Level-9'
waiter-palypoo Mar 2, 2023
ecce69f
Optimise imports for Deadline and Event classes
waiter-palypoo Mar 2, 2023
019af43
Add JavaDoc comments for multiple classes and methods. Refactor some …
waiter-palypoo Mar 3, 2023
c915504
Merge pull request #3 from waiter-palypoo/branch-A-JavaDoc
waiter-palypoo Mar 3, 2023
b195b1d
Merge branch 'master' of https://github.com/waiter-palypoo/ip
waiter-palypoo Mar 3, 2023
5a621ec
Updated user guide, changed find method to print the index of matchin…
waiter-palypoo Mar 3, 2023
29dcae7
Fix bugs involving invalid inputs for mark, unmark and delete methods
waiter-palypoo Mar 17, 2023
d207461
Build jar file
waiter-palypoo Mar 17, 2023
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
Empty file added data/savedlist.txt
Empty file.
169 changes: 160 additions & 9 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,180 @@
# User Guide

Welcome to the HinaBot User Guide! HinaBot is a personal assistant program that helps you
maintain a to-do list.

## Features

### Feature-ABC
### Support for multiple task types

HinaBot supports 3 different types of items on a to-do list: regular tasks, deadlines (tasks which have a due-date),
and events (which have a start and end date).

### Search function

Description of the feature.
HinaBot allows you to search your to-do list for tasks that contain a particular substring, making it easier to keep
track of large numbers of tasks.

### Feature-XYZ
### Delete and mark functions

Description of the feature.
HinaBot allows you to mark tasks as done or not done and also supports deletion of a task.

### Save and load function
All changes you make to your to-do list are stored locally, meaning you can pick up right where you left off.

## Usage

### `Keyword` - Describe action
### `todo` - Add a regular task to the to-do list

Describe the action and its outcome.
Adds a regular task (no due date) to the to-do list. By default, the task is set as not done.

Example of usage:

`keyword (optional arguments)`
`todo buy milk`

Expected outcome:

The task is added to your to-do list and HinaBot announces how many tasks are currently on your list

```
Noted! This task has been added:
[T][ ] buy milk
There are 1 items on your list.
```
### `deadline` - Add a deadline to the to-do list

Adds a deadline (with a do-by date in dd-MMM-yyyy HH:mm format) to the to-do list. By default, the task is set as not done.

Example of usage:

`deadline Assignment 1 /by 04-Apr-2023 23:59`

Expected outcome:

Description of the outcome.
The deadline is added to your to-do list and HinaBot announces how many tasks are currently on your list

```
Noted! This task has been added:
[D][ ] Assignment 1 (by: 04-Apr-2023 23:59)
There are 2 items on your list
```
### `event` - Add an event to the to-do list

Adds an event (with start and end times in dd-MMM-yyyy HH:mm format) to the to-do list. By default, the task is set as not done.

Example of usage:

`event Midterms /from 03-Mar-2023 13:00 /to 03-Mar-2023 17:30`

Expected outcome:

The deadline is added to your to-do list and HinaBot announces how many tasks are currently on your list

```
Noted! This task has been added:
[E][ ] Midterms (from: 03-Mar-2023 13:00 to: 03-Mar-2023 17:30)
There are 2 items on your list
```
### `list` - Lists all tasks in the to-do list

Prints a list of all tasks in the to-do list including the task type and done status.

Example of usage:

`list`

Expected outcome:

The deadline is added to your to-do list and HinaBot announces how many tasks are currently on your list

```
1. [T][ ] buy milk
2. [D][ ] Assignment 1 (by: 04-Apr-2023 23:59)
3. [E][ ] Midterms (from: 03-Mar-2023 13:00 to: 03-Mar-2023 17:30)
```
### `mark` - Marks a task as done

Marks an item by its index on the to-do list as done. This is indicated by an 'X' in the checkbox next to
its description.

Example of usage:

`mark 1`

Expected outcome:

An acknowledgement message and an 'X' is printed in the checkbox next to item 1 on the to-do list.
```
expected output
Roger that! This task is marked as done:
[T][X] buy milk
```

### `unmark` - Marks a task as not done

Marks an item by its index on the to-do list as not done. This is indicated by a blank checkbox next to
its description.

Example of usage:

`unmark 1`

Expected outcome:

An acknowledgement message and a blank checkbox is printed next to item 1 on the to-do list.
```
Roger that! This task is marked as not done:
[T][ ] buy milk
```

### `delete` - Remove a task from the to-do list

Removes the item at the specified index from the to-do list.

Example of usage:

`delete 3`

Expected outcome:

An acknowledgement message and the description of the task being removed is shown, followed by an announcement
of the size of the remaining list.
```
Got it! This task will be removed:
[E][ ] Midterms (from: 03-Mar-2023 13:00 to: 03-Mar-2023 17:30)
There are 2 items on your list.
```

### `find` - Search for a task

Searches the to-do list for all tasks with a description containing the substring provided by the user.

Example of usage:

`find buy`

Expected outcome:

Any matching tasks, along with their index on the list, are printed.

```
Found a match! Here are the results master!
1. [T][ ] buy milk
```

### `bye` - Exits the program

Terminates the program and prints a goodbye message.

Example of usage:

`bye`

Expected outcome:

The program exits with code 0 and a goodbye message is shown.

```
Goodbye master, let's meet again soon...

Process finished with exit code 0
```
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: hina.HinaBot

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

import hina.exceptions.HinaException;
import hina.helper.Parser;
import hina.helper.Storage;
import hina.helper.TaskList;
import hina.helper.Ui;

import java.io.FileNotFoundException;

public class HinaBot {
private static Ui ui;
private static Storage storage;
private static TaskList tasks;

/**
* Class constructor specifying the path to a file containing save data. Tries to
* access the save file and attempts to create a new one if it does not exist.
*
* @param savePath path to the save file.
* @param dataDir directory the save file is stored in.
*/
public HinaBot(String savePath, String dataDir) {
ui = new Ui();
storage = new Storage();
Ui.showGreeting();
try {
tasks = new TaskList(Storage.readSaveFile(savePath));
} catch (FileNotFoundException exception) {
Storage.createSaveFile(savePath, dataDir);
}
}

public static void main(String[] args) {
new HinaBot("data/savedlist.txt", "data");

while (true) {
try {
Parser.readCommand();
} catch (HinaException cmdException) {
Ui.invalidCommandMessage();
} catch (StringIndexOutOfBoundsException argException) {
Ui.notEnoughDetails();
}
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/hina/exceptions/HinaException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package hina.exceptions;

public class HinaException extends Throwable {
}
87 changes: 87 additions & 0 deletions src/main/java/hina/helper/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package hina.helper;

import hina.exceptions.HinaException;

import java.io.IOException;
import java.util.Scanner;

/**
* Contains methods to process user input.
*/
public class Parser {
/**
* Reads a user input from the command line and determines if it was a command.
* If the input was a recognised command, handle it respectively, else throws
* a <code>HinaException</code>.
*
* @throws HinaException If the input is not recognised as a valid command.
*/
public static void readCommand() throws HinaException {
String line;
Scanner in = new Scanner(System.in);
line = in.nextLine().trim();
if (line.equalsIgnoreCase("bye")) {
Ui.showExitMessage();
System.exit(0);
} else if (line.equalsIgnoreCase("list")) {
TaskList.listTasks();
} else if (line.split(" ")[0].equalsIgnoreCase("mark")) {
try {
int taskIndex = Integer.parseInt(line.split(" ")[1]);
TaskList.markTask(taskIndex);
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
Ui.invalidNumberMessage();
}
try {
Storage.writeToFile();
} catch (IOException ioexception) {
Ui.couldNotSaveMessage();
}
} else if (line.split(" ")[0].equalsIgnoreCase("unmark")) {
int taskIndex = Integer.parseInt(line.split(" ")[1]);
TaskList.unmarkTask(taskIndex);
try {
Storage.writeToFile();
} catch (IOException ioexception) {
Ui.couldNotSaveMessage();
}
} else if (line.split(" ")[0].equalsIgnoreCase("todo")) {
TaskList.addTask(line.substring(5));
try {
Storage.writeToFile();
} catch (IOException ioexception) {
Ui.couldNotSaveMessage();
}
} else if (line.split(" ")[0].equalsIgnoreCase("deadline")) {
TaskList.addDeadline(line.substring(9));
try {
Storage.writeToFile();
} catch (IOException ioexception) {
Ui.couldNotSaveMessage();
}
} else if (line.split(" ")[0].equalsIgnoreCase("event")) {
TaskList.addEvent(line.substring(6));
try {
Storage.writeToFile();
} catch (IOException ioexception) {
Ui.couldNotSaveMessage();
}
} else if (line.split(" ")[0].equalsIgnoreCase("delete")) {
try {
int taskIndex = Integer.parseInt(line.split(" ")[1]);
TaskList.deleteTask(taskIndex);
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
Ui.invalidNumberMessage();
}
try {
Storage.writeToFile();
} catch (IOException ioexception) {
Ui.couldNotSaveMessage();
}
} else if (line.split(" ")[0].equalsIgnoreCase("find")) {
TaskList.findTask(line);
} else {
throw new HinaException();
}
}
}
Loading