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

[Nicholascyx] ip #625

Open
wants to merge 56 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
68c58c1
Add Gradle support
May 24, 2020
03523ec
Bump gradle and lib version
Eclipse-Dominator Aug 5, 2023
81a9c53
build.gradle: Prevent generating a second JAR file
aureliony Jul 16, 2024
459380b
Added Kafka.java, Added greet and exit message
Nicholascyx Aug 26, 2024
5a9e282
Added support for echo
Nicholascyx Aug 26, 2024
b4bbf71
Added support for add and list function, added indentations
Nicholascyx Aug 28, 2024
e134e90
Added new method for list
Nicholascyx Aug 28, 2024
c8593dd
Used ArrayList to store tasks
Nicholascyx Aug 28, 2024
8b32bad
Added [] for tasks and markAsDone() function
Nicholascyx Aug 28, 2024
eccb99a
Added support for Mark As Done
Nicholascyx Aug 28, 2024
2792677
Added Deadline, Event and Todo
Nicholascyx Aug 28, 2024
9377e1d
Added support for different events
Nicholascyx Aug 28, 2024
bbf800e
Added support for exceptions
Nicholascyx Aug 29, 2024
7a84450
Added support for delete
Nicholascyx Aug 29, 2024
246d624
Added support for text-ui-test
Nicholascyx Aug 30, 2024
2527e8c
Add changes for text-ui-test
Nicholascyx Sep 2, 2024
efa2a78
Add support for saving tasks
Nicholascyx Sep 4, 2024
d2e9b4e
Add a create new file function
Nicholascyx Sep 4, 2024
30ccaeb
Add improvements for KafkaTextWriter
Nicholascyx Sep 4, 2024
6d9bfa9
Add support for loading tasks
Nicholascyx Sep 4, 2024
ac0f46e
Add datetime recogniton for deadlines
Nicholascyx Sep 4, 2024
a556a31
Add datetime recognition for events
Nicholascyx Sep 4, 2024
32b6215
Add UI class functions
Nicholascyx Sep 5, 2024
4c7c84d
Add Storage class functions
Nicholascyx Sep 5, 2024
58d631d
Add Parser class and TaskList class functions
Nicholascyx Sep 5, 2024
b28d0cb
Add all the classes into a package
Nicholascyx Sep 6, 2024
c2a4109
Merge branch 'add-gradle-support' of https://github.com/Nicholascyx/ip
Nicholascyx Sep 6, 2024
00907a3
Add gradle into project
Nicholascyx Sep 6, 2024
67cb1a1
Add JUnit tests
Nicholascyx Sep 6, 2024
31ee68b
Improve JUnit test for TaskListTest
Nicholascyx Sep 6, 2024
fd6d300
Add Jar file
Nicholascyx Sep 6, 2024
58a71df
Add JavaDoc comments
Nicholascyx Sep 6, 2024
0b4ccdb
Add Coding Standard changes
Nicholascyx Sep 6, 2024
440f471
Add find function for the tasks
Nicholascyx Sep 12, 2024
294c546
Merge branch 'branch-A-JavaDoc'
Nicholascyx Sep 12, 2024
d5b379b
Merge branch 'branch-Level-9'
Nicholascyx Sep 12, 2024
e090307
Add JavaDoc comments for find functions and resolve conflicts
Nicholascyx Sep 12, 2024
d8bddd1
Add support for GUI
Nicholascyx Sep 20, 2024
7e36021
Add more support for GUI
Nicholascyx Sep 20, 2024
b080878
Add some code quality changes
Nicholascyx Sep 21, 2024
b35dcac
Add some additional changes for parser command
Nicholascyx Sep 21, 2024
edd7146
Add assertions
Nicholascyx Sep 21, 2024
0303a46
Change more codequality relevant stuff
Nicholascyx Sep 22, 2024
16a76a5
Add small adjustments to throw IOException
Nicholascyx Sep 22, 2024
80768a8
Merge pull request #2 from Nicholascyx/branch-A-Assertions
Nicholascyx Sep 22, 2024
2c9400f
Merge branch 'master' into branch-A-CodeQuality
Nicholascyx Sep 22, 2024
ba37625
Revert "Merge branch 'master' into branch-A-CodeQuality"
Nicholascyx Sep 22, 2024
015627c
Merge pull request #3 from Nicholascyx/branch-A-CodeQuality
Nicholascyx Sep 22, 2024
283b4e4
Add more JavaDocs
Nicholascyx Sep 22, 2024
94e7c8f
Add snooze function
Nicholascyx Sep 23, 2024
0c71886
Add support for assertions
Nicholascyx Sep 23, 2024
1898269
Merge branch 'branch-B-Snooze'
Nicholascyx Sep 23, 2024
42d6385
Update the filepath
Nicholascyx Sep 23, 2024
c9ce769
Create jar file
Nicholascyx Sep 23, 2024
13e20f2
Add Readme
Nicholascyx Sep 23, 2024
d7e2b2f
Update README.md
Nicholascyx Sep 23, 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
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 {

protected String by;

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

@Override
public String toString() {
return "[D]" + super.toString() + "(by:" + by + ")";
}
}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

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

protected String from;
Copy link

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

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 + ")";
}
}
136 changes: 136 additions & 0 deletions src/main/java/Kafka.java
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() {
Copy link

Choose a reason for hiding this comment

The 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 = """
__ __ __ _
| |/ / ____ _/ /_ | | ____
| / / _ | |_ _| | |/ / / _ |
| \\ | |_| | | | | < | |_| |
|__|\\__\\ \\____| |__| |_|\\ \\ \\____|
""";
Copy link

Choose a reason for hiding this comment

The 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")) {
Copy link

Choose a reason for hiding this comment

The 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?");
Copy link

Choose a reason for hiding this comment

The 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();
}
}
5 changes: 5 additions & 0 deletions src/main/java/KafkaException.java
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);
}
}
32 changes: 32 additions & 0 deletions src/main/java/Task.java
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;
}
}
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();
}
}
72 changes: 66 additions & 6 deletions text-ui-test/EXPECTED.TXT
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.
16 changes: 16 additions & 0 deletions text-ui-test/input.txt
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
2 changes: 1 addition & 1 deletion text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 (
REM no error here, errorlevel == 0

REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT
java -classpath ..\bin Duke < input.txt > ACTUAL.TXT
java -classpath ..\bin Kafka < input.txt > ACTUAL.TXT

REM compare the output to the expected output
FC ACTUAL.TXT EXPECTED.TXT
2 changes: 1 addition & 1 deletion text-ui-test/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ then
fi

# run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT
java -classpath ../bin Duke < input.txt > ACTUAL.TXT
java -classpath ../bin Kafka < input.txt > ACTUAL.TXT

# convert to UNIX format
cp EXPECTED.TXT EXPECTED-UNIX.TXT
Expand Down