Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
cfe27b7
Add chatbot skeleton
yuhengr Jan 26, 2024
6db6312
Add level 1
yuhengr Feb 2, 2024
efcec81
Add level 2
yuhengr Feb 9, 2024
3440622
Add level 3
yuhengr Feb 9, 2024
cec49c2
Add level 4
yuhengr Feb 9, 2024
55b6be6
Add level 5
yuhengr Feb 22, 2024
a23e514
Add level 5 in branch-Level-5
yuhengr Feb 22, 2024
98de3d5
Add error handling for mark and unmark
yuhengr Feb 22, 2024
b04d05d
Rename variables
yuhengr Feb 22, 2024
43028d3
Change error messages for mark and unmark
yuhengr Feb 22, 2024
c504b93
Merge branch 'branch-Level-5'
yuhengr Feb 22, 2024
894d758
Add skeleton for delete
yuhengr Feb 22, 2024
17b2bac
Add delete feature
yuhengr Feb 22, 2024
f28f0ce
Add level 7 write to file
yuhengr Feb 22, 2024
eb7ebe6
Disable opening logo
yuhengr Feb 22, 2024
0af291b
Merge branch 'branch-Level-6'
yuhengr Feb 22, 2024
ab8d095
Add level 7 read from file
yuhengr Feb 23, 2024
1bb8666
Merge branch-Level-7
yuhengr Mar 6, 2024
2032036
Refactor read from file functionality to a method
yuhengr Mar 6, 2024
e46f8a7
Refactor to remove magic numbers
yuhengr Mar 6, 2024
68e709b
Add storage package skeleton
yuhengr Mar 6, 2024
5a43cbc
Refactor tasks-related classes to package
yuhengr Mar 6, 2024
1e5b368
Modify classes in package task
yuhengr Mar 6, 2024
ff6ffbf
Import package task
yuhengr Mar 6, 2024
accdf6f
Add imports for class Storage
yuhengr Mar 6, 2024
b9139c0
Add class TaskList
yuhengr Mar 6, 2024
616a5d4
Add addTodo method in class TaskList
yuhengr Mar 6, 2024
7622977
Abstract commands into class TaskList
yuhengr Mar 6, 2024
5aa8ebe
Refactor file management into class Storage
yuhengr Mar 7, 2024
3a67fa2
Add package ui
yuhengr Mar 7, 2024
dc65e62
Add messages to class UI
yuhengr Mar 7, 2024
101a9a0
Fix bug that appends additional ) when loading tasks
yuhengr Mar 7, 2024
86e95f3
Refactor ui messages
yuhengr Mar 7, 2024
2e41c85
Modify to handle both upper and lower cases
yuhengr Mar 7, 2024
6af42f4
Add class Parser skeleton
yuhengr Mar 7, 2024
400cc86
Add parseTodo method to class Parser
yuhengr Mar 7, 2024
6738b93
Add methods to parse Deadline and Event to class Parser
yuhengr Mar 7, 2024
6fd592c
Fix bug. Empty Todo description will now be caught.
yuhengr Mar 7, 2024
4c0e67f
Trim user input before adding to tasks
yuhengr Mar 7, 2024
a702714
Refactor error messages
yuhengr Mar 7, 2024
b4baa94
Add Level-9 in branch-Level-9
yuhengr Mar 7, 2024
449d6ca
Merge pull request #1 from yuhengr/branch-Level-9
yuhengr Mar 7, 2024
ea0b2b4
Refactor code
yuhengr Mar 7, 2024
2b97a19
Add A-JavaDoc
yuhengr Mar 7, 2024
6152c52
Merge pull request #2 from yuhengr/branch-A-JavaDoc
yuhengr Mar 8, 2024
f7ab8bc
Add more comments
yuhengr Mar 8, 2024
0428822
Add initial edit for A-UserGuide
yuhengr Mar 8, 2024
ea631e8
Add more JavaDoc comments
yuhengr Mar 8, 2024
ff8bf1e
Edit README.md
yuhengr 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
64 changes: 52 additions & 12 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,69 @@
# User Guide
# User Guide - Chatbot Ekud
This is the user guide for chatbot Ekud, a Command Line Interface (CLI) application.<br>

## Features

### Feature-ABC
### Adding a task
Adds a task to the task list. The task can be a Todo, Deadline or Event.<br>

Description of the feature.
## Usage
> `todo <description>`<br>
> Adds a Todo task with the given description.

> `deadline <description> /by <by>`<br>
> Adds a Deadline task with the given description and deadline to meet.

> `event <description> /from <from> /to <to>`<br>
> Adds an event task with its ongoing period.

### Listing all the tasks

Shows a list of all the tasks in the task list.

## Usage
> `list`

### Deleting a task

Deletes a task in the task list.

### Feature-XYZ
## Usage
> `delete <index>`

### Marking a task

Description of the feature.
Mark a task as completed.

