Skip to content

[Zhao Yuqing] iP#67

Open
z0723-julie wants to merge 33 commits into
nus-cs2113-AY2122S2:masterfrom
z0723-julie:master
Open

[Zhao Yuqing] iP#67
z0723-julie wants to merge 33 commits into
nus-cs2113-AY2122S2:masterfrom
z0723-julie:master

Conversation

@z0723-julie

Copy link
Copy Markdown

No description provided.

@shxr3f shxr3f 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.

Well written code based on Coding Statndards.
Got to take a look at switch statements.

Comment thread src/main/java/Duke.java Outdated
private static void showList() {
System.out.println(" ____________________________________________________________");
System.out.println(" Here are the tasks in your list:");
for (int i = 0; i < descriptions.size(); i++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing is always present in loops and conditional statements.

Comment thread src/main/java/Duke.java Outdated
Comment on lines +95 to +110
switch (type) {
case "T":
Todo todo = new Todo(description);
System.out.println(todo.toString(isDone));
break;
case "D":
Deadline deadline = new Deadline(description, date);
System.out.println(deadline.toString(isDone));
break;
case "E":
Event event = new Event(description, date);
System.out.println(event.toString(isDone));
break;
default:
System.out.println(" Unknown Type");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indentation for case clauses under switch statements

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing it out, I will work on it!

Comment thread src/main/java/Duke.java Outdated
Comment on lines +124 to +139
switch (type) {
case "T":
Todo todo = new Todo(description);
System.out.println(" " + todo.toString(true));
break;
case "D":
Deadline deadline = new Deadline(description, date);
System.out.println(" " + deadline.toString(true));
break;
case "E":
Event event = new Event(description, date);
System.out.println(" " + event.toString(true));
break;
default:
System.out.println(" Unknown Type");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indentation for case clauses under switch statements

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing it out, I will work on it!

Comment thread src/main/java/Duke.java Outdated
Comment on lines +6 to +10
private static ArrayList<String> descriptions = new ArrayList<>();
private static ArrayList<Boolean> dones = new ArrayList<>();
private static ArrayList<String> types = new ArrayList<>();
private static ArrayList<String> dates = new ArrayList<>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following plural form for Arrays! Good naming conventions used throughout.

Comment thread src/main/java/Duke.java Outdated
System.out.println("____________________________________________________________");
System.out.println(exits);
System.out.println("____________________________________________________________");
greeting();

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 modularization here.

Comment thread src/main/java/Deadline.java Outdated
@@ -0,0 +1,14 @@
public class Deadline extends Task {

protected String by;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name might not be meaningful enough, maybe change to "deadline"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will reconsider that.

Comment thread src/main/java/Duke.java Outdated
}

private static void echo() {
String line;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The meaning of “line” is a bit unclear, maybe consider change it into "input"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will reconsider that.

Comment thread src/main/java/Duke.java Outdated
System.out.println(" ____________________________________________________________");
System.out.println(" Here are the tasks in your list:");
for (int i = 0; i < descriptions.size(); i++) {
System.out.println(i+1 + "." + descriptions.get(i));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should always be spaces before and after +

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing it out, I will work on it!

Comment thread src/main/java/Duke.java Outdated
int number = Integer.parseInt(line.substring(line.length() - 1));
markAsDone(number);
line = in.nextLine();
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The continue here is redundant

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing it out, I will work on it!

Comment thread src/main/java/Deadline.java Outdated
@@ -0,0 +1,14 @@
public class Deadline extends Task {

protected String by;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name might not be meaningful enough, maybe change to "deadline"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will consider it!

Comment thread src/main/java/Duke.java Outdated
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
greeting();
getCommand();

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 modularization here.

Comment thread src/main/java/Duke.java Outdated
}

private static void getCommand() {
String line;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The meaning of “line” is a bit unclear, maybe consider change it into "input"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will consider that.

Comment thread src/main/java/Duke.java Outdated
int number = Integer.parseInt(line.substring(line.length() - 1));
markAsDone(number);
line = in.nextLine();
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The continue here is redundant.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will consider that.

Comment thread src/main/java/Event.java Outdated
@@ -0,0 +1,14 @@
public class Event extends Task {

protected String at;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to reconsider the variable name "at" also, it's unclear about the meaning

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will consider that.

Comment thread src/main/java/Duke.java Outdated
Todo todo = new Todo(description);
System.out.println(todo.toString(isDone));
break;
case "D":

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indentation required for case statement

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing it out, I will fix it.

@warrencxw warrencxw 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.

Code was generally well done. There are just a few potential areas for improvement to help readability and code quality to consider.

Comment thread src/main/java/Duke.java Outdated
Comment on lines 12 to 16
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making this logo a constant instead, as it would not be changed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will reconsider that.

Comment thread src/main/java/Duke.java Outdated
Comment on lines +47 to +49
System.out.println(" ____________________________________________________________");
System.out.println(" Bye. Hope to see you again soon!");
System.out.println(" ____________________________________________________________");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making the String here a constant with perhaps a name of FAREWELL_MESSAGE, so that it is clear that you are printing a closing message at the end.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will reconsider that.

Comment thread src/main/java/Duke.java Outdated
private static void markAsDone(int number) {
System.out.println(" ____________________________________________________________");
System.out.println(" Nice! I've marked this task as done:");
int index = number - 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider naming the variable as something that may be more easily understood at one glance, e.g. taskNumber, taskIndex

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing it out, I will work on it!

Comment thread src/main/java/Duke.java Outdated
System.out.println(" ____________________________________________________________");
}

private static void greeting() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming greeting to a verb to make it clearer what this method does.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing it out, I will work on it!

Comment thread src/main/java/Duke.java Outdated
dones.add(false);
if (line.startsWith("todo")) {
types.add("T");
description = line.substring(5);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting out this magic literal '5' into a constant to make it clearer why this substring is made.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing it out, I will work on it!

@laiisaac laiisaac 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.

There are some good practices overall, but I think using more Single Level Abstraction could make the code more readable

Comment thread src/main/java/Duke.java Outdated
Comment on lines +24 to +26
Scanner in = new Scanner(System.in);
// get user input
line = in.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.

Maybe a method of getUserInput would increase readability?

Comment thread src/main/java/Duke.java Outdated
System.out.println(" ____________________________________________________________");
}

private static void handleCommand(String line) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleCommand method looks a little long, perhaps adding methods for adding different events can increase readability?

Comment thread src/main/java/Duke.java Outdated
line = in.nextLine();
continue;
}
// Command is valid, handle the command

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 the occasional comments which clarify parts of the code

Comment thread src/main/java/Duke.java Outdated
}
}

private static void showList() {

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 methods like this where the name makes the intention obvious, would love to see more of such methods.

Comment thread src/main/java/duke/Duke.java Outdated
continue;
}
if (input.startsWith("done")) {
int number = Integer.parseInt(input.substring(input.length() - 1));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a separate variable for input.substring(input.length() - 1) to make the code more readable

Comment thread src/main/java/duke/Duke.java Outdated
continue;
}
if (input.startsWith("delete")) {
int number = Integer.parseInt(input.substring(input.length() - 1));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the parseInt in deleteTask function to maintain SLAP

Comment thread src/main/java/duke/Duke.java Outdated
}
}

private static void loadTasks() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create a separate class for things that have to do with the storing of information into a text file, instead of including it all in Duke


private static void markAsDone(int number) {
System.out.println(" ____________________________________________________________");
System.out.println(" Nice! I've marked this task as done:");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create constants for these messages

System.out.println(" ____________________________________________________________");
System.out.println(" Nice! I've marked this task as done:");
int index = number - 1;
String description = tasks.get(index);

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 creating an exception for if the task with that index doesnt exist. E.g. if your tasks length is only 2 and someone inputs 5 as the index

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.

6 participants