Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
1c58c46
Greet, Echo, Exit
HanJiyao Jan 19, 2022
c9eb14c
Add, List
HanJiyao Jan 19, 2022
155a643
Mark as Done
HanJiyao Jan 19, 2022
4957053
ToDos, Events, Deadlines
HanJiyao Jan 19, 2022
f2253e1
Automated Text UI Testing
HanJiyao Jan 19, 2022
3838a18
Handle Errors
HanJiyao Jan 19, 2022
b597f58
Delete
HanJiyao Jan 19, 2022
487f743
Use Enums
HanJiyao Jan 19, 2022
56225e7
Configure workflow
HanJiyao Feb 1, 2022
48e2f6d
Save
HanJiyao Feb 4, 2022
4d1eb80
Dates and Times
HanJiyao Feb 4, 2022
7091195
Merge Dates and Times
HanJiyao Feb 4, 2022
8b9cda8
Mark correction
HanJiyao Feb 4, 2022
2e9dc51
Use More OOP
HanJiyao Feb 4, 2022
1c8552d
Organize into Packages
HanJiyao Feb 4, 2022
f5a3b70
Merge remote-tracking branch 'origin/add-gradle-support'
HanJiyao Feb 4, 2022
eff6e71
Create New Gradle and put in source
HanJiyao Feb 4, 2022
6d47139
Merge branch 'branch-A-Gradle'
HanJiyao Feb 4, 2022
c56753c
Add JUnit Tests
HanJiyao Feb 4, 2022
08c07f8
Create a JAR File
HanJiyao Feb 4, 2022
dce93d4
Find
HanJiyao Feb 4, 2022
81fc655
Add JavaDoc comments
HanJiyao Feb 4, 2022
101e5d5
Tweak the code to comply with a coding standard
HanJiyao Feb 4, 2022
434b8e2
Merge branch 'branch-A-CodingStandard'
HanJiyao Feb 4, 2022
4bdbade
Merge branch 'branch-Level-9'
HanJiyao Feb 4, 2022
d10fbdf
Use CheckStyle
HanJiyao Feb 4, 2022
5049a11
update find
HanJiyao Feb 5, 2022
b101cee
Update find
HanJiyao Feb 5, 2022
6597d68
Merge remote-tracking branch 'origin/branch-Level-9' into branch-Level-9
HanJiyao Feb 5, 2022
950a50a
GUI
HanJiyao Feb 6, 2022
4b1d394
GUI FXML and css
HanJiyao Feb 10, 2022
eb80f8f
Use Varargs
HanJiyao Feb 10, 2022
b267473
Duke class: remove unused textUI()
HanJiyao Feb 10, 2022
47ca398
Add assertion
HanJiyao Feb 10, 2022
2421531
Improve code quality
HanJiyao Feb 10, 2022
563adc5
Merge pull request #1 from HanJiyao/branch-A-CodeQuality
HanJiyao Feb 10, 2022
a5c14ef
Merge branch 'master' into branch-A-Assertions
HanJiyao Feb 10, 2022
be2f68d
Merge pull request #2 from HanJiyao/branch-A-Assertions
HanJiyao Feb 10, 2022
b56632e
Resolve name error by merging
HanJiyao Feb 10, 2022
29c34e9
Clear up more code quality
HanJiyao Feb 11, 2022
040bf3d
Change exit behavior
HanJiyao Feb 11, 2022
0524042
Import checkstyle config
HanJiyao Feb 11, 2022
6c19c88
Improve code quality change header comments and variable name
HanJiyao Feb 11, 2022
807c50c
Use Streams
HanJiyao Feb 11, 2022
f358128
Set up CI
HanJiyao Feb 11, 2022
d737951
Set up CI
HanJiyao Feb 11, 2022
77b7f78
Provide a way to attach priorities to items
HanJiyao Feb 12, 2022
e29df41
Sort items managed by app
HanJiyao Feb 12, 2022
dd5f585
Modify runtest
HanJiyao Jan 22, 2037
34d91f6
Modify ui-test
HanJiyao Jan 22, 2022
e3dbb49
Merge pull request #4 from HanJiyao/branch-C-PrioritySort
HanJiyao Feb 12, 2022
ed249d5
Merge pull request #4 from HanJiyao/branch-C-PrioritySort
HanJiyao Feb 3, 2022
dbfdf37
Merge remote-tracking branch 'origin/master'
HanJiyao Feb 3, 2022
2126abb
Trail commitO
HanJiyao Jan 24, 2022
6cf8715
Clear up format
HanJiyao Feb 13, 2022
c55e9a3
Create gradle.yml
HanJiyao Feb 13, 2022
c2b7e71
Edit runtest
HanJiyao Feb 13, 2022
dff2e82
Merge remote-tracking branch 'origin/master'
HanJiyao Feb 13, 2022
11f3ceb
Remove text-ui-test as no longer needed
HanJiyao Feb 13, 2022
deba367
Better GUI
HanJiyao Feb 13, 2022
dc4be77
Add a User Guide
HanJiyao Feb 13, 2022
48c91bf
Bug fix date parser
HanJiyao Feb 13, 2022
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
26 changes: 26 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class Deadline extends Task{
protected String by;
public Deadline(String task, String by) {
super(task.trim());
this.by = by.trim();
}

public Deadline(String task, boolean done) {
super(task, done);
}

@Override
public Deadline mark() {
return new Deadline(task, true);
}

@Override
public Deadline unmark() {
return new Deadline(task, false);
}

@Override
public String toString() {
return "["+Type.D+"]" + super.toString() + " (by: " + by + ")";
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done on the naming of variables, they are easily read!

}
140 changes: 138 additions & 2 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,146 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
+ "|____/ \\__,_|_|\\_\\___|";
System.out.println(logo);

System.out.println(output("Hello! I'm Duke by A0221330A.\n What can I do for you?"));

ArrayList<Task> list = new ArrayList<>();

boolean exit = false;
while (!exit) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextLine()) {
List<String> input = Arrays.asList(sc.nextLine().split(" "));
switch (input.get(0)) {
case "bye":
System.out.println(output("Bye. Hope to see you again soon!"));
exit = true;
break;
case "list":
StringBuilder text = new StringBuilder();
text.append("Here are the tasks in your list:\n");
for (int i = 0; i < list.size(); i++) {
text.append(" ").append(i + 1).append(". ")
.append(list.get(i))
.append("\n");
}
text.delete(text.length() - 1, text.length());
System.out.println(output(text.toString()));
break;
case "mark":
try {
int markIndex = Integer.parseInt(input.get(1)) - 1;
list.set(markIndex, list.get(markIndex).mark());
System.out.println(output("Nice! I've marked this task as done:\n "
+ list.get(markIndex)));
} catch (IndexOutOfBoundsException | NumberFormatException ex) {
DukeException exception = new DukeException("☹ OOPS!!! invalid index.");
System.out.println(output(exception.toString()));
}
break;
case "unmark":
try {
int unmarkIndex = Integer.parseInt(input.get(1)) - 1;
list.set(unmarkIndex, list.get(unmarkIndex).unmark());
System.out.println(output("OK, I've marked this task as not done yet:\n "
+ list.get(unmarkIndex)));
} catch (IndexOutOfBoundsException | NumberFormatException ex) {
DukeException exception = new DukeException("☹ OOPS!!! invalid index.");
System.out.println(output(exception.toString()));
}
break;
case "todo":
StringBuilder todo = new StringBuilder();
if (input.size() == 1) {
DukeException exception = new DukeException("☹ OOPS!!! The description of a todo cannot be empty.");
System.out.println(output(exception.toString()));
} else {
for (int i = 1; i < input.size(); i++) {
todo.append(input.get(i)).append(" ");
}
list.add(new ToDo(todo.toString()));
System.out.println(output("Got it. I've added this task: \n "
+ list.get(list.size() - 1) + "\n Now you have " + list.size() + " tasks in the list."));
}
break;

case "deadline":
StringBuilder deadline = new StringBuilder();
StringBuilder deadlineBy = new StringBuilder();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe can encapsulate this functionality in another class if you want

int byIndex = input.indexOf("/by");
if (input.size() == 1) {
DukeException exception = new DukeException("☹ OOPS!!! The description of a deadline cannot be empty.");
System.out.println(output(exception.toString()));
} else if (byIndex == -1) {
DukeException exception = new DukeException("☹ OOPS!!! The datetime of a deadline cannot be empty.");
System.out.println(output(exception.toString()));
} else {
for (int i = 1; i < byIndex; i++) {
deadline.append(input.get(i)).append(" ");
}
for (int i = byIndex + 1; i < input.size(); i++) {
deadlineBy.append(input.get(i)).append(" ");
}
list.add(new Deadline(deadline.toString(), deadlineBy.toString()));
System.out.println(output("Got it. I've added this task: \n "
+ list.get(list.size() - 1) + "\n Now you have " + list.size() + " tasks in the list."));
}
break;
case "event":
int atIndex = input.indexOf("/at");
if (input.size() == 1) {
DukeException exception = new DukeException("☹ OOPS!!! The description of a event cannot be empty.");
System.out.println(output(exception.toString()));
} else if (atIndex == -1) {
DukeException exception = new DukeException("☹ OOPS!!! The datetime of a event cannot be empty.");
System.out.println(output(exception.toString()));
} else {
StringBuilder event = new StringBuilder();
for (int i = 1; i < atIndex; i++) {
event.append(input.get(i)).append(" ");
}
StringBuilder eventAt = new StringBuilder();
for (int i = atIndex + 1; i < input.size(); i++) {
eventAt.append(input.get(i)).append(" ");
}
list.add(new Event(event.toString(), eventAt.toString()));
System.out.println(output("Got it. I've added this task: \n "
+ list.get(list.size() - 1) + "\n Now you have " + list.size() + " tasks in the list."));
}
break;
case "delete":
try {
int deleteIndex = Integer.parseInt(input.get(1)) - 1;
Task delete = list.get(deleteIndex);
list.remove(deleteIndex);
System.out.println(output("Noted. I've removed this task: \n "
+ delete + "\n Now you have " + list.size() + " tasks in the list."));
} catch (IndexOutOfBoundsException | NumberFormatException ex) {
DukeException exception = new DukeException("☹ OOPS!!! invalid index.");
System.out.println(output(exception.toString()));
}
break;
default:
DukeException exception = new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
System.out.println(output(exception.toString()));
break;
}
}
}
}