## Usage
> `mark <index>`

### `Keyword` - Describe action
### Unmarking a task

Describe the action and its outcome.
Unmark a task as uncompleted.

Example of usage:
## Usage
> `unmark <index>`

`keyword (optional arguments)`
### Deleting a task

Expected outcome:
Deletes a task based on the task number.

## Usage
> `delete <index>`

### Finding a task

Finds relevant tasks based on keyword.

## Usage
> `find <keyword>`

Description of the outcome.
#### Example of usage:
`find books` - Finds tasks that contain keyword "books".

#### Expected outcome:
```
expected output
Here are the relevant tasks:
1.[T][] read book
2.[D][] return book
```
85 changes: 79 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,83 @@
import java.util.Scanner;
import java.io.FileNotFoundException;
import java.io.IOException;
import exception.EkudException;
import task.TaskList;
import storage.Storage;
import ui.UI;

/**
* This Duke class is an abstraction of the chatbot and provides its driver method.
*/
public class Duke {

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);

System.out.println(UI.GREETING_MESSAGE);

String userInput;
Scanner in = new Scanner(System.in);
TaskList tasks = new TaskList();

Storage storage = new Storage();

// Try to load existing tasks.
try {
tasks = storage.readFromFile();
}
catch (FileNotFoundException error){
System.out.println(UI.FILE_NOT_FOUND_MESSAGE);
}

userInput = in.nextLine();

while(!userInput.equals("bye")){
String[] userInputWords = userInput.split(" ");
String userCommand = userInputWords[0].toLowerCase();

if(userCommand.equals("list")){
tasks.list();
}
else if(userCommand.equals("mark")){
tasks.mark(userInput);
}
else if(userCommand.equals("unmark")){
tasks.unmark(userInput);
}
else if(userCommand.equals("todo")){
tasks.addTodo(userInput);
}
else if(userCommand.equals("deadline")){
tasks.addDeadline(userInput);
}
else if(userCommand.equals("event")){
tasks.addEvent(userInput);
}
else if(userCommand.equals("delete")){
tasks.delete(userInput);
}
else if(userCommand.equals("find")) {
tasks.find(userInput);
}
else{
try {
throw new EkudException();
}
catch (EkudException error){
System.out.println(UI.INVALID_COMMAND_MESSAGE);
}
}
userInput = in.nextLine();
}

// Save tasks before ending the session.
try {
storage.writeToFile(tasks);
}
catch(IOException error) {
System.out.println(UI.FILE_WRITE_ERROR_MESSAGE);
}

System.out.println(UI.EXIT_MESSAGE);
}
}
4 changes: 4 additions & 0 deletions src/main/java/exception/EkudException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package exception;

public class EkudException extends Exception {
}
49 changes: 49 additions & 0 deletions src/main/java/storage/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package storage;

import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import task.TaskList;

/**
* This Storage class is a file manager that stores the list of tasks.
*/
public class Storage {

private static final String filePath = "tasks.txt";

public Storage() {}

/**
* Saves the tasks before ending the chatbot session.
*
* @param tasks contain the tasks that were added during the session.
* @throws IOException if the text file cannot be opened or written to etc.
*/
public void writeToFile(TaskList tasks) throws IOException {
FileWriter fw = new FileWriter(filePath);
for(int i = 0; i < tasks.getTaskCount(); i++){
fw.write(tasks.getTask(i).toString() + "\n");
}
fw.close();
};

/**
* Loads pre-existing tasks from a text file.
*
* @return TaskList object containing the loaded tasks.
* @throws FileNotFoundException if the text file cannot be found.
*/
public TaskList readFromFile() throws FileNotFoundException {
File f = new File(filePath);
Scanner s = new Scanner(f);
TaskList tasks = new TaskList();
while(s.hasNext()) {
String currentLine = s.nextLine();
tasks.addTaskFromFile(currentLine);
}
return tasks;
};
}
19 changes: 19 additions & 0 deletions src/main/java/task/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package task;

/**
* This Deadline class represents a task with a deadline to meet.
*/
public class Deadline extends Task {

protected String by;

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

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}
20 changes: 20 additions & 0 deletions src/main/java/task/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package task;

/**
* This Event class represents a task and its ongoing period.
*/
public class Event extends Task {

protected String startTime;
protected String endTime;

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

public String toString() {
return "[E]" + super.toString() + " (from: " + this.startTime + " to: " + this.endTime + ")";
}
}
31 changes: 31 additions & 0 deletions src/main/java/task/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package task;

/**
* The super class for Todo, Deadline and Event.
*/
public class Task {
protected String description;
protected boolean isDone;

public Task(String description) {
this.description = description;
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "X" : " ");
}

public void markAsDone() {
this.isDone = true;
}

public void markAsNotDone() {
this.isDone = false;
}

@Override
public String toString() {
return String.format("[%s] %s", this.getStatusIcon(), this.description);
}
}
Loading