Skip to content

[Teo Jia Rong] iP - #73

Open
tjiarong wants to merge 43 commits into
nus-cs2113-AY2122S2:masterfrom
tjiarong:master
Open

tjiarong wants to merge 43 commits into
nus-cs2113-AY2122S2:masterfrom
tjiarong:master

Conversation

@tjiarong

@tjiarong tjiarong commented Feb 2, 2022

Copy link
Copy Markdown

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

@Teanweijun Teanweijun 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 the code looks nice. Just have a few misc improvements that could be made. Keep it up!

Comment thread src/main/java/Duke.java Outdated
Comment on lines +14 to +41
String command = line.split(" ")[0];
while (!command.equals("bye")) {
switch (command) {
case "list":
printList(tasks);
break;
case "unmark":
unmarkTask(line, tasks);
break;
case "mark":
markTask(line, tasks);
break;
case "todo":
addToDo(line, tasks);
break;
case "deadline":
addDeadline(line, tasks);
break;
case "event":
addEvent(line, tasks);
break;
default:
addTask(line, tasks);
break;
}
line = in.nextLine();
command = line.split(" ")[0];
}

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 this section into a separate method? It could make your main more readable.

Comment thread src/main/java/Duke.java Outdated
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
final int MAX_TASK = 100;
Task[] tasks = new Task[MAX_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.

tasks here is a global variable... Is there a reason you have to pass them explicitly into your methods such as unmarkTask?

Comment thread src/main/java/Duke.java Outdated
+ "| ) | (___) | | | | ) ( | | | | (___) || ) \\ | \n"
+ "|/ (_______) )_( |/ \\| )_( (_______)|/ )_) \n";

System.out.println("_____________________________________________\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.

Since you use this line a lot, you could consider creating a static String to print this line instead of copying it all the time?

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

@Override
public String toString() {
return ("[D]" + super.toString() + " (at: " + getPeriod() + ")");

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 method exists inside the Events class already. It might be better if you printed period instead of calling getPeriod. Similar improvements can be made throughout the code.

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

private static void addEvent(String line, Task[] tasks) {
String arg = line.split(" ", 2)[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.

This line.split by space is repeated throughout your adds. I think it'd be better if you could handle this before passing it into the function!

Comment thread src/main/java/Duke.java Outdated
Comment on lines +70 to +75
System.out.println("_____________________________________________\n"
+ "Got it. I've added this task: \n"
+ t + "\n"
+ "Now you have " + (t.getTaskCount() - 1) + " tasks in the list." + "\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.

I like how your print statements all end with "\n", makes it very readable!

Comment thread src/main/java/Duke.java Outdated
String eventDate = arg.split("/at ", 2)[1];
Task t = new Events(event, eventDate);
tasks[t.getTaskCount() - 1] = t;
System.out.println("_____________________________________________\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.

Maybe can make the line a constant variable since you use it a lot.

Comment thread src/main/java/Duke.java Outdated
Comment on lines +47 to +61
String logo = "_______ _______ _________ _______ _________ _______ _\n"
+ "( ____ )( ___ )\\__ __/( ___ )\\__ __/( ___ )( ( /|\n"
+ "| ( )|| ( ) | ) ( | ( ) | ) ( | ( ) || \\ ( |\\\n"
+ "| (____)|| | | | | | | (___) | | | | | | || \\ | |\n"
+ "| _____)| | | | | | | ___ | | | | | | || (\\ \\) | \n"
+ "| ( | | | | | | | ( ) | | | | | | || | \\ | \n"
+ "| ) | (___) | | | | ) ( | | | | (___) || ) \\ | \n"
+ "|/ (_______) )_( |/ \\| )_( (_______)|/ )_) \n";

System.out.println("_____________________________________________\n"
+ logo + "\n"
+ "Hello! I'm Duke\n"
+ "What can I do for you?\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.

it's really readable to change a new line when you add \n

Comment thread src/main/java/Duke.java Outdated
Comment on lines +140 to +143
System.out.println("_____________________________________________\n"
+ "OK, I've marked this task as not done yet:\n"
+ tasks[taskNum] + "\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.

since you have use this print method in many classes maybe can consider making it as a method that every class can use

Comment thread src/main/java/Duke.java Outdated
Comment on lines +17 to +20
case "list":
printList(tasks);
break;
case "unmark":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

matching switch case coding standard!

Comment thread src/main/java/potaton/Potaton.java Outdated
String eventDate = arg.split(" \\(at: ", 2)[1].split("\\)")[0];
Task t = new Events(event, eventDate);
tasks.add(t);
System.out.println("_____________________________________________\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.

You have several println statements with line headers like this. How about shortening the print statements by declaring a header variable and reusing it?

Comment thread src/main/java/potaton/Potaton.java Outdated
public static final String FILE_MISSING_MESSAGE = "File does not exist. Creating file.";
public static final String FILE_FOUND_MESSAGE = "File found. Loading file into database.";

public static void main(String[] args) throws IOException {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Excellent use of SLAP here.

Comment thread src/main/java/potaton/Potaton.java Outdated
Comment on lines +147 to +149
String arg = line.split("] ", 2)[1];
String task = arg.split(" \\(by: ", 2)[0];
String dueDate = arg.split(" \\(by: ", 2)[1].split("\\)")[0];

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 appears to be a magic number which you could avoid. How about trying named constants?

import java.util.ArrayList;
import java.util.Scanner;

public class Potaton {

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 have little or no javadoc comments. Including them in this class would greatly help the reader quickly understand what some of the methods are doing.

Comment thread src/main/java/potaton/Potaton.java Outdated
Comment on lines +58 to +66
try {
addToDo(line, tasks);
} catch (IndexOutOfBoundsException e) {
// Refactor this later
System.out.println("_____________________________________________\n"
+ "Error: The description of a todo cannot be empty." + "\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.

This block of code could be refactored so as to ensure SLAP.

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.

4 participants