public static String output(String text) {
String line = " ____________________________________________________________";
return line + "\n " + text + "\n" + line;
}
}
10 changes: 10 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class DukeException extends Exception {
public DukeException(String errMsg) {
super(errMsg);
}

@Override
public String toString() {
return super.getMessage();
}
}
26 changes: 26 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class Event extends Task{
protected String at;
public Event(String task, String at) {
super(task.trim());
this.at = at.trim();
}

public Event(String task, boolean done) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Easy to read!

super(task, done);
}

@Override
public Event mark() {
return new Event(task, true);
}

@Override
public Event unmark() {
return new Event(task, false);
}

@Override
public String toString() {
return "["+Type.E+"]" + super.toString() + " (at: " + at + ")";
}
}
27 changes: 27 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class Task {
protected String task;
protected boolean done;

public Task(String task) {
this.task = task;
this.done = false;
}

public Task(String task, boolean done) {
this.task = task;
this.done = done;
}

public Task mark() {
return new Task(task, true);
}

public Task unmark() {
return new Task(task, false);
}

@Override
public String toString() {
return done? "[✓] " + task: "[ ] " + task;
}
}
24 changes: 24 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class ToDo extends Task{
public ToDo(String task) {
super(task.trim());
}

public ToDo(String task, boolean done) {
super(task, done);
}

@Override
public ToDo mark() {
return new ToDo(task, true);
}

@Override
public ToDo unmark() {
return new ToDo(task, false);
}

@Override
public String toString() {
return "["+Type.T+"]" + super.toString();
}
}
3 changes: 3 additions & 0 deletions src/main/java/Type.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public enum Type {
T, D, E
}
64 changes: 60 additions & 4 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,63 @@
Hello from
____ _
| _ \ _ _| | _____
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

