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

[Varun] iP #198

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

[Varun] iP #198

wants to merge 48 commits into from

Conversation

flerovious
Copy link

No description provided.

Copy link

@astralum astralum left a comment

Choose a reason for hiding this comment

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

Excellent work! After some modifications, it'll become even more readable and clear :)

@@ -0,0 +1,14 @@
public class Event extends Task{
private static String SYMBOL = "E";
Copy link

Choose a reason for hiding this comment

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

Could the name be more descriptive?

while (true) {
String command = input.nextLine();

// parse and handle commands
Copy link

Choose a reason for hiding this comment

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

Do you think you can put this logic in a different method?

String eventTime = parsedInput[1].strip();
TaskManager.addEvent(eventTitle, eventTime);
} else {
// handle invalid command
Copy link

Choose a reason for hiding this comment

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

This comment is helpful :)

@@ -0,0 +1,47 @@
public class TaskManager {
private static int taskNo = 0;
final private static int maxTasks = 100;
Copy link

Choose a reason for hiding this comment

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

Perhaps a more informative name would be maxTasksNo to keep in line with taskNo, or name those two constants such that they sound similar

addTask(todo);
}

static void addDeadline(String deadlineName, String deadlineDue) {
Copy link

Choose a reason for hiding this comment

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

Perhaps for the second parameter, you can use the same name as in Deadline.java (in this case it is dueDate), or a similar one in style with deadlineName

String command = input.nextLine();

// parse and handle commands
if (command.equals(EXIT_CMD)) {
Copy link

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 constants here! Makes it clear and easy to change

// handle invalid command
System.out.println("Invalid command! Please enter a valid command");
}
}

Choose a reason for hiding this comment

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

maybe you could try to refactor the code to avoid long methods( above 30 LOC)

Event event = new Event(eventName, eventTime);
addTask(event);
}

Choose a reason for hiding this comment

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

good use of refactoring to split the subtasks creation into 3 functions

