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

[Guanlin] iP #187

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8d473bd
Increment Level 1
Feb 7, 2024
902153b
no message
Feb 7, 2024
37892d1
Level 1-1
Feb 7, 2024
8c29b77
Level-2
Feb 7, 2024
373d959
Level 3
Feb 8, 2024
6da7d59
Level 3
Feb 8, 2024
b832517
Level 4
Feb 14, 2024
ab3c2a2
A-CodeQuality
Feb 14, 2024
a5e25f4
Some clean up
Feb 15, 2024
c771a07
Level 5
Feb 18, 2024
068ec72
A-Packages with some exceptions refining
Feb 18, 2024
a0124d8
Added Array List Class
Feb 25, 2024
91efd3c
Added delete function to the bot
Feb 25, 2024
4ceb8bc
added file reading and writing along with some touch ups
Feb 25, 2024
fd754ce
made some changes according to TA comments
Feb 25, 2024
4b7773e
removed some magic numbers
Feb 25, 2024
2e7a416
Add UI class for future use
Mar 5, 2024
3d32a68
upload for PC use
Mar 6, 2024
abec695
add UI class and replaced body code with UI class
Mar 6, 2024
5b96b6d
add logic class and refactor code
Mar 6, 2024
2bfc693
add storage class and make main code more OOP
Mar 6, 2024
c447112
add TaskManager class and more OOP
Mar 7, 2024
f55da6d
add find function and create new IllegalArgumentException
Mar 7, 2024
0bc30b2
Merge pull request #1 from Fureimi/branch-Level-8
Fureimi Mar 7, 2024
e69231e
add javadoc comments to classes
Mar 7, 2024
976d60c
Merge branch 'master' of https://github.com/Fureimi/ip
Mar 7, 2024
96b0adc
Merge branch 'master' into branch-JavaDoc
Mar 7, 2024
d447eeb
Merge pull request #2 from Fureimi/branch-JavaDoc
Fureimi Mar 7, 2024
48ebd3d
add user guide
Mar 8, 2024
fc09fdc
do minor changes to readme formatting
Mar 8, 2024
6bd7337
do minor changes to README
Mar 8, 2024
09bebe3
change notes in readme
Mar 8, 2024
7107311
change ui and readme errors
Mar 8, 2024
6c21a23
clean up importing
Mar 8, 2024
f462c50
add error handling
Mar 8, 2024
9b642bc
import Tasks class
Mar 8, 2024
8f6b521
Merge branch 'master' into branch-Level-5
Mar 8, 2024
61d2e5a
Merge branch 'branch-Level-5'
Mar 8, 2024
0e69b9e
delete extra classes
Mar 8, 2024
d3581b7
add delete
Feb 25, 2024
b0ff90a
add save and loading
Feb 25, 2024
9f54241
Merge branch 'branch-Level-6'
Mar 8, 2024
35b1b33
Merge branch 'branch-Level-7'
Mar 8, 2024
a177300
final version of germabot (should be)
Mar 8, 2024
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
115 changes: 102 additions & 13 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,118 @@
# User Guide
# GermaBot User Guide

GermaBot is a task list bot. You can add, delete, find and list the stored tasks. GermaBot recognizes 3 different type
of tasks: Todo tasks, deadline tasks and event tasks.
GermaBot is also capable of saving files to your local hard disk, to the `/src/data/GermaBotData.txt` file.

## Features

### Feature-ABC
> ## Notes about the command format.
> - Words in `UPPER_CASE` are the parameters to be supplied by the user.
> - Extra parameters that do not take in any parameters (such as `list` and `bye`) will be ignored.
> e.g. if the input is `list 123`, it will be interpreted as `list`.



### Adding Todo tasks : `todo`
Adds a todo task to the task list.

Description of the feature.
Format: `todo TASK_NAME`

### Feature-XYZ
### Adding Deadline tasks : `deadline`
Adds a deadline task to the task list.

Description of the feature.
Format: `deadline TASK_NAME /by DEADLINE`

Example:
```
deadline Read a book /by 4th July
```

## Usage
### Adding Event tasks : `event`
Adds an event task to the task list.

