-
Notifications
You must be signed in to change notification settings - Fork 192
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
[Silin Chen] iP #192
base: master
Are you sure you want to change the base?
[Silin Chen] iP #192
Conversation
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 job on the readability of the code, but the main thing to look out for is the method names.
src/main/java/Task.java
Outdated
public void setDone() { | ||
this.isDone = true; | ||
} |
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.
Good job following naming conventions, however, I think you may have to place a parameter for the boolean instead.
src/main/java/Duke.java
Outdated
if (line.equals("list")) { | ||
for (int i = 0; i < taskNumber; i++) { | ||
System.out.println((i + 1) + "." + tasks[i]); | ||
} |
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.
Good work on following bracketing conventions:
https://se-education.org/guides/conventions/java/basic.html#conditionals
src/main/java/Duke.java
Outdated
Task[] tasks= new Task[100]; | ||
int taskNumber = 0; | ||
String line; | ||
Scanner in = new Scanner(System.in); |
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 you can name the in
here inputScanner
instead?
src/main/java/Duke.java
Outdated
public class Duke { | ||
public static void hi() { |
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.
The name of the method have to be a verb instead:
https://se-education.org/guides/conventions/java/basic.html#naming
src/main/java/Duke.java
Outdated
System.out.println("What can I do for you?"); | ||
} | ||
|
||
public static void 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.
The name of the method have to be a verb instead:
https://se-education.org/guides/conventions/java/basic.html#naming
src/main/java/Duke.java
Outdated
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
|
||
public static void running() { |
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.
The name of the method have to be a verb instead:
https://se-education.org/guides/conventions/java/basic.html#naming
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, readability is there. Main issue is the long running() method that takes up multiple lines of code. Do try to keep a method within 30 lines of code.
src/main/java/Duke.java
Outdated
public static void running() { | ||
Task[] tasks= new Task[100]; | ||
int taskNumber = 0; | ||
String line; | ||
Scanner in = new Scanner(System.in); | ||
while (true) { | ||
//new scanner | ||
line = in.nextLine(); | ||
//if goodbye | ||
if (line.equals("bye")) { | ||
return; | ||
} | ||
//if want to list out tasks or mark as done or add items | ||
if (line.equals("list")) { | ||
for (int i = 0; i < taskNumber; i++) { | ||
System.out.println((i + 1) + "." + tasks[i]); | ||
} | ||
} else if (line.startsWith("done")) { | ||
int index = Integer.parseInt(line.substring(5)) - 1; | ||
tasks[index].setDone(); | ||
System.out.println("Nice! I've marked this task as done:"); | ||
System.out.println(" " + tasks[index].getStatusIcon() + " " + tasks[index].getDescription()); | ||
} else if (line.startsWith("todo")) { | ||
tasks[taskNumber] = new ToDo(line.substring(5)); | ||
taskNumber++; | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(" " + tasks[taskNumber - 1]); | ||
System.out.println("Now you have " + taskNumber + " tasks in the list"); | ||
} else if (line.startsWith("deadline")) { | ||
String[] words = line.split(" "); | ||
int index = 0; | ||
String deadlineDescription = ""; | ||
String by = ""; | ||
for (int i = 0; i < words.length; i++) { | ||
if (words[i].equals("/by")) { | ||
index = i; | ||
break; | ||
} | ||
} | ||
for (int i = 1; i < index; i++) { | ||
deadlineDescription = deadlineDescription + words[i] + " "; | ||
} | ||
by = words[index + 1]; | ||
tasks[taskNumber] = new Deadline(deadlineDescription, by); | ||
taskNumber++; | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(" " + tasks[taskNumber - 1]); | ||
System.out.println("Now you have " + taskNumber + " tasks in the list"); | ||
} else if (line.startsWith("event")) { | ||
String[] words = line.split(" "); | ||
int index = 0; | ||
String eventDescription = ""; | ||
String at = ""; | ||
for (int i = 0; i < words.length; i++) { | ||
if (words[i].equals("/at")) { | ||
index = i; | ||
break; | ||
} | ||
} | ||
for (int i = 1; i < index; i++) { | ||
eventDescription = eventDescription + words[i] + " "; | ||
} | ||
for (int i = index + 1; i < words.length; i++) { | ||
at = at + words[i] + " "; | ||
} | ||
tasks[taskNumber] = new Event(eventDescription, at); | ||
taskNumber++; | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(" " + tasks[taskNumber - 1]); | ||
System.out.println("Now you have " + taskNumber + " tasks in the list"); | ||
} | ||
} | ||
} |
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.
Method is over 30 lines of code. It would not fit into the computer screen making it hard to debug and read. Maybe split the method into smaller methods.
src/main/java/Deadline.java
Outdated
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 + ")"; | ||
} | ||
} |
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.
Clear! Reader would not be confused.
src/main/java/ToDo.java
Outdated
public class ToDo extends Task{ | ||
public ToDo(String description) { | ||
super(description); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[T]" + super.toString(); | ||
} | ||
} |
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.
Clear! Reader would not be confused.
src/main/java/Task.java
Outdated
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public void setDone() { | ||
this.isDone = true; | ||
} | ||
|
||
public String getDescription() { | ||
return this.description; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "[X]" : "[ ]"); // mark done task with X | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.getStatusIcon() + " " + this.getDescription(); | ||
} | ||
} |
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.
Clear! Reader would not be confused.
src/main/java/Duke.java
Outdated
if (line.equals("list")) { | ||
for (int i = 0; i < taskNumber; i++) { | ||
System.out.println((i + 1) + "." + tasks[i]); | ||
} | ||
} else if (line.startsWith("done")) { | ||
int index = Integer.parseInt(line.substring(5)) - 1; | ||
tasks[index].setDone(); | ||
System.out.println("Nice! I've marked this task as done:"); | ||
System.out.println(" " + tasks[index].getStatusIcon() + " " + tasks[index].getDescription()); | ||
} else if (line.startsWith("todo")) { | ||
tasks[taskNumber] = new ToDo(line.substring(5)); | ||
taskNumber++; | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(" " + tasks[taskNumber - 1]); | ||
System.out.println("Now you have " + taskNumber + " tasks in the list"); | ||
} else if (line.startsWith("deadline")) { | ||
String[] words = line.split(" "); | ||
int index = 0; | ||
String deadlineDescription = ""; | ||
String by = ""; | ||
for (int i = 0; i < words.length; i++) { | ||
if (words[i].equals("/by")) { | ||
index = i; | ||
break; | ||
} | ||
} | ||
for (int i = 1; i < index; i++) { | ||
deadlineDescription = deadlineDescription + words[i] + " "; | ||
} | ||
by = words[index + 1]; | ||
tasks[taskNumber] = new Deadline(deadlineDescription, by); | ||
taskNumber++; | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(" " + tasks[taskNumber - 1]); | ||
System.out.println("Now you have " + taskNumber + " tasks in the list"); | ||
} else if (line.startsWith("event")) { | ||
String[] words = line.split(" "); | ||
int index = 0; | ||
String eventDescription = ""; | ||
String at = ""; | ||
for (int i = 0; i < words.length; i++) { | ||
if (words[i].equals("/at")) { | ||
index = i; | ||
break; | ||
} | ||
} | ||
for (int i = 1; i < index; i++) { | ||
eventDescription = eventDescription + words[i] + " "; | ||
} | ||
for (int i = index + 1; i < words.length; i++) { | ||
at = at + words[i] + " "; | ||
} | ||
tasks[taskNumber] = new Event(eventDescription, at); | ||
taskNumber++; | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(" " + tasks[taskNumber - 1]); | ||
System.out.println("Now you have " + taskNumber + " tasks in the list"); | ||
} |
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.
Good work on avoiding deep nested conditionals!
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.
In general, I think you did a great job in complying with the coding standards! I have pointed out some minor changes that you could make to enhance the quality of your code. Keep up the good work!
src/main/java/duke/command/Duke.java
Outdated
while (true) { | ||
line = in.nextLine(); | ||
if (line.equals("bye")) { | ||
return; | ||
} | ||
if (line.equals("list")) { | ||
listOut(tasks, taskNumber); | ||
} else if (line.startsWith("done")) { | ||
markDone(line, tasks); | ||
} else if (line.startsWith("todo")) { | ||
if (addTodo(line, tasks, taskNumber)) { | ||
taskNumber++; | ||
} | ||
} else if (line.startsWith("deadline")) { | ||
if (addDeadline(line, tasks, taskNumber)) { | ||
taskNumber++; | ||
} | ||
} else if (line.startsWith("event")) { | ||
if (addEvent(line, tasks, taskNumber)) { | ||
taskNumber++; | ||
} | ||
} else { | ||
System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
} | ||
} |
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.
You could consider splitting this functionality into another method for better readability and reusability of your code.
src/main/java/duke/command/Duke.java
Outdated
tasks[taskNumber] = new Event(eventDescription, at); | ||
taskNumber++; | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(" " + tasks[taskNumber - 1]); |
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.
Should the magic literal 1 be declared as a constant instead so that it is easier for you and other programmers to refer to your code in the future? This applies to all magic literals across the code.
src/main/java/duke/command/Duke.java
Outdated
String[] words = line.split(" "); | ||
int index = 0; | ||
String deadlineDescription = ""; | ||
String by = ""; | ||
for (int i = 0; i < words.length; i++) { | ||
if (words[i].equals("/by")) { | ||
index = i; | ||
break; | ||
} | ||
} | ||
if (index == 0) { | ||
System.out.println("OOPS!!! The description of a deadline cannot be empty."); | ||
return false; | ||
} | ||
for (int i = 1; i < index; i++) { | ||
deadlineDescription = deadlineDescription + words[i] + " "; | ||
} | ||
for (int i = index + 1; i < words.length; i++) { | ||
by = by + words[i] + " "; | ||
} | ||
tasks[taskNumber] = new Deadline(deadlineDescription, by); | ||
taskNumber++; | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(" " + tasks[taskNumber - 1]); | ||
System.out.println("Now you have " + taskNumber + " tasks in the list"); | ||
return true; |
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.
You may want to consider splitting this method into multiple smaller methods that do smaller tasks and call it from this method. This goes the same for the other tasks-related methods.
src/main/java/duke/command/Duke.java
Outdated
|
||
|
||
public class Duke { | ||
public static void listOut(Task[] tasks, int taskNumber) { |
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.
Consider using a clearer naming convention for your method such as printTasks().
this.by = by; | ||
} | ||
|
||
@Override |
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.
Good use of the override statement. Well done!
@@ -0,0 +1,12 @@ | |||
package duke.task; | |||
|
|||
public class ToDo extends 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.
Do take note of the spacing for each bracket and curly braces for the consistency of the whole program.
src/main/java/duke/command/Duke.java
Outdated
while (true) { | ||
line = in.nextLine(); | ||
if (line.equals("bye")) { | ||
return; |
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.
In general, we do not use a return statement in a void function. If you want to break out of the current loop, use the "break" statement instead.
add the find feature (level 9)
# Conflicts: # src/main/java/duke/command/TaskList.java
Branch a java doc
No description provided.