Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ee93d49
Add initial chatbot greeting and farewell code
Aug 27, 2024
e97299f
Enhance chatbot with command echoing and custom responses
Aug 27, 2024
83b1a8f
Add task storage and listing functionality to Lia
Aug 27, 2024
152a3fd
Add task marking functionality and refactor to use Task class
Aug 28, 2024
3537037
Refactor chatbot and Task class to follow coding standards
Aug 28, 2024
cb58915
Add code for ToDo, Deadline, and Event tasks in Lia
Sep 3, 2024
a2c539f
Add more print line indents to better align ouput
Sep 3, 2024
efc785b
Refactor I/O redirection testing setup for Duke
Sep 3, 2024
2806640
Refactor task addition logic in Duke to reduce code duplication
Sep 3, 2024
492ee59
Refactor Lia chatbot code to adhere to coding standards
Sep 9, 2024
8419b12
Refactor Task class into separate ToDo, Deadline, and Event subclasses
Sep 9, 2024
3c59eab
Add a new class called LiaException
Sep 9, 2024
3775ba5
Add error handling to Lia chatbot using exceptions
Sep 9, 2024
84d3c01
Merge branch 'branch-level-5'
Sep 9, 2024
cb198a4
Refactor Task class to include ToDo, Deadline, and Event subclasses
Sep 9, 2024
8f10200
Organize Lia chatbot into task and exception packages
Sep 10, 2024
4ae1e71
Merge branch 'branch-A-Packages'
Sep 10, 2024
0d8410c
Fix task count incrementation for non-task-adding commands
Sep 10, 2024
3db5cdc
Reimplement task marking and unmarking functionality
Sep 10, 2024
1d828de
Refactor Lia chatbot to use ArrayList for task management
Sep 17, 2024
cd4443e
Add delete function to Lia chatbot
Sep 17, 2024
b8c0232
Add file saving and loading functionality to Lia chatbot
Sep 17, 2024
35e1c12
Add error handling for corrupted data in file loading
Sep 17, 2024
708a2ba
Merge branch 'branch-Level-6'
Sep 17, 2024
3f2fa4e
Merge branch 'branch-Level-7'
Sep 17, 2024
05cb2bb
Refactor code to improve OOP structure
Oct 10, 2024
5665e33
Enhance chatBot to support date and time handling
Oct 10, 2024
6ad1da8
Merge pull request #1 from wahkia/branch-level-8
wahkia Oct 10, 2024
d8d77a6
Implement find command to search for tasks by keyword
Oct 10, 2024
a191c7e
Merge pull request #2 from wahkia/branch-Level-9
wahkia Oct 10, 2024
46f1638
Add Javadoc comments tfor improved code documentation
Oct 10, 2024
0af4ce4
Merge pull request #3 from wahkia/branch-A-JavaDoc
wahkia Oct 10, 2024
145a188
Add User Guide for Lia chatbot with usage instructions and features
Oct 10, 2024
a06ac05
Merge pull request #4 from wahkia/branch-A-UserGuide
wahkia Oct 10, 2024
12da9a8
Update on the style and design of the user guie
Oct 10, 2024
b94104e
Enhance Lia's personality in chatbot responses and add emojis for imp…
Oct 10, 2024
bb6f4f5
Upadate lia chatBot to not include emojis
Oct 10, 2024
362dd99
Add getting started section to the user guide
Oct 10, 2024
636a76e
Refactor the run command for Lia.jar
Oct 10, 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
126 changes: 126 additions & 0 deletions src/main/java/Lia.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import java.util.Scanner;