### `Keyword` - Describe action
Format: `event TASK_NAME /from STARTDATE /to ENDDATE`

Describe the action and its outcome.
Example:
```
event Dad's party /from 6pm /to 12am
```

Example of usage:
### Listing all tasks : `list`
Shows the list of the current tasks, including the details of the task.

`keyword (optional arguments)`
Example input:
```
list
```
Example output:
```
Gotcha! Here are your tasks:
1. [T][X] Read a book
2. [D][ ] Finish IP (by: 23rd November)
3. [E][X] Dad's birthday party (from: 6pm to: 12am)
```

### Deleting tasks : `delete`
Deletes a task from the task list.

Format: `delete TASK_NUMBER`

Example:
```
delete 2
```
Example output:
```
Okay! I've removed this task from your To Do List:
[D][X] Finish IP (by: tmr)
Now you have, let me count... 4 items left in your To Do List!
```

Expected outcome:
### Finding tasks : `find`
Finds a task containing certain keywords.

Description of the outcome.
Format: `find KEYWORDS`

Example:
```
expected output
find book
```
Example output:
```
Gotcha! Finding tasks containing 'book'...
1. [T][X] Read a book
```

### Marking tasks as done : `mark`
Marks a task as done.

Format: `mark TASK_NUMBER`

Example:
```
mark 2
```
Example output:
```
Good job! I'll mark this task as done: [X] Finish IP
```

### Marking tasks as undone : `unmark`
Marks a task as undone.

Format: `unmark TASK_NUMBER`

Example:
```
unmark 1
```
Example output:
```
Aww, not done? Okay, I'll mark this task as undone: [ ] Read a book
```

### Exiting the program: `bye`
Exits the program.

Format: `bye`
3 changes: 3 additions & 0 deletions src/data/GermaBotData.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
T | 1 | Read a book
D | 0 | Finish IP | tmr
E | 1 | Do NOT drop out (IMPOSSIBLE) | now | end of semester
121 changes: 121 additions & 0 deletions src/main/java/DataHandling/LoadData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package DataHandling;

import Exceptions.FileReadException;
import Exceptions.LoadFileException;
import GermaBot.UI;
import Tasks.*;

import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;

/**
* The LoadData class handles loading tasks from a file into the program.
*/
public class LoadData {
static ArrayList<Task> toDoList = new ArrayList<>();
static int counter = 0;

/**
* Loads a ToDo task from a string description and adds it to the task list.
*
* @param description The description of the ToDo task.
* @throws LoadFileException If the description is empty.
*/
public static void loadToDo(String description) throws LoadFileException {
if (description.isEmpty()) {
throw new LoadFileException();
}
toDoList.add(new ToDo(description));
}

/**
* Loads a Deadline task from a string description and adds it to the task list.
*
* @param description The description of the Deadline task, including the deadline date.
* @throws LoadFileException If the description or deadline date is empty or invalid.
*/
public static void loadDeadline(String description) throws LoadFileException {
String[] deadlineDescription = description.split("\\|");
String task = deadlineDescription[0].trim();
String by = deadlineDescription[1].trim();
if (task.isBlank() || by.isBlank()) {
throw new LoadFileException();
}
toDoList.add(new Deadline(task, by));
}

/**
* Loads an Event task from a string description and adds it to the task list.
*
* @param description The description of the Event task, including the start and end dates.
* @throws LoadFileException If the description or dates are empty or invalid.
*/
public static void loadEvent(String description) throws LoadFileException {
String[] eventDescription = description.split("\\|");
String task = eventDescription[0].trim();
String from = eventDescription[1].trim();
String by = eventDescription[2].trim();
if (task.isBlank() || from.isBlank() || by.isBlank()) {
throw new LoadFileException();
}
toDoList.add(new Event(task, from, by));
}

/**
* Loads tasks from a file into the program.
*
* @return An ArrayList of tasks loaded from the file.
* @throws FileNotFoundException If the file is not found.
* @throws FileReadException If there is an error reading the file, such as if the file is in an invalid format.
*/
public static ArrayList<Task> loadFile() throws FileNotFoundException, FileReadException {
File data = new File("src/data/GermaBotData.txt");
Scanner fileInput = new Scanner(data);
do {
String task = fileInput.nextLine();
if (task.trim().isEmpty()) {
throw new FileReadException();
}
counter++;
char type = task.charAt(0);
String description = task.substring(8);
boolean isCompleted = task.charAt(4) != '0';
if (type == 'T') {
try {
loadToDo(description);
} catch (LoadFileException e) {
UI.printLoadFileException();
}
} else if (type == 'D') {
try {
loadDeadline(description);
} catch (LoadFileException e) {
UI.printLoadFileException();
}
} else if (type == 'E') {
try {
loadEvent(description);
} catch (LoadFileException e) {
UI.printLoadFileException();
}
} else {
break;
}
int idxToMark = toDoList.size() - 1;
toDoList.get(idxToMark).setDone(isCompleted);
} while (fileInput.hasNext());
fileInput.close();
return toDoList;
}

/**
* Returns the number of tasks loaded from the file.
*
* @return The number of tasks.
*/
public static int getCounter() {
return counter;
}
}
54 changes: 54 additions & 0 deletions src/main/java/DataHandling/SaveData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package DataHandling;

