-
Notifications
You must be signed in to change notification settings - Fork 200
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
[ngyongjian] iP #208
base: master
Are you sure you want to change the base?
[ngyongjian] iP #208
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.
Good job on your code!
Could use some reformating.
src/main/java/Duke.java
Outdated
if (input.equals("list")) { | ||
output = "Here are the tasks in the list:" + System.lineSeparator() + Task.printTasksList(tasks); | ||
|
||
} else if (input.matches("mark [0-9]{1,2}")) { | ||
String[] marks = input.split(" "); | ||
tasks.get(Integer.parseInt(marks[1]) - 1).markAsDone(); | ||
output = "Nice! I've marked this task as done:" + System.lineSeparator() | ||
+ tasks.get(Integer.parseInt(marks[1]) - 1).toString(); | ||
} else if (input.matches("unmark [0-9]{1,2}")) { | ||
String[] marks = input.split(" "); | ||
tasks.get(Integer.parseInt(marks[1]) - 1).markAsNotDone(); | ||
output = "OK, I've marked this task as not done yet:" + System.lineSeparator() | ||
+ tasks.get(Integer.parseInt(marks[1]) - 1).toString(); | ||
} else if (input.startsWith("todo", 0)) { | ||
String toDoDesc = input.split("todo")[1].trim(); | ||
Task toDo = new Todo(toDoDesc); | ||
tasks.add(toDo); | ||
output = "Got it. I've added this task:" + System.lineSeparator() | ||
+ toDo.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks | ||
+ " in the list."; | ||
} else if (input.startsWith("deadline", 0)) { | ||
String deadlineDesc = input.split("/")[0].split("deadline")[1].trim(); | ||
String deadlineDay = input.split("/")[1].trim(); | ||
Task deadline = new Deadline(deadlineDesc, deadlineDay); | ||
tasks.add(deadline); | ||
output = "Got it. I've added this task:" + System.lineSeparator() | ||
+ deadline.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks | ||
+ " in the list."; | ||
} else if (input.startsWith("event", 0)) { | ||
String eventDesc = input.split("/")[0].split("event")[1].trim(); | ||
String start = input.split("/")[1].trim(); | ||
String end = input.split("/")[2].trim(); | ||
Task event = new Event(eventDesc, start, end); | ||
tasks.add(event); | ||
output = "Got it. I've added this task:" + System.lineSeparator() | ||
+ event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks | ||
+ " in the list."; | ||
} else { | ||
Task task = new Task(input); | ||
tasks.add(task); | ||
output = "Got it. I've added this task:" + System.lineSeparator() | ||
+ task.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks | ||
+ " 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 code readability with the else-if statements!
System.out.println("What can I do for you?\n"); | ||
ArrayList<Task> tasks = new ArrayList<Task>(); | ||
try (Scanner scan = new Scanner(System.in)) { | ||
String input = scan.nextLine(); |
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.
"Arrow Head" code, maybe you can consider avoiding deep nesting?
src/main/java/Duke.java
Outdated
+ event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks | ||
+ " in the list."; | ||
} else { | ||
Task task = new Task(input); |
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.
A lot of complex strings/formulas, maybe consider splitting them up?
src/main/java/Duke.java
Outdated
Task event = new Event(eventDesc, start, end); | ||
tasks.add(event); | ||
output = "Got it. I've added this task:" + System.lineSeparator() | ||
+ event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks |
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.
A lot of "magic numbers" involved. Maybe can consider using constants instead?
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.
Try not to use magic numbers. Can consider using an aptly named variable.
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.
Can consider using switch case instead of if else to decide what to do based on the first word entered
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, good naming and layout.
src/main/java/Duke.java
Outdated
@@ -6,5 +9,68 @@ public static void main(String[] args) { | |||
+ "| |_| | |_| | < __/\n" | |||
+ "|____/ \\__,_|_|\\_\\___|\n"; | |||
System.out.println("Hello from\n" + logo); | |||
System.out.println("Hello! I'm Duke"); | |||
System.out.println("What can I do for you?\n"); | |||
ArrayList<Task> tasks = new ArrayList<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.
I like how you used a resizable array to store the tasks instead of a fixed size of 100.
System.out.println("Hello! I'm Duke"); | ||
System.out.println("What can I do for you?\n"); | ||
ArrayList<Task> tasks = new ArrayList<Task>(); | ||
try (Scanner scan = 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.
Please follow the Java coding standards when using exceptions.
try (Scanner scan = new Scanner(System.in)) { | |
try { | |
Scanner scan = new Scanner(System.in) |
System.out.println("___________________________________________________"); | ||
input = scan.nextLine(); | ||
} | ||
} catch (NumberFormatException e) { |
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 exceptions here
src/main/java/Event.java
Outdated
@@ -0,0 +1,15 @@ | |||
public class Event extends Task { | |||
protected String start; |
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.
variables such as start and end can be more descriptive.
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 implementation on Duke so far! Some general points to improve your code:
- Use of magic literals: Do try to identify such literals and replace them with named constants so that readers can better understand what your code aims to achieve
- Long Main method: Due to implementation of all the main features of duke being consolidated in the main function, it seems difficult to read and understand the flow of it. Do consider refacotring these features into seperate methods to enhance understandability of the code
src/main/java/Duke.java
Outdated
} else if (input.startsWith("mark")) { | ||
String[] marks = input.split(" "); | ||
tasks.get(Integer.parseInt(marks[1]) - 1).markAsDone(); | ||
output = "Nice! I've marked this task as done:" + System.lineSeparator() | ||
+ tasks.get(Integer.parseInt(marks[1]) - 1).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.
Try extracting such chunks into a seperate method to ease readability of the main function as it seems to be too big currently
src/main/java/Duke.java
Outdated
String deadlineDesc = input.split("/")[0].split("deadline")[1].trim(); | ||
String deadlineDay = input.split("/")[1].trim(); |
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.
Strings such as "/" and "deadline" seem to suggest usage of magic literals, do consider declaring them as named constants to enhance readability and understandability
src/main/java/Duke.java
Outdated
} else if (input.startsWith("event", 0)) { | ||
String eventDesc = input.split("/")[0].split("event")[1].trim(); | ||
String start = input.split("/")[1].trim(); |
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.
Indentation seems off here, should be 4 instead of 2
Branch level 9
add JavaDoc
No description provided.