Skip to content

[John Nicholas S] iP#88

Open
johnsuharjono wants to merge 35 commits into
nus-cs2113-AY2122S2:masterfrom
johnsuharjono:master
Open

[John Nicholas S] iP#88
johnsuharjono wants to merge 35 commits into
nus-cs2113-AY2122S2:masterfrom
johnsuharjono:master

Conversation

@johnsuharjono

Copy link
Copy Markdown

No description provided.

Comment thread src/main/java/Brave.java Outdated
public class Brave {
public static void main(String[] args) {
String input;
String[] splitInput;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Plural form should be used on names representing a collection of objects - maybe use splitInputs instead?

Comment thread src/main/java/Brave.java Outdated
tasks.addTask(new Event(description, eventTime));
break;
default:
System.out.println("Wrong input, available command are -> list/mark/unmark/todo/deadline/event");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice catch for unknown commands!

Comment thread src/main/java/Deadline.java Outdated
this.by = by;
}

@Override

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 note on method overriding!

Comment thread src/main/java/Event.java Outdated
Comment on lines +1 to +17
public class Event extends Task {
private String eventTime;

public Event(String description, String eventTime) {
super(description);
this.eventTime = eventTime;
}

@Override
public String getStatusIcon() {
return "[E]" + super.getStatusIcon();
}

public String getDescription() {
return super.getDescription() + String.format(" (at: %s)", this.eventTime);
}
} No newline at end of file

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 done, I don't think there's any violations here :-)

Comment thread src/main/java/Brave.java Outdated
Comment on lines +15 to +16


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should this be 1 newline?

@wli-linda wli-linda 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 quality code, nice work! I like your way of getting rid of magic numbers