____________________________________________________________
Hello! I'm Duke by A0221330A.
What can I do for you?
____________________________________________________________
____________________________________________________________
Got it. I've added this task:
[T][ ] read book
Now you have 1 tasks in the list.
____________________________________________________________
____________________________________________________________
Got it. I've added this task:
[D][ ] return book (by: June 6th)
Now you have 2 tasks in the list.
____________________________________________________________
____________________________________________________________
Got it. I've added this task:
[E][ ] project meeting (at: Aug 6th 2-4pm)
Now you have 3 tasks in the list.
____________________________________________________________
____________________________________________________________
Got it. I've added this task:
[T][ ] join sports club
Now you have 4 tasks in the list.
____________________________________________________________
____________________________________________________________
Nice! I've marked this task as done:
[T][✓] read book
____________________________________________________________
____________________________________________________________
Nice! I've marked this task as done:
[T][✓] join sports club
____________________________________________________________
____________________________________________________________
Got it. I've added this task:
[T][ ] borrow book
Now you have 5 tasks in the list.
____________________________________________________________
____________________________________________________________
Here are the tasks in your list:
1. [T][✓] read book
2. [D][ ] return book (by: June 6th)
3. [E][ ] project meeting (at: Aug 6th 2-4pm)
4. [T][✓] join sports club
5. [T][ ] borrow book
____________________________________________________________
____________________________________________________________
Got it. I've added this task:
[D][ ] return book (by: Sunday)
Now you have 6 tasks in the list.
____________________________________________________________
____________________________________________________________
Got it. I've added this task:
[E][ ] project meeting (at: Mon 2-4 pm)
Now you have 7 tasks in the list.
____________________________________________________________
____________________________________________________________
Bye. Hope to see you again soon!
____________________________________________________________
11 changes: 11 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
todo read book
deadline return book /by June 6th
event project meeting /at Aug 6th 2-4pm
todo join sports club
mark 1
mark 4
todo borrow book
list
deadline return book /by Sunday
event project meeting /at Mon 2-4 pm
bye