/**
* Lia is a simple chatbot program that helps users manage tasks.
*/
public class Lia {

public static void main(String[] args) {
// Customizing the chatbot with the name Lia
String logo =

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Coding Standard: Logo is constant. Use LOGO

"""
██▓ ██▓ ▄▄▄ \s
▓██▒ ▓██▒▒████▄ \s
▒██░ ▒██▒▒██ ▀█▄ \s
▒██░ ░██░░██▄▄▄▄██\s
░██████▒░██░ ▓█ ▓██▒
░ ▒░▓ ░░▓ ▒▒ ▓▒█░
░ ░ ▒ ░ ▒ ░ ▒ ▒▒ ░
░ ░ ▒ ░ ░ ▒ \s
░ ░ ░ ░ ░
""";

Scanner scanner = new Scanner(System.in);
String input;
Task[] tasks = new Task[100]; // Fixed-size array to store tasks
int taskCount = 0; // Counter to keep track of the number of tasks

// Greet the user with enthusiasm

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this looks like a note-to-self comment or a redundant comment; can be removed

printLine();
System.out.println(" Hello! I'm \n" + logo);
System.out.println(" What can I do for you?");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Instead of leaving whitespaces use a constant String with the amount of whitespace and add them as INCIDENTION. This way UI bugs of not using enough whitespace can be avoided.

printLine();

// Chatbot loop: keep asking for input until "bye" is entered
while (true) {
input = scanner.nextLine().trim();
String[] inputArr = input.split(" ", 2); // Splitting command and details

// If the user types "bye", end the loop with a warm farewell
if (inputArr[0].equalsIgnoreCase("bye")) {
printLine();
System.out.println(" Bye. Hope to see you again soon!");
printLine();
break;
}

// If the user types "list", display all tasks added
if (inputArr[0].equalsIgnoreCase("list")) {
printLine();
if (taskCount == 0) {
System.out.println(" No tasks found.");
} else {
System.out.println(" Here are the tasks in your list:");
for (int i = 0; i < taskCount; i++) {
System.out.println(" " + (i + 1) + "." + tasks[i].toString());
}
}
printLine();
} else if (inputArr[0].equalsIgnoreCase("mark")) {
int taskIndex = Integer.parseInt(inputArr[1]) - 1;
if (taskIndex >= 0 && taskIndex < taskCount) {
tasks[taskIndex].markAsDone();
printLine();
System.out.println(" Nice! I've marked this task as done:");
System.out.println(" " + tasks[taskIndex].toString());
printLine();
}
} else if (inputArr[0].equalsIgnoreCase("unmark")) {
int taskIndex = Integer.parseInt(inputArr[1]) - 1;
if (taskIndex >= 0 && taskIndex < taskCount) {
tasks[taskIndex].markAsNotDone();
printLine();
System.out.println(" OK, I've marked this task as not done yet:");
System.out.println(" " + tasks[taskIndex].toString());
printLine();
}
} else if (inputArr[0].equalsIgnoreCase("todo")) {
tasks[taskCount] = new ToDo(inputArr[1]);
taskCount++;
addTaskAndPrint(tasks[taskCount - 1], taskCount);
} else if (inputArr[0].equalsIgnoreCase("deadline")) {
String[] details = inputArr[1].split(" /by ", 2);
tasks[taskCount] = new Deadline(details[0], details[1]);
taskCount++;
addTaskAndPrint(tasks[taskCount - 1], taskCount);
} else if (inputArr[0].equalsIgnoreCase("event")) {
String[] details = inputArr[1].split(" /from ", 2);
String[] times = details[1].split(" /to ", 2);
tasks[taskCount] = new Event(details[0], times[0], times[1]);
taskCount++;
addTaskAndPrint(tasks[taskCount - 1], taskCount);
} else {
// Add the user's input as a new task
tasks[taskCount] = new Task(input);
taskCount++;
printLine();
System.out.println(" added: " + input);
printLine();
}
}

// Close the scanner to prevent resource leak
scanner.close();
}

/**
* Adds a task and prints the confirmation message.
*
* @param task The task to be added.
* @param taskCount The current number of tasks.
*/
private static void addTaskAndPrint(Task task, int taskCount) {
printLine();
System.out.println(" Got it. I've added this task:");
System.out.println(" " + task.toString());
System.out.println(" Now you have " + taskCount + " tasks in the list.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done. The feedback to the user is helpful.

printLine();
}

/**
* Prints a line separator.
*/
public static void printLine() {
System.out.println(" ___________________________________________________________");
}
}
139 changes: 139 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* Represents a task with a description and completion status (done or not done).
*/
public class Task {
protected String description;
protected boolean isDone;

/**
* Creates a new Task with the given description.
* By default, the task is marked as not done.
*
* @param description A description of the task
*/
public Task(String description) {
this.description = description;
this.isDone = false; // By default, a task is not done when created
}

/**
* Returns the status icon of the task.
* "X" indicates that the task is done, and " " indicates that it is not done.
*
* @return The status icon of the task.
*/
public String getStatusIcon() {
return (isDone ? "X" : " "); // "X" for done, " " for not done
}

/**
* Marks the task as done.
*/
public void markAsDone() {
this.isDone = true;
}

/**
* Marks the task as not done.
*/
public void markAsNotDone() {
this.isDone = false;
}

/**
* Returns a string representation of the task,
* including its status and description.
*
* @return A string representing the task.
*/
@Override
public String toString() {
return "[" + getStatusIcon() + "] " + description;
}
}

/**
* Represents a ToDo task, which is a task without any specific date or time.
*/
class ToDo extends Task {

/**
* Creates a new ToDo task with the given description.
*
* @param description A description of the ToDo task.
*/
public ToDo(String description) {
super(description);
}

/**
* Returns a string representation of the ToDo task.
*
* @return A string representing the ToDo task.
*/
@Override
public String toString() {
return "[T]" + super.toString();
}
}

/**
* Represents a Deadline task, which is a task that needs to be done
* before a specific date/time.
*/
class Deadline extends Task {
protected String by;

/**
* Creates a new Deadline task with the given description and deadline.
*
* @param description A description of the task.
* @param by The deadline by which the task must be completed.
*/
public Deadline(String description, String by) {
super(description);
this.by = by;
}

/**
* Returns a string representation of the Deadline task.
*
* @return A string representing the Deadline task.
*/
@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}

/**
* Represents an Event task, which is a task that starts and ends
* at specific dates/times.
*/
class Event extends Task {
protected String start;
protected String end;

/**
* Creates a new Event task with the given description, start, and end times.
*
* @param description A description of the event.
* @param start The start time of the event.
* @param end The end time of the event.
*/
public Event(String description, String start, String end) {
super(description);
this.start = start;
this.end = end;
}

/**
* Returns a string representation of the Event task.
*

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider creating new files for each class.

* @return A string representing the Event task.
*/
@Override
public String toString() {
return "[E]" + super.toString() + " (from: " + start + " to: " + end + ")";
}
}
72 changes: 66 additions & 6 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,67 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|
___________________________________________________________
Hello! I'm
██▓ ██▓ ▄▄▄
▓██▒ ▓██▒▒████▄
▒██░ ▒██▒▒██ ▀█▄
▒██░ ░██░░██▄▄▄▄██
░██████▒░██░ ▓█ ▓██▒
░ ▒░▓ ░░▓ ▒▒ ▓▒█░
░ ░ ▒ ░ ▒ ░ ▒ ▒▒ ░
░ ░ ▒ ░ ░ ▒
░ ░ ░ ░ ░

What can I do for you?
___________________________________________________________
___________________________________________________________
Got it. I've added this task:
[T][ ] read book
Now you have 1 tasks in the list.
___________________________________________________________
___________________________________________________________
Here are the tasks in your list:
1.[T][ ] read book
___________________________________________________________
___________________________________________________________
Got it. I've added this task:
[D][ ] return book (by: Sunday)
Now you have 2 tasks in the list.
___________________________________________________________
___________________________________________________________
Here are the tasks in your list:
1.[T][ ] read book
2.[D][ ] return book (by: Sunday)
___________________________________________________________
___________________________________________________________
Got it. I've added this task:
[E][ ] project meeting (from: Mon 2pm to: 4pm)
Now you have 3 tasks in the list.
___________________________________________________________
___________________________________________________________
Here are the tasks in your list:
1.[T][ ] read book
2.[D][ ] return book (by: Sunday)
3.[E][ ] project meeting (from: Mon 2pm to: 4pm)
___________________________________________________________
___________________________________________________________
Nice! I've marked this task as done:
[T][X] read book
___________________________________________________________
___________________________________________________________
Here are the tasks in your list:
1.[T][X] read book
2.[D][ ] return book (by: Sunday)
3.[E][ ] project meeting (from: Mon 2pm to: 4pm)
___________________________________________________________
___________________________________________________________
OK, I've marked this task as not done yet:
[T][ ] read book
___________________________________________________________
___________________________________________________________
Here are the tasks in your list:
1.[T][ ] read book
2.[D][ ] return book (by: Sunday)
3.[E][ ] project meeting (from: Mon 2pm to: 4pm)
___________________________________________________________
___________________________________________________________
Bye. Hope to see you again soon!
___________________________________________________________
11 changes: 11 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
todo read book
list
deadline return book /by Sunday
list
event project meeting /from Mon 2pm /to 4pm

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

consider adding "wrong user input" to test whether the application breaks if e.g. deadline is used without /by.

list
mark 1
list
unmark 1
list
bye
2 changes: 1 addition & 1 deletion text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 (
REM no error here, errorlevel == 0

REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT
java -classpath ..\bin Duke < input.txt > ACTUAL.TXT
java -classpath ..\bin Lia < input.txt > ACTUAL.TXT

REM compare the output to the expected output
FC ACTUAL.TXT EXPECTED.TXT
Loading