Comment thread src/main/java/Brave.java Outdated
Comment on lines +29 to +49
switch (command) {
case "list":
tasks.printTaskList();
break;
case "mark":
tasks.markTask(Integer.parseInt(splitInput[1]) - 1); // 0 indexing
break;
case "unmark":
tasks.unmarkTask(Integer.parseInt(splitInput[1]) - 1); // 0 indexing
break;
case "todo":
tasks.addTask(new Todo(splitInput[1]));
break;
case "deadline":
// To-do validate arguments~
arguments = splitInput[1].split(" /by ", 2);
description = arguments[0];
String by = arguments[1];
tasks.addTask(new Deadline(description, by));
break;
case "event":

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 main method is a little long, maybe it'd be nice to extract this portion as a separate method?

Comment thread src/main/java/TaskManager.java Outdated
public void addTask(Task description) {
this.tasks[this.tasksCount] = description;
System.out.println("\t____________________________________________________________");
System.out.println("\tYepp, I have added this task\n\t" + this.tasks[this.tasksCount].description + "\n\tYou currently have " + (this.tasksCount + 1) + " task 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.

Consider splitting this line so it's not so long?

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

Nice use of class inheritance

Comment thread src/main/java/TaskManager.java Outdated
Comment on lines +2 to +3
public static final int MAX_TASK = 100;
private final 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.

Good way of getting rid of magic numbers!

Comment thread src/main/java/Event.java Outdated
Comment on lines +9 to +12
@Override
public String getStatusIcon() {
return "[E]" + super.getStatusIcon();
}

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 method overriding :)

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

I only see one naming convention you could consider correcting. The readability of your code is quite nice; I appreciate how concise your 'Brave.java' is, and all of your other classes are very understandable. I added a few notes on things I thought were well done, and a few suggestions such as Javadoc comments.

Comment thread src/main/java/TaskManager.java Outdated
@@ -0,0 +1,44 @@
public class TaskManager {

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 think the inclusion of a TaskManager class is a very good idea; it makes the code in 'Main' much more concise

Comment thread src/main/java/TaskManager.java Outdated
public void addTask(Task description) {
this.tasks[this.tasksCount] = description;
System.out.println("\t____________________________________________________________");
System.out.println("\tYepp, I have added this task\n\t" + this.tasks[this.tasksCount].description + "\n\tYou currently have " + (this.tasksCount + 1) + " task 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.

The max line length is 120 characters; maybe you could split this between two lines?

Comment thread src/main/java/TaskManager.java Outdated
Comment on lines +2 to +3
public static final int MAX_TASK = 100;
private final 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.

Good job including a MAX_TASK constant for this; it is a common mistake to forget it (I need to fix this in my code)

Comment thread src/main/java/Task.java Outdated
Comment on lines +1 to +25
public class Task {
protected String description;
protected boolean isDone;

public Task(String description) {
this.description = description;
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "[X]" : "[ ]"); // mark done task with X
}

public String getDescription() {
return description;
}

public void markAsDone() {
isDone = true;
}

public void unmarkAsDone() {
isDone = false;
}
}

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 think your Task class and all the classes that inherit from it are coded very well. Since Task has so many child classes, you could consider Javadoc comments for convention's sake.

Comment thread src/main/java/Brave.java Outdated
public class Brave {
public static void main(String[] args) {
String input;
String[] splitInput;

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 agree with mafpovul; perhaps a plural would be better here?

Comment thread src/main/java/TaskManager.java Outdated
public void unmarkTask(int taskIndex) {
this.tasks[taskIndex].unmarkAsDone();
System.out.println("OK, I've marked this task as not done yet:");
System.out.println(this.tasks[taskIndex].getStatusIcon() + " " + this.tasks[taskIndex].getDescription());

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 format is generally great and neatly following the standards. Can change lines when the text to print is too long.

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

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.

The format is clear and neat! Maybe you can use a string object to store the seperate line, then no need to type the line every time( can secure same length)

Comment thread src/main/java/TaskManager.java Outdated
for (int i=0; i<tasksCount; i++) {
System.out.println(String.format("\t%d.%s %s", i+1,this.tasks[i].getStatusIcon(), this.tasks[i].getDescription() ));
for (int i = 0; i < tasksCount; i++) {
System.out.println(String.format("\t%d.%s %s", i + 1, this.tasks[i].getStatusIcon(), this.tasks[i].getDescription()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice changes to add spaces between operation cahracters.

Comment thread src/main/java/Brave.java Outdated
break;
case "unmark":
tasks.unmarkTask(Integer.parseInt(splitInput[1]) - 1);
tasks.unmarkTask(Integer.parseInt(splitInput[1]) - 1); // 0 indexing

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 to see more comments. It's clear for the readers.

Comment thread src/main/java/brave/Brave.java Outdated
Comment on lines +8 to +98
public static void main(String[] args) {
String input;
String[] splitInputs;
String command;
String[] arguments;
String description;
Scanner in = new Scanner(System.in);
TaskManager tasks = new TaskManager();
try {
tasks.initialiseTasks("data/brave.txt");
} catch (FileNotFoundException e) {
System.out.println("File not found");
}

tasks.showWelcomeMessage();
while (true) {
input = in.nextLine();
splitInputs = input.split(" ", 2);
command = splitInputs[0]; //e.g. mark 2 -> take the first word as the command -> "mark"

if (command.equals("bye")) {
tasks.showFarewellMessage();
tasks.saveTask("data/brave.txt");
break;
}

switch (command) {
case "list":
tasks.printTaskList();
break;
case "mark":
try {
tasks.markTask(Integer.parseInt(splitInputs[1]) - 1); // 0 indexing
} catch (NumberFormatException e) {
System.out.println("Please put in integer value");
} catch (NullPointerException | ArrayIndexOutOfBoundsException e) {
System.out.println("Please put in valid number of task");
}
break;
case "unmark":
try {
tasks.unmarkTask(Integer.parseInt(splitInputs[1]) - 1); // 0 indexing
} catch (NumberFormatException e) {
System.out.println("Please put in integer value");
} catch (NullPointerException | ArrayIndexOutOfBoundsException e) {
System.out.println("Please put in valid number of task");
}
break;
case "todo":
try {
description = splitInputs[1];
tasks.addTask(new Todo(description));
} catch (IndexOutOfBoundsException e) {
System.out.println(" ☹ OOPS!!! The description of a todo cannot be empty.");
}
break;
case "deadline":
// To-do validate arguments~
arguments = splitInputs[1].split(" /by ", 2);
description = arguments[0];
String by = arguments[1];
tasks.addTask(new Deadline(description, by));
break;
case "event":
// To-do validate arguments~
arguments = splitInputs[1].split(" /at ", 2);
description = arguments[0];
String eventTime = arguments[1];
tasks.addTask(new Event(description, eventTime));
break;
case "delete":
try {
tasks.deleteTask(Integer.parseInt(splitInputs[1]) - 1); // 0 indexing
} catch (NumberFormatException e) {
System.out.println("Please put in integer value");
} catch (NullPointerException | ArrayIndexOutOfBoundsException e) {
System.out.println("Please put in valid number of task");
}
break;
default:
try {
throw new IllegalArgumentException();
} catch (IllegalArgumentException e) {
System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
System.out.println("Available command are -> list/mark/unmark/todo/deadline/event");
}
break;
}
}
}
}

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 method is too long, perhaps you might want to SLAP it.

Comment thread src/main/java/brave/TaskManager.java Outdated
Comment on lines +40 to +43
if (details[1].equals("1")) {
selected_task = tasks.get(taskIndex);
selected_task.markAsDone();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Repetative code, perhaps you can find a way to code it once only?

Comment thread src/main/java/brave/Brave.java Outdated
Scanner in = new Scanner(System.in);
TaskManager tasks = new TaskManager();
try {
tasks.initialiseTasks("data/brave.txt");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Magic literal here, you might want to place it as a static constant.

Comment thread src/main/java/brave/TaskManager.java Outdated
Comment on lines +11 to +15
// public static final int MAX_TASK = 100;
public static final String LINE_SPLIT = "\t____________________________________________________________";
private final ArrayList<Task> tasks = new ArrayList<>();
// private final Task[] tasks = new Task[MAX_TASK];
// private int tasksCount = 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.

Remember to remove unneccesary comments before you commit

Comment thread src/main/java/brave/Brave.java Outdated
Comment on lines +88 to +94
try {
throw new IllegalArgumentException();
} catch (IllegalArgumentException e) {
System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
System.out.println("Available command are -> list/mark/unmark/todo/deadline/event");
}
break;

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 don't think you need to throw a new IllegalArgumentException here, just printing will do.

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