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

[kristianachwan] iP #204

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

Conversation

kristianachwan
Copy link

No description provided.

);
String inputText;
String outputMessage;
while (true) {
Copy link

Choose a reason for hiding this comment

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

Should this method be divided? For example, mark method, unmark method can be seperated from this method.

this.isDone = true;
}
public void unmarkAsDone () {
this.isDone = false;
Copy link

Choose a reason for hiding this comment

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

Should this be indented?

@@ -0,0 +1,40 @@
public class Task {
protected String description;
Copy link

Choose a reason for hiding this comment

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

I like how you used protected variables instead of public!

this.deadlineBy = deadlineBy;
}

@Override
Copy link

Choose a reason for hiding this comment

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

I like how you used @OverRide to make sure that you are properly overriding method from its parent

public class Task {
protected String description;
protected boolean isDone;
static int numberOfTasks = 0;
Copy link

Choose a reason for hiding this comment

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

Maybe numberOfTasks can be protected variable too, so that it can only be acceessed by get method:)

Copy link

@ArtemiszenN ArtemiszenN left a comment

Choose a reason for hiding this comment

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

Overall the code works well I think, but it is quite cluttered and readability could be improved.

Comment on lines 22 to 68
while (true) {
inputText = scanner.nextLine();
if (inputText.equals("list")) {
outputMessage = Task.getTasksList(tasks);
} else if (inputText.startsWith("mark")) {
int taskIndex = getTaskIndexFromInput(inputText);
tasks[taskIndex].markAsDone();
outputMessage = "Nice! I've marked this task as done: " + "\n\t\t"
+ tasks[taskIndex].toString();
} else if (inputText.startsWith("unmark")) {
int taskIndex = getTaskIndexFromInput(inputText);
tasks[taskIndex].unmarkAsDone();
outputMessage = "Ok, I've marked this task as not done: " + "\n\t\t"
+ tasks[taskIndex].toString();
} else if (inputText.startsWith("task")) {
String taskDescription = inputText.split("/")[0].split("task")[1].trim();
Task newTask = new Task(taskDescription);
tasks[Task.numberOfTasks - 1] = newTask;
outputMessage = TASK_ADDED_PREFIX + newTask.toString() + "\n\t"
+ getTaskAddedPostfix();
} else if (inputText.startsWith("todo")) {
String toDoDescription = inputText.split("/")[0].split("todo")[1].trim();
Task newTodo = new ToDo(toDoDescription);
tasks[Task.numberOfTasks - 1] = newTodo;
outputMessage = TASK_ADDED_PREFIX + newTodo.toString() + "\n\t"
+ getTaskAddedPostfix();
} else if (inputText.startsWith("deadline")) {
String deadlineDescription = inputText.split("/")[0].split("deadline")[1].trim();
String deadlineBy = inputText.split("/")[1].trim();
Task newDeadline = new Deadline(deadlineDescription, deadlineBy);
tasks[Task.numberOfTasks - 1] = newDeadline;
outputMessage = TASK_ADDED_PREFIX + newDeadline.toString() + "\n\t"
+ getTaskAddedPostfix();
} else if (inputText.startsWith("event")) {
String eventDescription = inputText.split("/")[0].split("event")[1].trim();
String eventStart = inputText.split("/")[1].trim();
String eventEnd = inputText.split("/")[2].trim();
Task newEvent = new Event(eventDescription, eventStart, eventEnd);
tasks[Task.numberOfTasks - 1] = newEvent;
outputMessage = TASK_ADDED_PREFIX + newEvent.toString() + "\n\t"
+ getTaskAddedPostfix();
} else if (inputText.equals("bye")) {
outputMessage = "Bye. Hope to see you again soon!";
break;
} else {
outputMessage = "Sorry, I don't understand what you said. Can you say it again?";
}

Choose a reason for hiding this comment

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

Should these be extracted into different functions?

Comment on lines 16 to 22
public static String getTasksList(Task[] tasks){
String tasksList = "";
for (int i = 0; i < numberOfTasks; i++) {
tasksList += String.format("%3d. ", (i+1)) + tasks[i].toString() + "\n\t";
}
return tasksList;
}

Choose a reason for hiding this comment

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

Should this function be stored outside? Or the class be changed to a TaskList which includes the array of tasks?

Comment on lines 5 to 6
static Task[] tasks = new Task[100];
static final String TASK_ADDED_PREFIX = "Got it. I've added this task:\n\t";

Choose a reason for hiding this comment

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

Should these variables be explicitly stated public/protected/private?

this.isDone = true;
}
public void unmarkAsDone () {
this.isDone = false;

Choose a reason for hiding this comment

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

Should this line be indented?

outputMessage = TASK_ADDED_PREFIX + newEvent.toString() + "\n\t"
+ getTaskAddedPostfix();
} else if (inputText.equals("bye")) {
outputMessage = "Bye. Hope to see you again soon!";

Choose a reason for hiding this comment

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

Should this line (and other similar lines) have a newline added?

@@ -0,0 +1,15 @@
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 you can look into using the auto formatting feature in Intellij to standardise the spaces after the curly brackets.

public class Duke {
static 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.

Perhaps look into using an ArrayList might be better? It allows the array to be dynamically sized.

String outputMessage;
while (true) {
inputText = scanner.nextLine();
if (inputText.equals("list")) {

Choose a reason for hiding this comment

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

I feel that using a switch statement might make the code cleaner and easier to read.

String toDoDescription = inputText.split("/")[0].split("todo")[1].trim();
Task newTodo = new ToDo(toDoDescription);
tasks[Task.numberOfTasks - 1] = newTodo;
outputMessage = TASK_ADDED_PREFIX + newTodo.toString() + "\n\t"

Choose a reason for hiding this comment

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

Good job on using UPPERCASE for constants.

Copy link

@maanyos maanyos 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 compliance with code standards
please work on the object-orientedness of the code, currently most of the logic is contained in Duke which makes it hard to read and trace through.
try creating new classes for command, parser etc and refactor code accordingly.
refer to addressbook3 if required

printDuke();
String input;
String outputMessage;
while (true) {
Copy link

Choose a reason for hiding this comment

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

use condition here instead of system.Exit later

private static final String DUKE_PREFIX = "Duke Error: ";


public static String[] parseCommand (String command) throws InvalidCommandException{
Copy link

Choose a reason for hiding this comment

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

why is there parseCommand in exception class?

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