Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[azfarulmatin] IP #70

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

azfarulmatin
Copy link

No description provided.

Copy link

@ryanlohyr ryanlohyr left a comment

Choose a reason for hiding this comment

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

Overall great job but some improvements to work on:)

// Check for any inputs with '/'
int checkSlash = userInput.indexOf("/");
if (checkSlash != -1) {
description = userInput.substring(type.length() + 1, checkSlash).trim();

Choose a reason for hiding this comment

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

Could this be refactored into a function? As we repeat it twice

userInput = scanner.nextLine();
System.out.println(LINE);

if (userInput.equals("bye")) {

Choose a reason for hiding this comment

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

could this be refactored into a switch statement for better readability?

String by = bracketInfo.replace("/by", "").trim();
tasks[count] = new Deadline(description, by);
} else if (type.equals("Event")) {
String from = bracketInfo.split("/from")[1].split("/to")[0].trim();

Choose a reason for hiding this comment

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

The code is relatively concise, but it might benefit from some additional comments or variable names to make it more self-explanatory. For example, you could define variables with more descriptive names for the split values.

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

Choose a reason for hiding this comment

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

The code uses string concatenation to build the final string for the object's representation. While this approach works, it can be a bit less readable, especially when dealing with multiple string elements. Consider using String.format() for improved readability and performance.

Copy link

@janelleenqi janelleenqi 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 JOB! There are some minor changes you can make for readability and organisation (using a switch statement sounds good!). You did well commenting each function and following the naming conventions!

this.description = description;
this.isDone = false;
}
public void markAsDone() {

Choose a reason for hiding this comment

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

you can consider spacing out (added new lines between) your functions for better readability

}
}

class Deadline extends Task {

Choose a reason for hiding this comment

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

having a new file for each class can keep your code more organised (abstraction)

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

Choose a reason for hiding this comment

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

you can consider combining this to become a setter method like "void setFound(boolean isFound);"


class Task {
protected String description;
protected boolean isDone;

Choose a reason for hiding this comment

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

You did well in following the naming conventions (PascalCase for class and camelCase for variables)!!

}
}

// Mark a task as done

Choose a reason for hiding this comment

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

Great job in explicitly commenting on the purpose of functions you added!

Copy link

@NaychiMin NaychiMin left a comment

Choose a reason for hiding this comment

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

Overall, your coding quality is very good, just small minor suggestions, not errors! Keep it up! 💯

Comment on lines 30 to 31
return "[X] "
+ description;

Choose a reason for hiding this comment

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

Any reason for separating it on different lines? It's a rather short line :)

// Create a task of a specific type to the tasks array
private static void addTask(String userInput, Task[] tasks, int count, String type) {
String description;
String bracketInfo;

Choose a reason for hiding this comment

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

Perhaps there might be a better more suggestive naming of the variable?

String description;
String bracketInfo;

// Check for any inputs with '/'

Choose a reason for hiding this comment

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

I like how you added comments for easier readability! 👍

+ LINE);

Scanner scanner = new Scanner(System.in);
Task[] tasks = new Task[100];

Choose a reason for hiding this comment

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

Good job on always having proper naming of functions, classes and variables! 👍

Copy link

@YongbinWang YongbinWang 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 job on your ip so far. Coding standard and code quality are alright. Try to structure your classes such that it only does one specific role. For example, your exceptions should be separated from your duke class. Keep up the good work!

Comment on lines 6 to 76
public void run() {
String LINE = "__________________________________________\n";
System.out.println(LINE
+ "Hello I'm MatinBot\n"
+ "What can I do for you?\n"
+ LINE);

Scanner scanner = new Scanner(System.in);
Task[] tasks = new duke.Task[100];
int count = 0;
String userInput;

while (true) {
// Get the user input first
userInput = scanner.nextLine();
System.out.println(LINE);

try {
if (userInput.equals("bye")) {
break;
} else if (userInput.equals("list")) {
printTasks(tasks, count);
} else if (userInput.startsWith("mark")) {
markTask(userInput, tasks, count);
} else if (userInput.startsWith("unmark")) {
unmarkTask(userInput, tasks, count);
} else if (userInput.startsWith("todo")) {
String description = userInput.replaceFirst("todo", "").trim();
if (description.isEmpty()) {
throw new EmptyDescriptionException("todo");
}
addTask("todo " + description, tasks, count, "todo");
count++;
} else if (userInput.startsWith("deadline")) {
String description = userInput.replaceFirst("deadline", "").trim();
if (description.isEmpty()) {
throw new EmptyDescriptionException("deadline");
}
// Check for /by in the description
if (!description.contains("/by")) {
System.out.println("☹ OOPS!!! The deadline task must include '/by' to specify the date.");
} else {
addTask("deadline " + description, tasks, count, "deadline");
count++;
}
} else if (userInput.startsWith("event")) {
String description = userInput.replaceFirst("event", "").trim();
if (description.isEmpty()) {
throw new EmptyDescriptionException("event");
}
// Check for /from and /to in the description
if (!description.contains("/from") || !description.contains("to")) {
System.out.println("☹ OOPS!!! The event task must include '/from' and '/to' to specify the date range.");
} else {
addTask("event " + description, tasks, count, "event");
count++;
}
} else {
throw new UnknownCommandException();
}
} catch (EmptyDescriptionException e) {
System.out.println(e.getMessage());
} catch (UnknownCommandException e) {
System.out.println(e.getMessage());
}
System.out.println(LINE);
}

System.out.println("Bye. Hope to see you again soon!\n" + LINE);
scanner.close();
}

Choose a reason for hiding this comment

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

Consider abstracting away some of the heavy logic to reduce long methods. Generally more than 30 lines is too long.


Scanner scanner = new Scanner(System.in);
Task[] tasks = new duke.Task[100];
int count = 0;

Choose a reason for hiding this comment

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

Consider using a more suitable variable name to keep track of your number of tasks.

Comment on lines 93 to 94
switch (type) {
case "todo":

Choose a reason for hiding this comment

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

Violation of coding standard here, there should not be an indentation for the case clause.

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