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

[Lik Hern] iP #488

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
f0c4e56
Add the ability to greet user, echo user input and exit program
Aug 20, 2022
4f8f316
Add the ability to store text and display to user when requested
Aug 20, 2022
f66f01b
Add the ability to mark/unmark tasks as done/not done yet
Aug 20, 2022
744d458
Add support for tracking three types of tasks: ToDos, Deadlines & Events
Aug 20, 2022
2da77c5
Set up automated text UI testing
Aug 20, 2022
324e1b1
Add the ability to handle certain exceptions
Aug 20, 2022
90aead3
Add support for deleting tasks from the list
Aug 20, 2022
c56dde6
Add the ability to save and load data from the hard disk
Sep 2, 2022
89d2bfb
Add the ability to identify certain date format and parse it correctly
Sep 2, 2022
4cd6136
Merge branch 'branch-Level-7'
Sep 2, 2022
51cda61
Merge branch 'branch-Level-8'
Sep 2, 2022
a200367
Arrange the code to more closely follow OOP design
Sep 4, 2022
634c9e6
Organize the classes into suitable java packages
Sep 9, 2022
399a384
Merge branch 'add-gradle-support' of https://github.com/nus-cs2103-AY…
Sep 9, 2022
f8ae081
Add Gradle support to the project
Sep 9, 2022
e1538fb
Add JUnit tests to test the behavior of the code
Sep 9, 2022
4e9edd6
Add JavaDoc comments to the code
Sep 9, 2022
abc6e72
Tweak the code to comply with a coding standard
Sep 9, 2022
120db3d
Add support for finding a task in task list by searching for a keyword
Sep 10, 2022
a97d88e
Merge branch 'branch-A-JavaDoc'
Sep 10, 2022
ead284b
Merge branch 'branch-A-CodingStandard'
Sep 10, 2022
ba7937c
Merge branch 'branch-Level-9'
Sep 10, 2022
050cef3
Add a GUI to Duke
Sep 12, 2022
d13c5bf
Merge branch 'branch-Level-10'
Sep 12, 2022
2bb32f4
Fixed minor problem related to GUI
Sep 12, 2022
cbb027c
Include assertions to verify certain assumptions
Sep 12, 2022
e75560b
Do refactor to improve code quality
Sep 12, 2022
cccbaca
Merge pull request #2 from LikHern/branch-A-Assertions
LikHern Sep 12, 2022
0921acb
Merge branch 'master' into branch-A-CodeQuality
Sep 12, 2022
859ae32
Merge pull request #3 from LikHern/branch-A-CodeQuality
LikHern Sep 12, 2022
5e6b548
Add support for archiving items
Sep 12, 2022
405f354
Add a User Guide to the project
Sep 13, 2022
7658174
Update README.md
LikHern Sep 13, 2022
b49dcb9
Update README.md
LikHern Sep 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
13 changes: 13 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Deadline extends Task {
protected String by;

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

@Override
public String toString() {
return String.format("[D]%s (by: %s)", super.toString(), by);
}
}
83 changes: 77 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,81 @@
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
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);
List<Task> storage = new ArrayList<>();
System.out.println("Hello! I'm Duke\nWhat can I do for you?");
Scanner scanner = new Scanner(System.in);
UserInput: while (scanner.hasNextLine()) {
UserCommand command;
try {
command = UserCommand.valueOf(scanner.next().toUpperCase());
} catch (IllegalArgumentException e) {
System.out.println("OOPS!!! I'm sorry, but I don't know what that means:-(");
scanner.nextLine();
continue;
}
switch (command) {
case TODO:
String toDoDescription = scanner.nextLine().strip();
if (toDoDescription.isBlank()) {
System.out.println("OOPS!!! The description of a todo cannot be empty.");
continue;
}
ToDo toDoTask = new ToDo(toDoDescription);
storage.add(toDoTask);
System.out.println("Got it. I've added this task:\n" + toDoTask
+ "\nNow you have " + storage.size() + " tasks in your list.");
break;
case DEADLINE:
scanner.useDelimiter("/by");
String deadlineDescription = scanner.next().strip();
scanner.reset().skip("/by");
String deadlineBy = scanner.nextLine().strip();
Deadline deadlineTask = new Deadline(deadlineDescription, deadlineBy);
storage.add(deadlineTask);
System.out.println("Got it. I've added this task:\n" + deadlineTask
+ "\nNow you have " + storage.size() + " tasks in the list.");
break;
case EVENT:
scanner.useDelimiter("/at");
String eventDescription = scanner.next().strip();
scanner.reset().skip("/at");
String eventAt = scanner.nextLine().strip();
Event eventTask = new Event(eventDescription, eventAt);
storage.add(eventTask);
System.out.println("Got it. I've added this task:\n" + eventTask
+ "\nNow you have " + storage.size() + " tasks in the list.");
break;

Choose a reason for hiding this comment

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

Code seems to repeat the concept of finding some delimiter, perhaps this can be abstracted?

case LIST:
System.out.println("Here are the tasks in your list:");
ListIterator<Task> listIterator = storage.listIterator();
while (listIterator.hasNext()) {
System.out.println(listIterator.nextIndex() + 1 + "." + listIterator.next());
}
break;
case MARK:
int markIndex = scanner.nextInt();
storage.get(markIndex - 1).markAsDone();
break;
case UNMARK:
int unmarkIndex = scanner.nextInt();
storage.get(unmarkIndex - 1).markAsUndone();
break;
case DELETE:
int deleteIndex = scanner.nextInt();
Task deletedTask = storage.get(deleteIndex - 1);
storage.remove(deletedTask);
System.out.println("Noted. I've removed this task:\n" + deletedTask
+ "\nNow you have " + storage.size() + " tasks in the list.");
break;
case BYE:
System.out.println("Bye. Hope to see you again soon!");
break UserInput;
Copy link

Choose a reason for hiding this comment

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

Interesting use of Java labels!

}
}
scanner.close();
}
}
13 changes: 13 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Event extends Task {
protected String at;
Copy link

Choose a reason for hiding this comment

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

Just like the Deadline class, perhaps you can change the variable name from "at" to "eventTime"?


Event(String description, String at) {
super(description);
this.at = at;
}

@Override
Copy link

Choose a reason for hiding this comment

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

Can write java docs

public String toString() {
return String.format("[E]%s (at: %s)", super.toString(), at);
}
}
36 changes: 36 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
public class Task {
protected String description;
protected boolean isDone;

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

Choose a reason for hiding this comment

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

Coding standard suggests avoiding unnecessary use of this with fields. (isDone here, in particular.)
https://se-education.org/guides/conventions/java/index.html#variables

}

