-
Notifications
You must be signed in to change notification settings - Fork 461
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
[Nathaniel Lukas] iP #477
base: master
Are you sure you want to change the base?
[Nathaniel Lukas] iP #477
Conversation
…changes. Load the data from the hard disk when the project starts up.
…bjects. Accept dates in yyyy-mm-dd format and print in MMM dd yyyy format
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.
Overall, I found the code easy to follow. The coding standard was consistent with only a few nits that might need fixing. Descriptive headers for public classes and methods could be included to allow for better documentation.
src/main/java/Task.java
Outdated
isDone = false; | ||
} | ||
|
||
public String data() { |
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.
Perhaps the name for the method could be change to one that starts with a verb like convertToData
?
src/main/java/Task.java
Outdated
@@ -0,0 +1,32 @@ | |||
public class Task { |
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.
Perhaps this Task
class and it's derived class could be put into a single package?
src/main/java/Task.java
Outdated
type = 'T'; | ||
} | ||
|
||
public String getStatusIcon() { |
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.
Maybe you can add some method headers for the public methods?
src/main/java/Duke.java
Outdated
System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
} else if (s.equals("deadline")) { | ||
String rest = sc.nextLine(); | ||
String[] split = rest.split("/"); |
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.
Considering that the split
is an array of strings, perhaps it could named using the plural convention? Another way to name it could be tokens
which might be more informative?
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.
Code employed is sufficient to pass muster for Level 7/8, but better design choices need to be applied for later levels. I assume you're busy with other commitments at the moment, in which case all the best.
Jiayous.
src/main/java/Duke.java
Outdated
if (s.equals("bye")) { | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
break; | ||
} else if (s.equals("list")) { | ||
System.out.println("Here are the tasks in your list:"); | ||
for (int a = 0; a < tasks.size(); a++) { | ||
System.out.println((a + 1) + "." + tasks.get(a)); | ||
} | ||
sc.nextLine(); | ||
} else if (s.equals("mark")) { | ||
int index = sc.nextInt() - 1; | ||
if (index >= tasks.size()) { | ||
throw new DukeException("Index out of bound!"); | ||
} | ||
tasks.get(index).markAsDone(); | ||
System.out.println("Nice! I've marked this task as done:"); | ||
System.out.println(tasks.get(index)); | ||
sc.nextLine(); | ||
} else if (s.equals("unmark")) { | ||
int index = sc.nextInt() - 1; | ||
if (index >= tasks.size()) { | ||
throw new DukeException("Index out of bound!"); | ||
} | ||
tasks.get(index).markNotDone(); | ||
System.out.println("OK, I've marked this task as not done yet:"); | ||
System.out.println(tasks.get(index)); | ||
sc.nextLine(); | ||
} else if (s.equals("todo")) { | ||
String task = sc.nextLine(); | ||
if (task.trim().isEmpty()) { | ||
throw new DukeException("☹ OOPS!!! The description of a todo cannot be empty."); | ||
} | ||
tasks.add(new Task(task)); | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(tasks.get(tasks.size() - 1)); | ||
System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
} else if (s.equals("deadline")) { | ||
String rest = sc.nextLine(); | ||
String[] split = rest.split("/"); | ||
String task = split[0]; | ||
String deadline = split[1]; | ||
deadline = deadline.substring(deadline.indexOf(' ') + 1); | ||
tasks.add(new Deadline(task, deadline)); | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(tasks.get(tasks.size() - 1)); | ||
System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
} else if (s.equals("event")) { | ||
String rest = sc.nextLine(); | ||
String[] split = rest.split("/"); | ||
String task = split[0]; | ||
String time = split[1]; | ||
time = time.substring(time.indexOf(' ') + 1); | ||
tasks.add(new Event(task, time)); | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(tasks.get(tasks.size() - 1)); | ||
System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
} else if (s.equals("delete")) { | ||
int index = sc.nextInt() - 1; | ||
if (index >= tasks.size()) { | ||
throw new DukeException("Index out of bound!"); | ||
} | ||
tasks.remove(index); | ||
System.out.println("Noted. I've removed this task:"); | ||
System.out.println(tasks.get(index)); | ||
System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
sc.nextLine(); | ||
} else { | ||
String rest = sc.nextLine(); | ||
throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
} | ||
modify(tasks); | ||
} catch (DukeException e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
} |
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.
Do consider the use of a switch statement as opposed to a large if-else block.
switch (s) {
case "bye":
// Code for exit
break;
case "list":
// Code for list print
break;
...
src/main/java/Duke.java
Outdated
if (split[0].equals("T")) { | ||
tasks.add(new Task(split[2])); | ||
if (split[1].equals("1")) { | ||
tasks.get(tasks.size() - 1).markAsDone(); | ||
} | ||
} else if (split[0].equals("D")) { | ||
tasks.add(new Deadline(split[2], split[3])); | ||
if (split[1].equals("1")) { | ||
tasks.get(tasks.size() - 1).markAsDone(); | ||
} | ||
} else if (split[0].equals("E")) { | ||
tasks.add(new Event(split[2], split[3])); | ||
if (split[1].equals("1")) { | ||
tasks.get(tasks.size() - 1).markAsDone(); | ||
} |
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.
Again, consider using a switch statement.
A switch fallthrough can be used to deal with the Deadline (line 115) and Event (line 120) cases elegantly.
switch (split[0]) {
case "T":
// Code for Todo
break;
case "D":
// Fallthrough
case "E":
// Code for Deadline and Event
break;
src/main/java/Task.java
Outdated
protected String description; | ||
protected boolean isDone; | ||
protected char type; |
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.
Nice use of protected, though realistically not necessary for description and isDone.
src/main/java/Task.java
Outdated
public void markAsDone() { | ||
isDone = true; | ||
} | ||
|
||
public void markNotDone() { | ||
isDone = false; |
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.
May want to include some code to check if the user is attempting to markAsDone an already done task, and same for markNotDone, and respond to user accordingly.
… at various points in the code There are no checks to ensure the correctness of each aspect of the program (e.g. variable values at certain points in time). It allows some bugs to be left undetected until an Exception happens and theprogram is terminated. Adding assertions into the program acts as a sanity check and helps in ensuring the correctness of the program.
Use assert feature to document important assumptions that should hold…
…ssary Important exceptions were not thrown, causing the program to terminate when bugs occur. Exceptions need to be thrown and catch to ensure the code works as intended and to eliminate bugs. Important exceptions are thrown and catch, and the error message is displayed in Duke GUI, especially for exceptions regarding array out of bound and incorrect syntax.
Examines the code and refactor to improve the code quality where nece…
Provide a way for the user to find free times, the nearest date witho…
Duke
Duke helps you keep track of ToDo, Event, and Deadline tasks. It's
All you need to do is
Features:
If you are a Java programmer, you can use it to practice Java too. Here's the
main
method