-
Notifications
You must be signed in to change notification settings - Fork 590
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
[Nicholascyx] ip #625
base: master
Are you sure you want to change the base?
[Nicholascyx] ip #625
Changes from 13 commits
68c58c1
03523ec
81a9c53
459380b
5a9e282
b4bbf71
e134e90
c8593dd
8b32bad
eccb99a
2792677
9377e1d
bbf800e
7a84450
246d624
2527e8c
efa2a78
d2e9b4e
30ccaeb
6d9bfa9
ac0f46e
a556a31
32b6215
4c7c84d
58d631d
b28d0cb
c2a4109
00907a3
67cb1a1
31ee68b
fd6d300
58a71df
0b4ccdb
440f471
294c546
d5b379b
e090307
d8bddd1
7e36021
b080878
b35dcac
edd7146
0303a46
16a76a5
80768a8
2c9400f
ba37625
015627c
283b4e4
94e7c8f
0c71886
1898269
42d6385
c9ce769
13e20f2
d7e2b2f
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,14 @@ | ||
public class Deadline extends Task { | ||
|
||
protected String by; | ||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + "(by:" + by + ")"; | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class Event extends Task { | ||
|
||
protected String from; | ||
protected String to; | ||
|
||
public Event(String description, String from, String to) { | ||
super(description); | ||
this.from = from; | ||
this.to = to; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + "(from:" + from + "to:" + to + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
public class Kafka { | ||
|
||
public ArrayList<Task> tasks = new ArrayList<>(); | ||
|
||
public void greet() { | ||
String message = """ | ||
Hello. Kafka here. | ||
We meet again. | ||
"""; | ||
System.out.println(message); | ||
} | ||
|
||
public void goodbye() { | ||
String message = " Farewell. I look forward to our next meeting, wherever destiny may lead us. "; | ||
System.out.println(message); | ||
} | ||
|
||
public void addTask(Task task) { | ||
this.tasks.add(task); | ||
System.out.println(" Got it. I've added this task."); | ||
System.out.println(" " + task); | ||
System.out.println(" Now you have " + this.tasks.size() + " task(s) in the list."); | ||
} | ||
|
||
public void createList() { | ||
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. The function name is a little misleading as it does not create a new list. Perhaps getList or printList might be better? |
||
System.out.println(" Here are the tasks in your list:"); | ||
for (int i = 0; i < this.tasks.size(); i++) { | ||
Task t = this.tasks.get(i); | ||
String listMessage = " " + (i + 1) + "." + t; | ||
System.out.println(listMessage); | ||
} | ||
} | ||
|
||
public void mark(int taskNumber) { | ||
Task t = this.tasks.get(taskNumber - 1); | ||
t.markAsDone(); | ||
String message = " Good work on this task. Want a prize?:\n" | ||
+ " " + t; | ||
System.out.println(message); | ||
} | ||
|
||
public void unmark(int taskNumber) { | ||
Task t = this.tasks.get(taskNumber - 1); | ||
t.markAsNotDone(); | ||
String message = " Hurry up. This task is necessary for Elio's script:\n" | ||
+ " " + t; | ||
System.out.println(message); | ||
} | ||
|
||
public void delete(int taskNumber) { | ||
if (this.tasks.isEmpty()) { | ||
return; | ||
} | ||
Task t = this.tasks.get(taskNumber - 1); | ||
this.tasks.remove(taskNumber - 1); | ||
String message = " I've removed this task:\n" | ||
+ " " + t; | ||
System.out.println(message); | ||
System.out.println(" Now you have " + this.tasks.size() + " task(s) in the list."); | ||
} | ||
|
||
public static void main(String[] args) { | ||
String logo = """ | ||
__ __ __ _ | ||
| |/ / ____ _/ /_ | | ____ | ||
| / / _ | |_ _| | |/ / / _ | | ||
| \\ | |_| | | | | < | |_| | | ||
|__|\\__\\ \\____| |__| |_|\\ \\ \\____| | ||
"""; | ||
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. Nice. I wouldn't be able to create that and adds character to the bot |
||
Scanner scanner = new Scanner(System.in); | ||
Kafka kafka = new Kafka(); | ||
boolean isExitChat = false; | ||
|
||
System.out.println(" Hello from\n" + logo); | ||
kafka.greet(); | ||
System.out.println(" What do you need me for?"); | ||
while (!isExitChat) { | ||
String[] userInput = scanner.nextLine().trim().split(" ", 2); | ||
try { | ||
if (userInput[0] == null) { | ||
continue; | ||
} | ||
if (userInput[0].equalsIgnoreCase("bye")) { | ||
isExitChat = true; | ||
} else if (userInput[0].equalsIgnoreCase("list")) { | ||
kafka.createList(); | ||
} else if (userInput[0].equalsIgnoreCase("mark")) { | ||
int taskNumber = Integer.parseInt(userInput[1]); | ||
kafka.mark(taskNumber); | ||
} else if (userInput[0].equalsIgnoreCase("unmark")) { | ||
int taskNumber = Integer.parseInt(userInput[1]); | ||
kafka.unmark(taskNumber); | ||
} else if (userInput[0].equalsIgnoreCase("delete")) { | ||
int taskNumber = Integer.parseInt(userInput[1]); | ||
kafka.delete(taskNumber); | ||
} else { | ||
if (userInput[0].equalsIgnoreCase("todo")) { | ||
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. Nested if statements are not as easy to read. Is it possible to just add more elif to handle the add task cases instead of nesting them in the else block? |
||
if (userInput.length < 2) { | ||
throw new KafkaException("It seems you've left the details blank. Even the simplest tasks need some direction, don't you think?"); | ||
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. Exception message is quite long and used repeatedly. Maybe store the message as a String variable? Or write a function to throw a new exception? |
||
} | ||
Task todo = new Todo(userInput[1]); | ||
kafka.addTask(todo); | ||
} else if (userInput[0].equalsIgnoreCase("deadline")) { | ||
if (userInput.length < 2) { | ||
throw new KafkaException("It seems you've left the details blank. Even the simplest tasks need some direction, don't you think?"); | ||
} | ||
String[] deadlineSplit = userInput[1].split("/by"); | ||
if (deadlineSplit.length < 2) { | ||
throw new KafkaException("It appears the details for this deadline task are off. Let's give it another go, shall we?"); | ||
} | ||
Task deadline = new Deadline(deadlineSplit[0], deadlineSplit[1]); | ||
kafka.addTask(deadline); | ||
} else if (userInput[0].equalsIgnoreCase("event")) { | ||
if (userInput.length < 2) { | ||
throw new KafkaException("It seems you've left the details blank. Even the simplest tasks need some direction, don't you think?"); | ||
} | ||
String[] eventSplit = userInput[1].split("/from|/to"); | ||
if (eventSplit.length < 3) { | ||
throw new KafkaException("It appears the details for this event task are off. Let's give it another go, shall we?"); | ||
} | ||
Task event = new Event(eventSplit[0], eventSplit[1], eventSplit[2]); | ||
kafka.addTask(event); | ||
} else { | ||
throw new KafkaException("Hmm... I'm not sure what you're getting at. Care to enlighten me?"); | ||
} | ||
} | ||
} catch (KafkaException e) { | ||
System.out.println(" " + e.getMessage()); | ||
} | ||
} | ||
kafka.goodbye(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public class KafkaException extends Exception { | ||
public KafkaException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (this.isDone ? "X" : " "); | ||
} | ||
|
||
public void markAsDone() { | ||
if (this.isDone) { | ||
return; | ||
} | ||
this.isDone = true; | ||
} | ||
|
||
public void markAsNotDone() { | ||
if (!this.isDone) { | ||
return; | ||
} | ||
this.isDone = false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + this.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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,67 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
Hello from | ||
__ __ __ _ | ||
| |/ / ____ _/ /_ | | ____ | ||
| / / _ | |_ _| | |/ / / _ | | ||
| \ | |_| | | | | < | |_| | | ||
|__|\__\ \____| |__| |_|\ \ \____| | ||
|
||
Hello. Kafka here. | ||
We meet again. | ||
|
||
What do you need me for? | ||
Got it. I've added this task. | ||
[T][ ] read book | ||
Now you have 1 task(s) in the list. | ||
Got it. I've added this task. | ||
[T][ ] return book | ||
Now you have 2 task(s) in the list. | ||
Got it. I've added this task. | ||
[D][ ] finish CS2103T assignments (by: Friday 4pm) | ||
Now you have 3 task(s) in the list. | ||
Got it. I've added this task. | ||
[D][ ] do ST2334 notes (by: Sunday) | ||
Now you have 4 task(s) in the list. | ||
Got it. I've added this task. | ||
[E][ ] welcome tea (from: Monday 7pm to: 9pm) | ||
Now you have 5 task(s) in the list. | ||
Got it. I've added this task. | ||
[E][ ] meeting (from: Wednesday 11pm to: Thursday 12am) | ||
Now you have 6 task(s) in the list. | ||
Here are the tasks in your list: | ||
1.[T][ ] read book | ||
2.[T][ ] return book | ||
3.[D][ ] finish CS2103T assignments (by: Friday 4pm) | ||
4.[D][ ] do ST2334 notes (by: Sunday) | ||
5.[E][ ] welcome tea (from: Monday 7pm to: 9pm) | ||
6.[E][ ] meeting (from: Wednesday 11pm to: Thursday 12am) | ||
Good work on this task. Want a prize?: | ||
[T][X] read book | ||
Good work on this task. Want a prize?: | ||
[D][X] do ST2334 notes (by: Sunday) | ||
Here are the tasks in your list: | ||
1.[T][X] read book | ||
2.[T][ ] return book | ||
3.[D][ ] finish CS2103T assignments (by: Friday 4pm) | ||
4.[D][X] do ST2334 notes (by: Sunday) | ||
5.[E][ ] welcome tea (from: Monday 7pm to: 9pm) | ||
6.[E][ ] meeting (from: Wednesday 11pm to: Thursday 12am) | ||
Hurry up. This task is necessary for Elio's script: | ||
[D][ ] do ST2334 notes (by: Sunday) | ||
Here are the tasks in your list: | ||
1.[T][X] read book | ||
2.[T][ ] return book | ||
3.[D][ ] finish CS2103T assignments (by: Friday 4pm) | ||
4.[D][ ] do ST2334 notes (by: Sunday) | ||
5.[E][ ] welcome tea (from: Monday 7pm to: 9pm) | ||
6.[E][ ] meeting (from: Wednesday 11pm to: Thursday 12am) | ||
Hmm... I'm not sure what you're getting at. Care to enlighten me? | ||
I've removed this task: | ||
[E][ ] meeting (from: Wednesday 11pm to: Thursday 12am) | ||
Now you have 5 task(s) in the list. | ||
Here are the tasks in your list: | ||
1.[T][X] read book | ||
2.[T][ ] return book | ||
3.[D][ ] finish CS2103T assignments (by: Friday 4pm) | ||
4.[D][ ] do ST2334 notes (by: Sunday) | ||
5.[E][ ] welcome tea (from: Monday 7pm to: 9pm) | ||
Farewell. I look forward to our next meeting, wherever destiny may lead us. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
todo read book | ||
todo return book | ||
deadline finish CS2103T assignments /by Friday 4pm | ||
deadline do ST2334 notes /by Sunday | ||
event welcome tea /from Monday 7pm /to 9pm | ||
event meeting /from Wednesday 11pm /to Thursday 12am | ||
list | ||
mark 1 | ||
mark 4 | ||
list | ||
unmark 4 | ||
list | ||
remove 6 | ||
delete 6 | ||
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.
I don't see the protected access modifier often. Quite curious about the reason