Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
08758df
Rename Duke to Chatbot
imaginer96 Aug 31, 2023
70db08d
Implemented skeletal chatbot functionality
imaginer96 Aug 31, 2023
f199592
Implemented Level 1 - echo, bye
imaginer96 Aug 31, 2023
74cd269
Implemented Level 2 - Add, list
imaginer96 Aug 31, 2023
89fbf7b
Implemented Level 3 - Mark as Done
imaginer96 Aug 31, 2023
c78ca99
Level 4. ToDos, Events, Deadlines implemented
imaginer96 Sep 6, 2023
fc69e5c
A-Inheritance Implemented
imaginer96 Sep 6, 2023
725a683
Implemented Level-5 with Exceptions
imaginer96 Sep 12, 2023
7f288f7
Merge branch 'branch-Level-5'
imaginer96 Sep 12, 2023
6d91851
Implemented A-Packages
imaginer96 Sep 12, 2023
45634a7
Merge branch 'branch-A-Packages'
imaginer96 Sep 12, 2023
05dfeaf
Implemented Level-6 with A-Collections using ArrayList
imaginer96 Sep 20, 2023
c6f11a2
Implemented Level-7
imaginer96 Sep 20, 2023
0321771
Merge branch 'branch-Level-6'
imaginer96 Sep 20, 2023
5526242
Fixed bug where Task status was not saved in storage file
imaginer96 Sep 20, 2023
a608f54
Removed static variable numOfTask
imaginer96 Sep 20, 2023
5e2946d
Removed numOfTask variable references
imaginer96 Sep 20, 2023
46504a4
Implemented A-MoreOOP
imaginer96 Oct 6, 2023
5b89da7
Implemented A-MoreOOP
imaginer96 Oct 6, 2023
c33523b
Implemented branch-Level-9
imaginer96 Oct 6, 2023
2026fdf
A-UserGuide
imaginer96 Oct 6, 2023
0465ace
Modified user guide
imaginer96 Oct 6, 2023
3c63edf
update docs
imaginer96 Oct 8, 2023
8b4c583
extracted most .println calls from Command to the Ui class
imaginer96 Oct 24, 2023
0838b6a
added command package
imaginer96 Oct 24, 2023
1e16cf3
Refactored if-else commands to individual classes
imaginer96 Oct 24, 2023
ba940d1
fixed bug where program exists upon exception
imaginer96 Oct 24, 2023
888536f
added function comments
imaginer96 Oct 24, 2023
5cc3861
Merge pull request #1 from imaginarys96/FinalImprovements
imaginarys96 Oct 24, 2023
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
101 changes: 101 additions & 0 deletions src/main/java/Chatbot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import java.util.Scanner;

public class Chatbot {
public static void main(String[] args) {
Task[] tasks = new Task[100];
int numOfTasks = 0;

String greetingMsg = "____________________________________________________________\n" +
" Hello! I'm Chatbot\n" +
" What can I do for you?\n" +
"____________________________________________________________\n";
String byeMsg = "____________________________________________________________\n" +
" Bye. Hope to see you again soon!\n" +
"____________________________________________________________\n";
System.out.println(greetingMsg);


Scanner in = new Scanner(System.in);
String input = in.nextLine();
while(!input.equals("bye")) {
if (input.equals("list")) {
System.out.println("____________________________________________________________");
System.out.println(" Here are the tasks in your list:");
for (int i = 0; i < numOfTasks; i++) {
System.out.println(" " + (i + 1) + ".[" + tasks[i].getTypeIcon() + "][" + tasks[i].getStatusIcon() + "] " + tasks[i].getDescription());
}
System.out.println("____________________________________________________________");
} else if (input.startsWith("mark ")) {
String number = input.replace("mark ", "").trim();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

number is ambiguous, recommend to use taskNumber

int markTaskNo = Integer.parseInt(number);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

noun should not be named with a verb in it, recommend to combine with previous line and use taskNumber as previously mentioned

if (markTaskNo > 0) {
tasks[markTaskNo - 1].markAsDone();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

using -1 magical number, would be good to define what the -1 means

}
System.out.println("____________________________________________________________");
System.out.println(" Nice! I've marked this task as done:");
System.out.println(" [" + tasks[markTaskNo - 1].getStatusIcon() + "] " + tasks[markTaskNo - 1].getDescription());
System.out.println("____________________________________________________________");
} else if (input.startsWith("unmark ")) {
String number = input.replace("unmark ", "").trim();
int unmarkTaskNo = Integer.parseInt(number);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

variable name can be mistaken as an action, recommend to use unmarkedTaskNo

if (unmarkTaskNo > 0) {
tasks[unmarkTaskNo - 1].markAsUndone();
}
System.out.println("____________________________________________________________");
System.out.println(" OK, I've marked this task as not done yet:");
System.out.println(" [" + tasks[unmarkTaskNo - 1].getStatusIcon() + "] " + tasks[unmarkTaskNo - 1].getDescription());
System.out.println("____________________________________________________________");
} else if ( input.startsWith("todo") ) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unnecessary spaces for start and ends of brackets


String msg = input.replace("todo ", "").trim();
msg = msg.replace("deadline", "");
msg = msg.replace("event", "");

Task task = new Task(input, "T");
tasks[numOfTasks] = task;
numOfTasks++;

System.out.println("____________________________________________________________");
System.out.println(" Got it. I've added this task:");
System.out.println(" [" + task.getTypeIcon() + "][" + task.getStatusIcon() + "] " + task.getDescription());
System.out.println(" Now you have " + String.valueOf(numOfTasks) + " tasks in the list.");
System.out.println("____________________________________________________________");
} else if ( input.startsWith("deadline") ) {
String msg = input.replace("deadline", "");

Task task = new Task(input, "D");
tasks[numOfTasks] = task;
numOfTasks++;

System.out.println("____________________________________________________________");
System.out.println(" Got it. I've added this task:");
System.out.println(" [" + task.getTypeIcon() + "][" + task.getStatusIcon() + "] " + task.getDescription());
System.out.println(" Now you have " + String.valueOf(numOfTasks) + " tasks in the list.");
System.out.println("____________________________________________________________");
} else if ( input.startsWith("event") ) {
String msg = input.replace("event", "");

Task task = new Task(input, "E");
tasks[numOfTasks] = task;
numOfTasks++;

System.out.println("____________________________________________________________");
System.out.println(" Got it. I've added this task:");
System.out.println(" [" + task.getTypeIcon() + "][" + task.getStatusIcon() + "] " + task.getDescription());
System.out.println(" Now you have " + String.valueOf(numOfTasks) + " tasks in the list.");
System.out.println("____________________________________________________________");
} else {
// if not bye, list, mark, then the command by default is add
tasks[numOfTasks] = new Task(input, "");
numOfTasks++;
System.out.println("____________________________________________________________");
System.out.println("added: " + input);
System.out.println("____________________________________________________________");
}

input = in.nextLine();
}
System.out.println(byeMsg);

}
}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

25 changes: 25 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class Task {
protected String description;
protected boolean isDone;
protected String type;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

type is ambiguous, can be mistaken as a verb, recommend to use taskType

public Task(String description, String type) {
this.description = description;
this.isDone = false;
this.type = type;
}
public String getDescription() {
return this.description;
}
public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}
public void markAsDone() {
this.isDone = true;
}
public void markAsUndone() {
this.isDone = false;
}

public String getTypeIcon() { return type; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

curly bracket should start on a newline


}