Skip to content
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

[Ryan-Reno] iP #532

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
55f9f9f
docs/README.md: Tweak document template
Jan 7, 2024
f837ddb
Add Gradle support
May 24, 2020
a6f7324
Bump gradle and lib version
Eclipse-Dominator Aug 5, 2023
914b0da
Renamed the chatbot
Feb 7, 2024
3883a94
Added greeting and exits automatically
Feb 7, 2024
a53b53c
Added echo
Feb 7, 2024
f779cb6
Added a list that stores tasks
Feb 7, 2024
b476b0e
Added markings for tasks
Feb 7, 2024
6720e2c
Added todo, deadline, and event
Feb 7, 2024
7cde4a5
Added automatic Text UI Testing
Feb 7, 2024
b8e8a40
Added exception handling for invalid inputs
Feb 7, 2024
26a563c
Added delete task functionality
Feb 7, 2024
74b371d
Add save mechanism for task list
Ryan-Reno Feb 13, 2024
967b214
Merge branch 'branch-level-7'
Ryan-Reno Feb 13, 2024
a70afdd
Abstracted more classes to adhere with OOP principles
Ryan-Reno Feb 13, 2024
3b251c2
Divide classes into packages
Ryan-Reno Feb 13, 2024
7cfdf32
Merge branch 'add-gradle-support'
Ryan-Reno Feb 13, 2024
8d06856
Add JUnit testing for Event and Task
Ryan-Reno Feb 13, 2024
5a4b61a
Add JavaDocs
Ryan-Reno Feb 13, 2024
d72286d
Merge branch 'branch-A-JavaDoc'
Ryan-Reno Feb 13, 2024
c242028
Followed coding standards
Ryan-Reno Feb 13, 2024
478a06a
Add find functionality to find a task by a keyword
Ryan-Reno Feb 13, 2024
a5a756e
Merge branch 'branch-A-CodingStandard'
Ryan-Reno Feb 13, 2024
c17cb99
Merge branch 'branch-Level-9'
Ryan-Reno Feb 13, 2024
fbcab40
Task stores date and time instead of string
Ryan-Reno Feb 14, 2024
b42ffb8
Refactor methods to adhere with OOP
Ryan-Reno Feb 14, 2024
9aee97a
Change EventTest to fit with new output
Ryan-Reno Feb 14, 2024
6e47af2
Implement GUI with JavaFX and FXML
Ryan-Reno Feb 14, 2024
93cef7e
Merge branch 'branch-Level-10'
Ryan-Reno Feb 14, 2024
e01bd29
Use assert in Ui to ensure important assumptions
Ryan-Reno Feb 15, 2024
c182ae8
Improve code quality by creating Parser class
Ryan-Reno Feb 15, 2024
1edcad5
Merge pull request #1 from Ryan-Reno/branch-A-CodeQuality
Ryan-Reno Feb 15, 2024
322878f
Detect duplicate tasks
Ryan-Reno Feb 15, 2024
0ba61c0
Merge pull request #2 from Ryan-Reno/branch-BCD-Extension
Ryan-Reno Feb 15, 2024
cbfab43
Fix DialogBox height limit and add bye command
Ryan-Reno Feb 18, 2024
5d89871
Merge branch 'branch-BCD-Extension'
Ryan-Reno Feb 18, 2024
d35be93
Add JavaDocs to methods
Ryan-Reno Feb 18, 2024
328fdfa
Add User Guide
Ryan-Reno Feb 18, 2024
c21a0ce
Add Ui.png to the user guide
Ryan-Reno Feb 20, 2024
6b96869
Add picture to the website
Ryan-Reno Feb 20, 2024
7ef6d4a
Add greetings when first opening the app
Ryan-Reno Feb 20, 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
208 changes: 208 additions & 0 deletions src/main/java/Chatbot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
import java.sql.Array;
import java.util.Scanner;
import java.util.ArrayList;

