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

[ngyongjian] iP #208

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open

Conversation

ngyongjian
Copy link

No description provided.

Copy link

@raydent30 raydent30 left a 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.

Comment on lines 19 to 62
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.";
}

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();

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?

+ event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks
+ " in the list.";
} else {
Task task = new Task(input);

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?

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

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?

Copy link

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.

Copy link

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

Copy link

@YC-Michael YC-Michael left a 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.

@@ -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>();

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)) {

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.

Suggested change
try (Scanner scan = new Scanner(System.in)) {
try {
Scanner scan = new Scanner(System.in)

System.out.println("___________________________________________________");
input = scan.nextLine();
}
} catch (NumberFormatException e) {

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

@@ -0,0 +1,15 @@
public class Event extends Task {
protected String start;

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.

Copy link

@theopin theopin left a 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

Comment on lines 30 to 34
} 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();
Copy link

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

Comment on lines 48 to 49
String deadlineDesc = input.split("/")[0].split("deadline")[1].trim();
String deadlineDay = input.split("/")[1].trim();
Copy link

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

Comment on lines 55 to 57
} else if (input.startsWith("event", 0)) {
String eventDesc = input.split("/")[0].split("event")[1].trim();
String start = input.split("/")[1].trim();
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants