-
Notifications
You must be signed in to change notification settings - Fork 434
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
base: master
Are you sure you want to change the base?
[Ryan-Reno] iP #532
Changes from 9 commits
55f9f9f
f837ddb
a6f7324
914b0da
3883a94
a53b53c
f779cb6
b476b0e
6720e2c
7cde4a5
b8e8a40
26a563c
74b371d
967b214
a70afdd
3b251c2
7cfdf32
8d06856
5a4b61a
d72286d
c242028
478a06a
a5a756e
c17cb99
fbcab40
b42ffb8
9aee97a
6e47af2
93cef7e
e01bd29
c182ae8
1edcad5
322878f
0ba61c0
cbfab43
5d89871
d35be93
328fdfa
c21a0ce
6b96869
7ef6d4a
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,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; | ||||||
|
||||||
|
||||||
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); | ||||||
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 removing the 'this' reference since there is inconsistent styling with addToDo among other instructions
Suggested change
|
||||||
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("____________________________________________________________"); | ||||||
} | ||||||
} |
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] + ")"; | ||
} | ||
} |
This file was deleted.
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] + ")"; | ||
} | ||
} |
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" + | ||
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 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(); | ||
} | ||
} |
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"); | ||
} | ||
} |
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; | ||
} | ||
} |
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(); | ||
} | ||
} |
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.
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.
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.
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?