public class Chatbot {
private Scanner scanner = new Scanner(System.in);
private String currentInput;
private ArrayList<Task> list;

Choose a reason for hiding this comment

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

Suggestion: Why not have a Tasks class to encapsulate the ArrayList objects? That way it makes the code in Chatbot.java a lot less dense, and you can abstract away most of the complexity into that class.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry I don't quite get what you mean. Isn't the point of the Task class to encapsulate the ArrayList objects? If so, doesn't my Task class behave the same with the Tasks class you suggested?



public Chatbot() {
this.currentInput = "";
this.list = new ArrayList<Task>();
}

public void start() {
greetings();
this.currentInput = scanner.nextLine();
while (!this.currentInput.equals("bye")) {
parseInput();
this.currentInput = scanner.nextLine();
}
exit();
}

private boolean isNumeric(String str) {
try {
Double.parseDouble(str);
return true;
} catch(NumberFormatException e){
return false;
}
}

private void parseInput() {
if (this.currentInput.equals("list")) {
outputList();
return;
}

String instruction[] = this.currentInput.split(" ", 2); // It only splits the first " "
if (instruction[0].equals("mark")) {
this.mark(instruction);
return;
}

if (instruction[0].equals("unmark")){
this.unmark(instruction);
return;
}

if (instruction[0].equals("delete")) {
this.delete(instruction);

Choose a reason for hiding this comment

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

Consider removing the 'this' reference since there is inconsistent styling with addToDo among other instructions

Suggested change
this.delete(instruction);
delete(instruction);

return;
}

if (instruction[0].equals("todo")) {
addToDo(instruction);
return;
}

if (instruction[0].equals("deadline")) {
addDeadline(instruction);
return;
}

if (instruction[0].equals("event")) {
addEvent(instruction);
return;
}

printHorizontalLine();
LiteException.InvalidInput();
}

private void delete(String instruction[]) {
try {
int index = Integer.parseInt(instruction[1]) - 1;
printHorizontalLine();
System.out.println("Noted. I've removed this task:\n" +
this.list.get(index) + "\n" +
"Now you have " + (this.list.size() - 1) + " tasks in the list.");
list.remove(index);
} catch (NullPointerException | ArrayIndexOutOfBoundsException e){
printHorizontalLine();
System.out.println("Please input a valid index. \n"
+ "The correct format is delete <index>. \n"
+ "The minimum index is 1 and the maximum index is " + this.list.size());
printHorizontalLine();
}
}

private void addToDo(String instruction[]) {
try {
String description = instruction[1];
printHorizontalLine();
System.out.println("Got it. I've added this task: ");
Task todo = new Todo(description);
this.list.add(todo);
System.out.println(todo);
System.out.println("Now you have " + this.list.size() + " tasks in the list");
printHorizontalLine();
} catch (ArrayIndexOutOfBoundsException e) {
printHorizontalLine();
System.out.println("Please give a name for the todo task. \n +" +
"The correct format is todo <description>");
printHorizontalLine();
}
}

private void addDeadline(String instruction[]) {
try {
String splits[] = instruction[1].split("/");
String description = splits[0];
String due = splits[1];
printHorizontalLine();
System.out.println("Got it. I've added this task: ");
Task deadline = new Deadline(description, due);
this.list.add(deadline);
System.out.println(deadline);
System.out.println("Now you have " + this.list.size() + " tasks in the list");
printHorizontalLine();
} catch (ArrayIndexOutOfBoundsException e) {
printHorizontalLine();
System.out.println("Invalid input. \n" +
"Please follow the format of: deadline <description> /by <date>");
printHorizontalLine();
}
}

private void addEvent(String[] instruction) {
try {
String splits[] = instruction[1].split("/");
String description = splits[0];
String start = splits[1];
String end = splits[2];
printHorizontalLine();
System.out.println("Got it. I've added this task: ");
Task event = new Event(description, start, end);
this.list.add(event);
System.out.println(event);
System.out.println("Now you have " + this.list.size() + " tasks in the list");
printHorizontalLine();
} catch (ArrayIndexOutOfBoundsException e) {
printHorizontalLine();
System.out.println("Invalid input. \n" +
"Please follow the format: event <description> /from <date> /to <date>");
printHorizontalLine();
}
}
private void unmark(String instruction[]) {
try {
int index = Integer.parseInt(instruction[1]) - 1;
printHorizontalLine();
System.out.println(this.list.get(index).unmark());
printHorizontalLine();
} catch (NullPointerException | ArrayIndexOutOfBoundsException e) {
printHorizontalLine();
System.out.println("Please input a valid index. \n"
+ "The correct format is unmark <index>. \n"
+ "The minimum index is 1 and the maximum index is " + list.size());
printHorizontalLine();
}
}

private void mark(String instruction[]) {
try {
int index = Integer.parseInt(instruction[1]) - 1;
printHorizontalLine();
System.out.println(this.list.get(index).mark());
printHorizontalLine();
} catch (NullPointerException | ArrayIndexOutOfBoundsException e) {
printHorizontalLine();
System.out.println("Please input a valid index. \n"
+ "The correct format is mark <index>. \n"
+ "The minimum index is 1 and the maximum index is " + list.size());
printHorizontalLine();
}
}

private void outputList() {
printHorizontalLine();
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < this.list.size(); i++) {
System.out.println((i+1) + ". " + this.list.get(i));
}
printHorizontalLine();
}

