Skip to content

[Tai Kah Kiang] iP#70

Open
kktai1512 wants to merge 42 commits into
nus-cs2113-AY2122S2:masterfrom
kktai1512:master
Open

[Tai Kah Kiang] iP#70
kktai1512 wants to merge 42 commits into
nus-cs2113-AY2122S2:masterfrom
kktai1512:master

Conversation

@kktai1512

Copy link
Copy Markdown

Completed until Week 3 (Level 3, then A- Coding Standard)

Has greetings, todo, and toggle complete

@kktai1512
kktai1512 force-pushed the master branch 2 times, most recently from 7d1cef2 to e86117d Compare February 2, 2022 12:31

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

Great work in overall! Levels of abstraction are present too.

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

//main
public static void run (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 title of this method can be more informative.

Comment thread src/main/java/Duke.java Outdated
String addInfo = words.size() >= 2 ? words.get(1) : null;

switch (type) {
case "todo":

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 extracting out some methods or sub-methods to a new class (eg. TaskManager, TaskList) to manage any functions related to Task

@cczhouqi cczhouqi 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, I think your code is clear and easy to follow👍🏻 There are only some minor formatting things that you may want to improve on.

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

//command methods
public static void hello() {

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 abstracted the hello message (and other tasks), that makes your main method clean and clear :D

Comment thread src/main/java/Duke.java Outdated
public static void run (String line) {
ArrayList<String> words = processInput(line, " ");
String command = words.get(0);
String description = words.size()>= 2 ? words.get(1) : null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Format can be more consistent here: you may want to add a space between “word.size()” and “>=“.

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

hello();

Scanner sc = 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.

Maybe the name “sc” can be more informative.

Comment thread src/main/java/Event.java Outdated

public Event(String name, String time) {
super(name);
this.time= time;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same as in Duke.java line 94, you may want to add a space between “this.time” and “=“ to make it more consistent.

@khseah khseah 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 clean and easy to read. However I feel the code can be more consistent as some methods and blocks of code are separated by a new line while others are not.

Comment thread src/main/java/Deadline.java Outdated

public Deadline(String name, String deadline) {
super(name);
this.deadline= deadline;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
this.deadline= deadline;
this.deadline = deadline;

Maybe add a space to improve readability. I noticed this in other parts of the code as well

Comment thread src/main/java/Deadline.java Outdated

@Override
public String toString() {
return "[D]" + super.toString() + String.format("(%s)", this.deadline) ;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
return "[D]" + super.toString() + String.format("(%s)", this.deadline) ;
return "[D]" + super.toString() + String.format("(%s)", this.deadline);

Not sure why there is a space before ;

Comment thread src/main/java/Duke.java Outdated
Comment on lines +23 to +25
if (divider != -1) {
words.set(0, line.substring(0, divider));
words.add(line.substring(divider+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.

Try and avoid magic literals

Comment thread src/main/java/Duke.java Outdated
printWithDivider(task.toString());
}

//main

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This comment isn't really helpful. Maybe provide more details?

Comment thread src/main/java/Event.java Outdated
@@ -0,0 +1,14 @@
public class Event extends 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.

This class has a empty line before its attributes. However I noticed other classes do not have this empty line. Try and make it more consistent

Comment thread src/main/java/Duke.java
public class Duke {
public static void main(String[] args) {

//fields

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This comment is not very helpful in providing further explanation on how the variable is used. It can be omitted.

Comment thread src/main/java/Duke.java Outdated
public static void run(String line) throws DukeException {
ArrayList<String> words = IOMethods.splitToTwo(line, " ");
String command = words.get(0);
String description = words.size()>= 2 ? words.get(1) : null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 is a magic number that you could avoid. Consider using named constants instead.

Comment thread src/main/java/Duke.java Outdated
Comment on lines +64 to +65


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove empty lines like these to improve code readability.

Comment on lines +24 to +26
String taskType = input.substring(indexOfSpace + 2, indexOfSpace+3);
String status = input.substring(indexOfSpace + 5, indexOfSpace + 6);
String nameAndDate = input.substring(indexOfSpace+ 7);

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 many magic numbers here which you can avoid.

System.out.println(breakLine);
}

public static void errorHandler(String input) throws DukeException {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is method is quite long (>30 LoC). Consider applying SLAP for each of the commands for further abstraction.

Comment on lines +34 to +36
case "todo":
case "event":
case "deadline":

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 refer to switch case statement layout in the Java coding standards and add fallthrough comments here.

Comment on lines +42 to +50
if (command.equals("event") || command.equals("deadline")) {
int indexOfSlash = input.indexOf("/");
String date = indexOfSlash == -1 ? "" : input.substring(indexOfSlash);
if (date.length() <= 1) {
String errorMsg = String.format("%s requires a valid date in the format taskName /date\n", command);
throw new DukeException(errorMsg);
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It is strange that event and deadline blocks of code are handled here after the fallthrough and there seems to be no course of action for todo beside checking for empty taskName. These lines seems trippy and you could try to restructure it to a simple form.

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