Skip to content

[Bui Gia Nhat Minh] iP#182

Open
minhbgn wants to merge 24 commits intonus-cs2113-AY2425S2:masterfrom
minhbgn:master
Open

[Bui Gia Nhat Minh] iP#182
minhbgn wants to merge 24 commits intonus-cs2113-AY2425S2:masterfrom
minhbgn:master

Conversation

@minhbgn
Copy link
Copy Markdown

@minhbgn minhbgn commented Feb 6, 2025

No description provided.

Copy link
Copy Markdown

@wentuoc wentuoc left a comment

Choose a reason for hiding this comment

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

Overall good readability with a clear and logial sequence! Just a few nits to pick. Good job :)


while (!input.equals("bye")) {

int space = input.indexOf(' ');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would a more descriptive variable name such as spaceIndex be better?


private final ArrayList<Item> itemList = new ArrayList<Item>();

public void 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.

I like the use of abstraction to manage the different stages of the program!


public Deadline(String name, boolean done){
super(name, done);
String newname = name.replace("/by","(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.

Should the by field be extracted out and stored as a separate attribute so that it can be accessed and modified when necessary? (e.g. say if I want to change the due date)


public class Item {
protected String name;
protected boolean 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.

Would it be better to use isDone as the name for this boolean variable?

while (!input.equals("bye")) {

int space = input.indexOf(' ');
boolean foundSpace = (space > 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.

I like the use of these boolean variables to simplify the expression in the if condition later on!

while (i < itemList.size()) {
if (itemList.get(i).isDone()){
itemList.remove(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.

Can consider adhering to K&R style for curly braces

package Item;

public class Item {
protected String name;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could've considered using a more descriptive name for the String variable


@Override
public String toString() {
if (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.

Perhaps could've used a ternary operator instead?


public class Roboast {
private static final String BOT_NAME = "Roboast";
private static final String LINE = "_".repeat(50);
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 instead of typing the "_" out, you just used the repeat method.

String content = input.substring(space+1);
if (command.equals("setDone")){
mark(content, true);
}
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 you should be more consistent with the spacing before the "{" if you want to add a space before it or not.

Copy link
Copy Markdown

@sevenseasofbri sevenseasofbri left a comment

Choose a reason for hiding this comment

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

Good job so far! You might need to work on following the layout accoridng to the java coding standard though.

@@ -0,0 +1,57 @@
package diskIO;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

From java coding standard: Names representing packages should be in all lower case.

Consider making the package name something like storage or disk.io

Comment on lines +14 to +39
super(name, done);
String newname = name.replace("/by","(by:");
int byIndex = newname.indexOf("(by:");

try {
deadline = newname.substring(byIndex + 5, newname.length() - 1);
}
catch (StringIndexOutOfBoundsException e) {
deadline = null;
}


if (!name.equals(newname)){
newname = newname + ")";
}
super.setItemName(newname);
super.itemType = "Deadline";
}

@Override
public String toString(){
if (super.isDone){
return "[D][X] " + super.itemName;
}
else{
return "[D][ ] " + super.itemName;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps avoid the usage of magic literals by using constants or vars.

try {
eventStartTime = newname.substring(newname.indexOf("(from:") + 6, newname.indexOf("to:") - 1);
eventEndTime = newname.substring(newname.indexOf("to:") + 4);;
}
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-catch blocks should ideally be of the form:

try {
    statements;
} catch (Exception exception) {
    statements;
}

Comment on lines +37 to +42
if (super.isDone){
return "[E][X] " + super.itemName;
}
else{
return "[E][ ] " + super.itemName;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if-else clauses should be of the form:

if (condition) {
    statements;
} else {
    statements;
}

@@ -0,0 +1,50 @@
package item;

public class Event extends Item{
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
public class Event extends Item{
public class Event extends Item {

this.itemList = itemList;
}

public void action(String input) throws RoboastException {
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 is over >30 LOC. Consider refactoring the inner-levels of code into other methods.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Additionally, a method is supposed to be a verb. As such action does not fit this description. Consider calling it applyAction or something.

Comment on lines +23 to +57
try {
command = input.substring(0, spaceIndex);
content = input.substring(spaceIndex + 1);
}
catch (IndexOutOfBoundsException e) {
command = input;
content = "";
}
if (command.equals("mark")) {
mark(content, true);
}
else if (command.equals("unmark")) {
mark(content, false);
}
else if (command.equals("todo")) {
addTodo(content);
}
else if (command.equals("deadline")) {
addDeadlines(content);
}
else if (command.equals("event")) {
addEvents(content);
}
else if (command.equals("list")) {
showItemList();
}
else if (command.equals("deleteAll")) {
deleteAll();
}
else if (command.equals("delete")) {
delete(content);
}
else {
throw new RoboastException("Invalid 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.

Again, the layout of these clauses needs to be adjusted (like mentioned before)

if (condition) {
    statements;
} else if (condition) {
    statements;
} else {
    statements;
}

Comment on lines +107 to +119
public void addDeadlines(String content) {
if (content.isEmpty()){
showAddEmptyError();
return;
}
System.out.println(LINE);
Item item = new Deadline(content, false);
itemList.add(item);
System.out.println("added: " + item.getItemName() + "\n" +
"You now have " + itemList.size() + " tasks\n" + LINE);
}

public void addEvents(String content) {
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 functions refer to events and deadline in plural, but the functions themselves add only 1 event or 1 deadline at a time. Consider naming them addDeadline and addEvent instead.


}

public void mark(String content, boolean isDone) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What is exaclt meant by variable content? Is it the input from the user? Consider naming it something else more intuitive.

if (itemList.get(i).isDone()){
itemList.remove(i);
}
else{
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
else{
else {

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