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

[TrungBui32] iP #112

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

Conversation

TrungBui32
Copy link

No description provided.

Copy link

@Yisoong Yisoong left a comment

Choose a reason for hiding this comment

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

Looks good overall but you might want to rename some of your variables for greater clarity. Good Job !!

private static int last_index = 0;

public static void echo(String msg) {
System.out.println("____________________________________________________________\n");
Copy link

Choose a reason for hiding this comment

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

I noticed that this was repeated many times. Perhaps it would be good to use a utility function to print the horizontal lines instead.


public class Poirot {
private static Task[] list_actions = new Task[100];
private static int last_index = 0;
Copy link

Choose a reason for hiding this comment

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

Perhaps it would be better to use lastIndex instead of last_index.

System.out.println("Hello! I'm POIROT\n");
System.out.println("What can I do for you?");
System.out.println("____________________________________________________________\n");
boolean working = true;
Copy link

Choose a reason for hiding this comment

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

Since this is a boolean, it might be better to call it "isWorking".

System.out.println("____________________________________________________________\n");
}

public static void add(Task action) {
Copy link

Choose a reason for hiding this comment

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

"add" is a bit ambiguous. It might be better to use "addTask" instead.

Copy link

@TPH777 TPH777 left a comment

Choose a reason for hiding this comment

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

Coding standards and code quality is not strictly followed, improvements can be made

private static int last_index = 0;

public static void echo(String msg) {
System.out.println("____________________________________________________________\n");
Copy link

Choose a reason for hiding this comment

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

Abstracting the printing of divider to a function will improve readability


public class Poirot {
private static Task[] list_actions = new Task[100];
private static int last_index = 0;
Copy link

Choose a reason for hiding this comment

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

size may be a better name than last_index

import java.util.Scanner;

public class Poirot {
private static Task[] list_actions = new Task[100];
Copy link

Choose a reason for hiding this comment

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

Use camelCase for variables, E.g. listActions, but a better name will be tasks

} else {
System.out.println("____________________________________________________________\n");
for (int i = 0; i < last_index; i++) {
System.out.println((i + 1) + ".[" + list_actions[i].getStatusIcon() + "]" + list_actions[i].getDescription());
Copy link

Choose a reason for hiding this comment

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

Abstract this to a function and give variable names for list_actions[i].getStatusIcon() and list_actions[i].getDescription to improve code readability

System.out.println("____________________________________________________________\n");
break;
case "unmark":
int y = Integer.parseInt(list_input[1]) - 1;
Copy link

Choose a reason for hiding this comment

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

Set a variable for list_input[1] as it is unclear what is that

System.out.println("____________________________________________________________\n");
break;
case "unmark":
int y = Integer.parseInt(list_input[1]) - 1;
Copy link

Choose a reason for hiding this comment

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

use a better name instead of y

Copy link

@Mahesh1772 Mahesh1772 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!

The code looks clean and solid. Try to make use of inheritance even more in your code as OOP make coding more scalable and easier to manage. Consider adding JavaDocs in the future commits

}
@Override
public String toFileString() {
return "D | " + (isDone ? "1" : "0") + " | " + description + " | " + by;

Choose a reason for hiding this comment

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

Consider adding the description in the parent classes toFIleString() to make full use of the inheritance principles


@Override
public String toString() {
return "[E][" + getStatusIcon() + "] " + description + " (from: " + from + " to: " + to + ")";

Choose a reason for hiding this comment

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

Consider adding the description in the parent classes toFIleString() to make full use of the inheritance principles

public static final String LINE = "____________________________________________________________\n";
private static Task[] tasks = new Task[100];
private static final String FILE_PATH = "./data/duke.txt";
private static int last_index = 0;

Choose a reason for hiding this comment

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

Consider naming the variables with more than one word in camelCase

@@ -0,0 +1,204 @@
import java.io.*;

Choose a reason for hiding this comment

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

Try not to use the * to import everything. Instead explicitly import what is needed.

Comment on lines 18 to 19
public abstract String toString();
public abstract String toFileString();

Choose a reason for hiding this comment

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

Consider making then non abstract methods, as they can be easily utilized by sub-classes. As such, Task could not be a abstract class.

Comment on lines 134 to 151
tasks[x].setDone(true);
System.out.println(LINE);
System.out.println("Nice! I've marked this task as done:\n");
System.out.print("[" + tasks[x].getStatusIcon() + "] ");
System.out.println(tasks[x].getDescription());
System.out.println(LINE);
saveTasksToFile(); // Save the task after marking it
break;
case "unmark":
validateTaskNumber(list_input);
int y = Integer.parseInt(list_input[1]) - 1;
tasks[y].setDone(false);
System.out.println(LINE);
System.out.println("OK, I've marked this task as not done yet:\n");
System.out.print("[" + tasks[y].getStatusIcon() + "] ");
System.out.println(tasks[y].getDescription());
System.out.println(LINE);
saveTasksToFile();

Choose a reason for hiding this comment

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

Consider saving the string formatted with the current isDone in a separate method inside Task class to reduce duplicate lines of code


boolean working = true;
Scanner scan = new Scanner(System.in);
while (working) {

Choose a reason for hiding this comment

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

Consider doing a saving changes to file at the end of each iteration, as such avoiding to call it every time something is changed, reduce duplicate lines

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