@@ -0,0 +1,12 @@
public class Todo extends Task {
private static String SYMBOL = "T";

Choose a reason for hiding this comment

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

i dont think it is a constant name , just a variable name but im not sure

for (int i = 0; i < taskNo; ++i) {
Task task = tasks[i];
System.out.printf("%d. %s\n", i + 1, task);
}

Choose a reason for hiding this comment

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

should stick to using printf or println not both as it is confusing

Copy link

@arvejw arvejw left a comment

Choose a reason for hiding this comment

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

Overall it is a good implementation. Basically whether certain variables are constants is vague as capitalized variable name implies a constant which should be set as a final variable

Comment on lines 4 to 9
public static String EXIT_CMD = "bye";
public static String LIST_CMD = "list";
public static String DONE_CMD = "done";
public static String TODO_CMD = "todo";
public static String DEADLINE_CMD = "deadline";
public static String EVENT_CMD = "event";
Copy link

Choose a reason for hiding this comment

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

Perhaps you should make these variables final variables as well. From the naming convention used I am assuming you intend for these to be constants, but I may be misunderstanding something.

@@ -0,0 +1,14 @@
public class Deadline extends Task{
private static String SYMBOL = "D";
Copy link

Choose a reason for hiding this comment

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

Perhaps this should be a final variable as I presume the SYMBOL is supposed to be a fixed constant

Choose a reason for hiding this comment

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

@arvejw is correct, as seen in the coding standards or code quality guidelines. The final keyword is to indicate that the String SYMBOL will never change. You can take a look at all constants and make sure they adhere to this.

String command = input.nextLine();

// parse and handle commands
if (command.equals(EXIT_CMD)) {
Copy link

Choose a reason for hiding this comment

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

As pointed out by others, very nice intuitive way of managing the various commands as the reader easily understands what command each code block carries out

Comment on lines 24 to 26
String parsedInput = command.split(" ")[1];
int taskNo = Integer.parseInt(parsedInput);
TaskManager.markTaskNoAsDone(taskNo - 1);
Copy link

Choose a reason for hiding this comment

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

Perhaps you might consider extracting out the execution of the commands into their own separate method

@@ -0,0 +1,14 @@
public class Event extends Task{
private static String SYMBOL = "E";
Copy link

@arvejw arvejw Sep 3, 2021

Choose a reason for hiding this comment

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

Similar to previous comments about constants, you can consider making this a final variable as its value should not be changing

String eventTime = parsedInput[1].strip();
TaskManager.addEvent(eventTitle, eventTime);
} else {
// handle invalid command
Copy link

Choose a reason for hiding this comment

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

good indentation of comment

public class Duke {
public static String EXIT_CMD = "bye";
Copy link

Choose a reason for hiding this comment

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

Good use of constants.

String deadlineDue = parsedInput[1].strip();
TaskManager.addDeadline(deadlineTitle, deadlineDue);
} else if (command.startsWith(EVENT_CMD)) {
String [] parsedInput = command.replaceFirst(EVENT_CMD, "").split("/at ");
Copy link

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.

Choose a reason for hiding this comment

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

@yzhedwin is correct, following coding standards.

if (taskNo < maxTasks) {
tasks[taskNo] = task;
taskNo++;

Copy link

Choose a reason for hiding this comment

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

I think don't really need a new line

} else if (command.startsWith(DONE_CMD)) {
String parsedInput = command.split(" ")[1];
int taskNo = Integer.parseInt(parsedInput);
TaskManager.markTaskNoAsDone(taskNo - 1);
Copy link

Choose a reason for hiding this comment

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

Variable could be better named for less ambiguity. Overall good adherence to coding standard!

Copy link

@hughjazzman hughjazzman left a comment

Choose a reason for hiding this comment

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

Do complete the week's tasks as soon as possible. 👍

@@ -0,0 +1,14 @@
public class Deadline extends Task{
private static String SYMBOL = "D";

Choose a reason for hiding this comment

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

@arvejw is correct, as seen in the coding standards or code quality guidelines. The final keyword is to indicate that the String SYMBOL will never change. You can take a look at all constants and make sure they adhere to this.

@@ -0,0 +1,14 @@
public class Deadline extends Task{

Choose a reason for hiding this comment

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

Perhaps there should be a space before the bracket? Similar for other classes.

Suggested change
public class Deadline extends Task{
public class Deadline extends Task {

@@ -0,0 +1,2 @@
public class AddTaskException extends DukeException{

Choose a reason for hiding this comment

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

Suggested change
public class AddTaskException extends DukeException{
public class AddTaskException extends DukeException {

Comment on lines 4 to 9
public static String EXIT_CMD = "bye";
public static String LIST_CMD = "list";
public static String DONE_CMD = "done";
public static String TODO_CMD = "todo";
public static String DEADLINE_CMD = "deadline";
public static String EVENT_CMD = "event";

Choose a reason for hiding this comment

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

Perhaps these commands being grouped together could have a common prefix? Following coding standards:

Associated constants should have a common prefix.

Suggested change
public static String EXIT_CMD = "bye";
public static String LIST_CMD = "list";
public static String DONE_CMD = "done";
public static String TODO_CMD = "todo";
public static String DEADLINE_CMD = "deadline";
public static String EVENT_CMD = "event";
public static final String CMD_EXIT = "bye";
public static final String CMD_LIST = "list";
public static final String CMD_DONE = "done";
public static final String CMD_TODO = "todo";
public static final String CMD_DEADLINE = "deadline";
public static final String CMD_EVENT = "event";

@@ -0,0 +1,2 @@
public class DeadlineException extends DukeException{

Choose a reason for hiding this comment

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

Suggested change
public class DeadlineException extends DukeException{
public class DeadlineException extends DukeException {

public class TaskManager {
private static int taskNo = 0;
final private static int maxTasks = 100;
final static Task[] tasks = new Task[maxTasks];

Choose a reason for hiding this comment

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

Perhaps this should be private, following the encapsulation paradigm of OOP?

Suggested change
final static Task[] tasks = new Task[maxTasks];
private static final Task[] tasks = new Task[MAX_TASKS];

final private static int maxTasks = 100;
final static Task[] tasks = new Task[maxTasks];

static void addTask(Task task) {

Choose a reason for hiding this comment

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

Consider updating the modifiers for the methods in this class. The default scope of methods in Java is package-private. Having them be static may not be advantageous as well, which you may learn later on.

System.out.println("Here are the tasks in your list:");
for (int i = 0; i < taskNo; ++i) {
Task task = tasks[i];
System.out.printf("%d. %s\n", i + 1, task);

Choose a reason for hiding this comment

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

This is not too big a deal (printf vs println), though you can consider simply sticking to print (not printf) as Java has its own handy toString methods that can convert Integer for you. I believe printf may be a habit from C.

Suggested change
System.out.printf("%d. %s\n", i + 1, task);
System.out.println((i + 1) + ". " + task);

@@ -0,0 +1,2 @@
public class TodoException extends DukeException{

Choose a reason for hiding this comment

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

Suggested change
public class TodoException extends DukeException{
public class TodoException extends DukeException {

final static Task[] tasks = new Task[maxTasks];

static void addTask(Task task) {
if (taskNo < maxTasks) {

Choose a reason for hiding this comment

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

You can consider making the happy path prominent here.

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.

7 participants