Skip to content

[ngyongjian] iP#208

Open
ngyongjian wants to merge 29 commits into
nus-cs2113-AY2223S2:masterfrom
ngyongjian:master
Open

[ngyongjian] iP#208
ngyongjian wants to merge 29 commits into
nus-cs2113-AY2223S2:masterfrom
ngyongjian:master

Conversation

@ngyongjian

Copy link
Copy Markdown

No description provided.

@raydent30 raydent30 left a comment

Copy link
Copy Markdown

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 thread src/main/java/Duke.java Outdated
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.";
}

Copy link
Copy Markdown

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!

Comment thread src/main/java/Duke.java
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();

Copy link
Copy Markdown

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?

Comment thread src/main/java/Duke.java Outdated
+ event.toString() + System.lineSeparator() + "Now you have " + Task.numberOfTasks
+ " in the list.";
} else {
Task task = new Task(input);

Copy link
Copy Markdown

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?

Comment thread 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

Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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

@YC-Michael YC-Michael left a comment

Copy link
Copy Markdown

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.

Comment thread src/main/java/Duke.java Outdated
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>();

Copy link
Copy Markdown

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.

Comment thread src/main/java/Duke.java
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)) {

Copy link
Copy Markdown

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)

Comment thread src/main/java/Duke.java
System.out.println("___________________________________________________");
input = scan.nextLine();
}
} catch (NumberFormatException e) {

Copy link
Copy Markdown

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

Comment thread src/main/java/Event.java Outdated
@@ -0,0 +1,15 @@
public class Event extends Task {
protected String start;

Copy link
Copy Markdown

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.

@theopin theopin left a comment

Copy link
Copy Markdown

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 thread src/main/java/Duke.java Outdated
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
Copy Markdown

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 thread src/main/java/Duke.java Outdated
Comment on lines +48 to +49
String deadlineDesc = input.split("/")[0].split("deadline")[1].trim();
String deadlineDay = input.split("/")[1].trim();

Copy link
Copy Markdown

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 thread src/main/java/Duke.java Outdated
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
Copy Markdown

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