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
2 changes: 2 additions & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
T | 0 | read
D | 0 | read | monday
102 changes: 86 additions & 16 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,100 @@
# Duke User Guide
# chatbot User Guide

// Update the title above to match the actual product name
**chatbot** is a simple, interactive command-line application that helps you manage tasks of various types. Whether you need to note down a quick to-do, track an upcoming deadline, or schedule an event, chatbot lets you create and organize tasks easily. You can also mark tasks as done, delete them, list all current tasks, and even search through them by keyword. The chatbot automatically saves your tasks, so they’re always available when you start it again.

// Product screenshot goes here

// Product intro goes here

## Adding deadlines
When you add a Deadline, you specify a description and a deadline time as a string.
This helps you keep track of tasks that have a specific due date.

Example: `deadline return book /by tomorrow`

Expected output:
~~~
Got it. I've added this task:
[D][ ] return book (by: tomorrow)
Now you have X tasks in the list.
~~~

## Feature: Add a Todo
Use this command to add a basic to-do item without any date/time.

Example: `todo read book`

Expected output:
~~~
Got it. I've added this task:
[T][ ] read book
Now you have X tasks in the list.
~~~

## Feature: Add an Event
Use this command to add an event with a start and end time/place.

Example: `event meeting /from Monday /to Tuesday`

Expected output:
~~~
Got it. I've added this task:
[E][ ] meeting (from: Monday to: Tuesday)
Now you have X tasks in the list.
~~~

## Feature: Mark a Task
Marks a specified task (by its number) as done.

Example: `mark 1`

Expected output:
~~~
Nice! I've marked this task as done:
[T][X] read book
~~~

## Feature: Unmark a Task
Unmarks a specified task (by its number) as not done.

Example: `unmark 1`

// Describe the action and its outcome.
Expected output:
~~~
OK, I've marked this task as not done yet:
[T][ ] read book
~~~

// Give examples of usage
## Feature: Delete a Task
Removes a specified task (by its number) from your list.

Example: `keyword (optional arguments)`
Example: `delete 1`

// A description of the expected outcome goes here
Expected output:
~~~
Noted. I've removed this task:
[T][ ] read book
Now you have X tasks in the list.
~~~

```
expected output
```
## Feature: List Tasks
Displays all tasks currently in your list, in order of creation.

## Feature ABC
Example: `list`

// Feature details
Expected output:
~~~
Here are the tasks in your list:
1.[T][ ] read book
2.[D][ ] return book (by: tomorrow)
3.[E][ ] meeting (from: Monday to: Tuesday)
~~~

## Feature: Find Tasks
Searches all tasks for a keyword in their description and displays the matches.

## Feature XYZ
Example: `find book`

// Feature details
Expected output:
~~~
Here are the matching tasks in your list:
1.[T][ ] read book
2.[D][ ] return book (by: tomorrow)
~~~
36 changes: 36 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Represents a Deadline task with a description and a "by" string.
*/
public class Deadline extends Task {
private String by;

/**
* Constructs a Deadline with the given description and by-string.
*
* @param description The task description.
* @param by The deadline or due date/time as a string.
*/
public Deadline(String description, String by) {
super(description);
this.by = by;
}

/**
* Returns the string specifying the deadline.
*
* @return The by string.
*/
public String getBy() {
return by;
}

/**
* Returns a string representation of a Deadline task.
*
* @return "[D]" + status + description + " (by: ...)"
*/
@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}
12 changes: 12 additions & 0 deletions src/main/java/DeadlineFormatException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Thrown when a user attempts to create a Deadline with incorrect formatting.
*/
public class DeadlineFormatException extends Exception {
/**
* Constructs a DeadlineFormatException and prints an error message.
*/
public DeadlineFormatException() {
System.out.println("Deadline format should be: "
+ "deadline <description> /by <d/M/yyyy HHmm>");
}
}
48 changes: 48 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Represents an Event task with a description, a "from" string, and a "to" string.
*/
public class Event extends Task {
private String from;
private String to;

/**
* Constructs an Event with the given description, from-string, and to-string.
*
* @param description The task description.
* @param from The start time/place.
* @param to The end time/place.
*/
public Event(String description, String from, String to) {
super(description);
this.from = from;
this.to = to;
}

/**
* Returns the "from" string.
*
* @return The from string.
*/
public String getFrom() {
return from;
}

/**
* Returns the "to" string.
*
* @return The to string.
*/
public String getTo() {
return to;
}

/**
* Returns a string representation of an Event task.
*
* @return "[E]" + status + description + " (from: ... to: ...)"
*/
@Override
public String toString() {
return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")";
}
}
12 changes: 12 additions & 0 deletions src/main/java/EventFormatException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Thrown when a user attempts to create an Event with incorrect formatting.
*/
public class EventFormatException extends Exception {
/**
* Constructs an EventFormatException and prints an error message.
*/
public EventFormatException() {
System.out.println("Event format should be: "
+ "event <description> /from <d/M/yyyy HHmm> /to <d/M/yyyy HHmm>");
}
}
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: chatbot

