Skip to content

[irfandeen] iP#178

Open
irfandeen wants to merge 39 commits intonus-cs2113-AY2425S2:masterfrom
irfandeen:master
Open

[irfandeen] iP#178
irfandeen wants to merge 39 commits intonus-cs2113-AY2425S2:masterfrom
irfandeen:master

Conversation

@irfandeen
Copy link
Copy Markdown

No description provided.

Comment on lines +51 to +72
switch (params[0]) {
case "list":
printTaskList(tasks, size);
break;
case "mark":
taskIndex = Integer.parseInt(params[1]);
tasks[taskIndex - 1].markAsDone();
printWithLineBreak("Nice! I've marked this task as done:\n"
+ "\t [" + tasks[taskIndex - 1].getStatusIcon() + "] "
+ tasks[taskIndex - 1].description);
break;
case "unmark":
taskIndex = Integer.parseInt(params[1]);
tasks[taskIndex - 1].unmarkAsDone();
printWithLineBreak("OK, I've marked this task as not done yet:\n"
+ "\t " + "[ ] " + tasks[taskIndex - 1].description);
break;
default:
tasks[size] = new Task(userInput);
size++;
printWithLineBreak("added: " + userInput);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Neat use of switch to handle the commands!

Comment on lines +4 to +37
public static void printLineBreak() {
String lineBreak = "\t_________________________________\n";
System.out.print(lineBreak);
}

public static void printWithLineBreak(String response) {
printLineBreak();
System.out.println("\t" + response);
printLineBreak();
}

public static void printWithoutLineBreak(String response) {
System.out.println("\t" + response);
}

public static void printGreeting() {
String greeting = "Hello! I'm Wall-E!\n" + "\tWhat can I do for you?\n\n";
printWithLineBreak(greeting);
}

public static void printExit() {
String exitMessage = "Bye. Hope to see you again soon!";
printWithLineBreak(exitMessage);
}

public static void printTaskList(Task[] tasks, int size) {
printLineBreak();
printWithoutLineBreak("Here are the tasks in your list: ");
for (int i = 0; i < size; i++) {
printWithoutLineBreak(Integer.toString(i + 1) + ". [" + tasks[i].getStatusIcon() + "] "
+ tasks[i].description);
}
printLineBreak();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Very neat code for the different functions!

Comment on lines +65 to +66
printWithLineBreak("OK, I've marked this task as not done yet:\n"
+ "\t " + "[ ] " + tasks[taskIndex - 1].description);
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 string concatenation for readability!

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! Pay attention to the usage of magic literals in your code.

Comment on lines +12 to +13
File f = new File(filePath);
Scanner s = new Scanner(f);
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 using more intuitive naming, f and s do not explain what the variables entail.

Comment on lines +15 to +34
while (s.hasNext()) {
String[] taskString = s.nextLine().split(",");
boolean isDone = taskString[0].equals("1") ? true : false;
String taskType = taskString[1];
String taskDescription = taskString[2];

if (taskType.equals("T")) {
tasks.add(new Todo(taskDescription));
} else if (taskType.equals("D")) {
String dueDate = taskString[3];
tasks.add(new Deadline(taskDescription, dueDate));
} else if (taskType.equals("E")) {
String fromDate = taskString[3];
String toDate = taskString[4];
tasks.add(new Event(taskDescription, fromDate, toDate));
}

if (isDone) {
tasks.get(listSize).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.

There are many magic literals here, consider using constants instead or if not possible, then add some concise comments on what is happening here.

Comment on lines +70 to +86
try {
FileWriter writer = new FileWriter(f);
for (int i = 0; i < listSize; i++) {
Task t = tasks.get(i);
String status = t.isDone() ? "1" : "0";
writer.write(status + "," + t.getTypeIcon() + "," + t.getDescription());
if (t.getTypeIcon() == "T") {
writer.write("\n");
} else if (t.getTypeIcon() == "D") {
Deadline d = (Deadline) t;
writer.write("," + d.getDueDate() + "\n");
} else if (t.getTypeIcon() == "E") {
Event e = (Event) t;
writer.write("," + e.getStartDate() + "," + e.getEndDate() + "\n");
}
}
writer.close();
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 is around 3 levels of indentation, consider refactoring the internal levels into another method.

import java.util.List;

public class WallE {
private static final int MAX_LIST_SIZE = 100;
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 use of constants.

Comment on lines +12 to +15
private static final String exitMessage = "Bye. Hope to see you again soon!";
private static final String greeting = "Hello! I'm Wall-E!\n" + "\tWhat can I do for you?\n\n";
private static int listSize = 0;
private static final String FILE_NAME = "data.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.

exitMessage and greeting could be considered constants since they technically shouldn't change in the course of the program

Constant names must be all uppercase using underscore to separate words (aka SCREAMING_SNAKE_CASE)

Scanner reader = new Scanner(System.in);
String userInput = reader.nextLine();

// Echoes the input, unless input == bye
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this comment relevant to the program anymore? I suppose the chatbot does not simply echo the entered command anymore.

userInput = reader.nextLine();
}

//putIntoStoredTasks(tasks);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Avoid commenting out dead code, remove it instead.

Comment on lines +136 to +159
for (int i = 1; i < params.length; i++) {
if (params[i].equals("/from")) {
stringType = 1;
} else if (params[i].equals("/to")) {
stringType = 2;
} else {
if (stringType == 0) {
if (eventName.isEmpty()) {
eventName.append(params[i]);
} else {
eventName.append(" ").append(params[i]);
}
} else if (stringType == 1) {
if (startDate.isEmpty()) {
startDate.append(params[i]);
} else {
startDate.append(" ").append(params[i]);
}
} else {
if (endDate.isEmpty()) {
endDate.append(params[i]);
} else {
endDate.append(" ").append(params[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.

This is very deep nesting and can be considered arrowhead code. Try to refactor the internal layers into separate methods.

Comment on lines +174 to +189
for (int i = 1; i < params.length; i++) {
if (params[i].equals("/by")) {
stringType = 2;
} else {
if (stringType == 0) {
if (!deadlineName.isEmpty()) {
deadlineName.append(" ").append(params[i]);
} else {
deadlineName.append(params[i]);
}
} else if (stringType == 2) {
if (!byDate.isEmpty()) {
byDate.append(" ").append(params[i]);
} else {
byDate.append(params[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.

Same with this segment, this is very deep nesting .

Comment on lines +209 to +217
printWithLineBreak("OK, I've marked this task as not done yet:\n"
+ "\t" + tasks.get(taskIndex - 1).toString());
}

private static void markTask(String[] params) {
int taskIndex;
taskIndex = Integer.parseInt(params[1]);
tasks.get(taskIndex - 1).markAsDone();
printWithLineBreak("Nice! I've marked this task as done:\n"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wrapped lines should be indented 8 spaces from their parent line. E.g.:

// from the java coding standards website
if (isReady) {
    setText("Long line split"
            + "into two parts.");
}

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.

3 participants