-
Notifications
You must be signed in to change notification settings - Fork 114
[wahkia] iP #99
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
base: master
Are you sure you want to change the base?
[wahkia] iP #99
Changes from 9 commits
ee93d49
e97299f
83b1a8f
152a3fd
3537037
cb58915
a2c539f
efc785b
2806640
492ee59
8419b12
3c59eab
3775ba5
84d3c01
cb198a4
8f10200
4ae1e71
0d8410c
3db5cdc
1d828de
cd4443e
b8c0232
35e1c12
708a2ba
3f2fa4e
05cb2bb
5665e33
6ad1da8
d8d77a6
a191c7e
46f1638
0af4ce4
145a188
a06ac05
12da9a8
b94104e
bb6f4f5
362dd99
636a76e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 = | ||
| """ | ||
| ██▓ ██▓ ▄▄▄ \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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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."); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(" ___________________________________________________________"); | ||
| } | ||
| } | ||
| 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. | ||
| * | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 + ")"; | ||
| } | ||
| } | ||
| 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! | ||
| ___________________________________________________________ |
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment.
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