import Tasks.*;

import java.io.FileWriter;
import java.io.IOException;

/**
* The SaveData class handles saving tasks to a file.
*/
public class SaveData {
private static final String filePath = "src/data/GermaBotData.txt";

/**
* Saves a ToDo task to the file.
*
* @param toDoTask The ToDo task to be saved.
* @param taskType The type of the task ('T' for ToDo).
* @throws IOException If there is an error writing to the file.
*/
public static void addTodoToFile(ToDo toDoTask, char taskType) throws IOException {
FileWriter writer = new FileWriter(filePath, true);
writer.write("T | " + (toDoTask.isDone() ? "1" : "0") + " | " + toDoTask.getDescription() + System.lineSeparator());
writer.close();
}

/**
* Saves a Deadline task to the file.
*
* @param deadlineTask The Deadline task to be saved.
* @param taskType The type of the task ('D' for Deadline).
* @throws IOException If there is an error writing to the file.
*/
public static void addDeadlineToFile(Deadline deadlineTask, char taskType) throws IOException {
FileWriter writer = new FileWriter(filePath, true);
writer.write("D | " + (deadlineTask.isDone() ? "1" : "0") + " | " + deadlineTask.getDescription() +
" | " + deadlineTask.getBy() + System.lineSeparator());
writer.close();
}

/**
* Saves an Event task to the file.
*
* @param eventTask The Event task to be saved.
* @param taskType The type of the task ('E' for Event).
* @throws IOException If there is an error writing to the file.
*/
public static void addEventToFile(Event eventTask, char taskType) throws IOException {
FileWriter writer = new FileWriter(filePath, true);
writer.write("E | " + (eventTask.isDone() ? "1" : "0") + " | " + eventTask.getDescription() +
" | " + eventTask.getFrom() + " | " + eventTask.getTo() + System.lineSeparator());
writer.close();
}
}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

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

public class EmptyTaskException extends Exception{
}
4 changes: 4 additions & 0 deletions src/main/java/Exceptions/FileReadException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Exceptions;

public class FileReadException extends Exception{
}
4 changes: 4 additions & 0 deletions src/main/java/Exceptions/LoadFileException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Exceptions;

public class LoadFileException extends Exception {
}
4 changes: 4 additions & 0 deletions src/main/java/Exceptions/MissingDeadlineException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Exceptions;

public class MissingDeadlineException extends Exception{
}
4 changes: 4 additions & 0 deletions src/main/java/Exceptions/MissingStartDateException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Exceptions;

public class MissingStartDateException extends Exception{
}
4 changes: 4 additions & 0 deletions src/main/java/Exceptions/TaskNotFoundException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Exceptions;

public class TaskNotFoundException extends Exception{
}
4 changes: 4 additions & 0 deletions src/main/java/Exceptions/UnknownInputException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Exceptions;

public class UnknownInputException extends Exception{
}
Loading