private String getStatusIcon() {
return (isDone ? "X" : " ");
}

public void markAsDone() {
Copy link

Choose a reason for hiding this comment

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

Can write java docs

if (isDone) {
System.out.println("This task is already marked as done!");
} else {
this.isDone = true;
System.out.println("Nice! I've marked this task as done:\n" + this);
}
}

public void markAsUndone() {
if (!isDone) {
System.out.println("This task is already marked as not done yet!");
} else {
this.isDone = false;
System.out.println("OK, I've marked this task as not done yet:\n" + this);
}
}

@Override
public String toString() {
return String.format("[%s] %s", getStatusIcon(), description);
}
}
10 changes: 10 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class ToDo extends Task {
ToDo(String description) {
super(description);
}

@Override
public String toString() {
return String.format("[T]%s", super.toString());
}
}
3 changes: 3 additions & 0 deletions src/main/java/UserCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public enum UserCommand {
TODO, DEADLINE, EVENT, LIST, MARK, UNMARK, DELETE, BYE
}
30 changes: 23 additions & 7 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

Hello! I'm Duke
What can I do for you?
Got it. I've added this task:
[T][ ] read book
Now you have 1 tasks in your list.
Got it. I've added this task:
[D][ ] return book (by: June 6th)
Now you have 2 tasks in your list.
Got it. I've added this task:
[E][ ] project meeting (at: Aug 6th 2-4pm)
Now you have 3 tasks in your list.
Nice! I've marked this task as done:
[T][X] read book
This task is already marked as done!
Nice! I've marked this task as done:
[D][X] return book (by: June 6th)
OK, I've marked this task as not done yet:
[D][ ] return book (by: June 6th)
This task is already marked as not done yet!
Here are the tasks in your list:
1.[T][X] read book
2.[D][ ] return book (by: June 6th)
3.[E][ ] project meeting (at: Aug 6th 2-4pm)
9 changes: 9 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
todo read book
deadline return book /by June 6th
event project meeting /at Aug 6th 2-4pm
mark 1
mark 1
mark 2
unmark 2
unmark 2
list