private void greetings() {
printHorizontalLine();
String msg = " Hello! I'm LITE\n" +
" What can I do for you?" ;
System.out.println(msg);
printHorizontalLine();
}

private void exit() {
printHorizontalLine();
String msg = " Bye. Hope to see you again soon!";
System.out.println(msg);
printHorizontalLine();
}

private void printHorizontalLine() {
System.out.println("____________________________________________________________");
}
}
14 changes: 14 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Deadline extends Task {
private String due;

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

@Override
public String toString() {
String dueSplit[] = due.split(" ", 2);
return "[D]" + super.toString() + "(" + dueSplit[0] + ": " + dueSplit[1] + ")";
}
}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class Event extends Task {
private String start;
private String end;

public Event(String description, String start, String end) {
super(description);
this.start = start;
this.end = end;
}

@Override
public String toString() {
String startSplit[] = start.split(" ", 2);
String endSplit[] = end.split(" ", 2);
return "[E]" + super.toString() + "(" + startSplit[0] + ": " + startSplit[1] +
endSplit[0] + ": " + endSplit[1] + ")";
}
}
15 changes: 15 additions & 0 deletions src/main/java/Lite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Lite {
public static void main(String[] args) {
String logo = " LLLLL IIIIIIIII TTTTTTTTTT EEEEEEEEEE \n" +

Choose a reason for hiding this comment

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

This is super cool and I really enjoy it :D

" LLLLL III TTT EEEEEEEEEE \n" +
" LLLLL III TTT EEE \n" +
" LLLLL III TTT EEEEEEEE \n" +
" LLLLL III TTT EEEEEEEE \n" +
" LLLLL III TTT EEE \n" +
" LLLLLLLLL IIIIIIIII TTT EEEEEEEEEE \n";

System.out.println("Hello from\n" + logo);
Chatbot chatbot = new Chatbot();
chatbot.start();
}
}
7 changes: 7 additions & 0 deletions src/main/java/LiteException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class LiteException {
public static void InvalidInput() {
System.out.println("Invalid input .\n" +
"Please begin your input with either one of these keywords: \n" +
"todo, list, deadline, event, mark, unmark, bye");
}
}
31 changes: 31 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class Task {
private String description;
private boolean isDone;

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

public String getStatusIcon() {
String done = (this.isDone ? "X" : "");
return "[" + done + "] ";
}

public String mark() {
this.isDone = true;
System.out.println("Nice! I've marked this task as done:");
return this.toString();
}

public String unmark() {
System.out.println("OK, I've marked this task as not done yet:");
this.isDone = false;
return this.toString();
}

@Override
public String toString() {
return getStatusIcon() + this.description;
}
}
11 changes: 11 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Todo extends Task {

public Todo(String description) {
super(description);
}

@Override
public String toString() {
return "[T]" + super.toString();
}
}
Loading