140 changes: 140 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/**
* Interprets user commands and lines from the storage file,
* and performs the necessary actions on the TaskList.
*/
public class Parser {

/**
* Handles a single user command, updating tasks as necessary
* and saving the changes.
*
* @param input The raw command input.
* @param tasks The TaskList to operate on.
* @param ui The Ui for printing messages.
* @param storage The Storage for saving changes.
* @return True if the command is "bye" (indicating an exit), else false.
* @throws TodoEmptyException If a todo command has an empty description.
* @throws DeadlineFormatException If a deadline command is malformed.
* @throws EventFormatException If an event command is malformed.
*/
public static boolean handleCommand(String input, TaskList tasks, Ui ui, Storage storage)
throws TodoEmptyException, DeadlineFormatException, EventFormatException {
if (input.equalsIgnoreCase("bye")) {
return true;
} else if (input.equalsIgnoreCase("list")) {
tasks.listTasks();
} else if (input.startsWith("mark ")) {
int index = Integer.parseInt(input.substring(5).trim()) - 1;
tasks.mark(index);
} else if (input.startsWith("unmark ")) {
int index = Integer.parseInt(input.substring(7).trim()) - 1;
tasks.unmark(index);
} else if (input.startsWith("delete ")) {
int index = Integer.parseInt(input.substring(7).trim()) - 1;
tasks.deleteTask(index);
} else if (input.startsWith("todo")) {
String description = input.substring(4).trim();
if (description.isEmpty()) {
throw new TodoEmptyException();
}
Todo todo = new Todo(description);
tasks.addTask(todo);
} else if (input.startsWith("deadline")) {
if (!input.contains("/by")) {
throw new DeadlineFormatException();
}
String[] parts = input.substring(8).split("/by");
if (parts.length < 2) {
throw new DeadlineFormatException();
}
String description = parts[0].trim();
String by = parts[1].trim();
if (description.isEmpty() || by.isEmpty()) {
throw new DeadlineFormatException();
}
Deadline d = new Deadline(description, by);
tasks.addTask(d);
} else if (input.startsWith("event")) {
if (!input.contains("/from") || !input.contains("/to")) {
throw new EventFormatException();
}
String[] parts = input.substring(5).split("/from|/to");
if (parts.length < 3) {
throw new EventFormatException();
}
String description = parts[0].trim();
String from = parts[1].trim();
String to = parts[2].trim();
if (description.isEmpty() || from.isEmpty() || to.isEmpty()) {
throw new EventFormatException();
}
Event e = new Event(description, from, to);
tasks.addTask(e);
} else if (input.startsWith("find ")) {
String keyword = input.substring(5).trim();
tasks.find(keyword);
} else {
ui.showError("I'm sorry, I don't understand that command.");
}
storage.save(tasks);
return false;
}

/**
* Parses a single line from the storage file into a Task.
* (Simple string-based approach for deadlines/events.)
*
* @param line A line from the file, e.g. "T | 0 | read book".
* @return The corresponding Task object, or null if unrecognized.
*/
public static Task parseTaskLine(String line) {
String[] parts = line.split("\\|");
for (int i = 0; i < parts.length; i++) {
parts[i] = parts[i].trim();
}
String type = parts[0];
boolean isDone = parts[1].equals("1");
String description = parts[2];

switch (type) {
case "T":
Todo todo = new Todo(description);
todo.setIsDone(isDone);
return todo;
case "D":
String by = parts[3];
Deadline d = new Deadline(description, by);
d.setIsDone(isDone);
return d;
case "E":
String from = parts[3];
String to = parts[4];
Event e = new Event(description, from, to);
e.setIsDone(isDone);
return e;
default:
return null;
}
}

/**
* Converts a Task into a line of text suitable for saving in the file.
*
* @param t The Task to encode.
* @return A string representation (e.g. "T | 1 | read book").
*/
public static String encodeTask(Task t) {
String doneBit = t.getIsDone() ? "1" : "0";
if (t instanceof Todo) {
return "T | " + doneBit + " | " + t.getDescription();
} else if (t instanceof Deadline) {
Deadline d = (Deadline) t;
return "D | " + doneBit + " | " + d.getDescription() + " | " + d.getBy();
} else if (t instanceof Event) {
Event e = (Event) t;
return "E | " + doneBit + " | " + e.getDescription() + " | " + e.getFrom() + " | " + e.getTo();
} else {
return "T | " + doneBit + " | " + t.getDescription();
}
}
}
Loading