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

[andreusxcarvalho] iP #108

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

Conversation

andreusxcarvalho
Copy link

No description provided.

System.out.println("Type 'list show' to display all items in the list.");
System.out.println("Type 'mark <number>' to mark a task as done.");
System.out.println("Type 'unmark <number>' to mark a task as not done.");
System.out.println("_______________________________________");
Copy link

Choose a reason for hiding this comment

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

Would it be better to store the greeting string as a constant instead of directly printing it?
In the event we need to change the System.out.println function to something else it would be easier + avoid magic number scenario

}

// Task class to represent each task in the list
static class Task {
Copy link

Choose a reason for hiding this comment

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

Should multiple classes be separated into different files for readability?

System.out.println("Item added to the list: " + item);
}

private static void showList() {
Copy link

Choose a reason for hiding this comment

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

The abstraction of the various features into various functions made the code easier to read. Well done!

private static void handleListInput(String input) {
String[] parts = input.split(" ", 2); // Split the input into command and item

if (parts.length > 1) {
Copy link

Choose a reason for hiding this comment

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

I think you can avoid arrowhead style code by using guard clauses. In each if statement, you return after the function was run. This way, you don't need an if else if chain

Copy link

@gskang-22 gskang-22 left a comment

Choose a reason for hiding this comment

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

Good work. Overall your code looks concise and free of mistakes.

Comment on lines 9 to 30
public static void main(String[] args) {
greetUser(); // Method to greet the user

Scanner scanner = new Scanner(System.in); // Use the imported Scanner class
String input = "";

while (!input.equals("bye")) {
input = scanner.nextLine();

if (input.startsWith("list")) {
handleListInput(input);
} else if (input.startsWith("mark ")) {
markTaskAsDone(input);
} else if (input.startsWith("unmark ")) {
markTaskAsNotDone(input);
} else {
echo(input); // Call echo method to repeat the input
}
}

exit();
}

Choose a reason for hiding this comment

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

I like how your statements are at the same level of abstraction

Comment on lines 31 to 40

private static void greetUser() {
System.out.println("_______________________________________");
System.out.println("Hello! I'm ANDY");
System.out.println("What can I do for you?");
System.out.println("Type 'list' followed by an item to add it to the list.");
System.out.println("Type 'list show' to display all items in the list.");
System.out.println("Type 'mark <number>' to mark a task as done.");
System.out.println("Type 'unmark <number>' to mark a task as not done.");
System.out.println("_______________________________________");

Choose a reason for hiding this comment

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

Would it be better to use a single println() function with concatenation instead of having multiple println() functions?

Comment on lines 110 to 136
static class Task {
private String description;
private boolean isDone;

public Task(String description) {
this.description = description;
this.isDone = false;
}

public String getDescription() {
return description;
}

public boolean isDone() {
return isDone;
}

public void setDone(boolean done) {
isDone = done;
}

@Override
public String toString() {
return (isDone ? "[X] " : "[ ] ") + description;
}
}
}

Choose a reason for hiding this comment

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

Would it be better to move your classes into their own files (AKA Task.java) to make your code more organized?

Comment on lines 78 to 86
try {
int taskNumber = Integer.parseInt(input.split(" ")[1]) - 1;
itemList.get(taskNumber).setDone(true);
System.out.println("Nice! I've marked this task as done:");
System.out.println("[X] " + itemList.get(taskNumber).getDescription());
} catch (Exception e) {
System.out.println("Invalid task number. Please try again.");
}
}

Choose a reason for hiding this comment

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

I like how you use try and catch statements to catch errors and prevent your code from crashing


public class Andy {

private static List<Task> itemList = new ArrayList<>(); // List to store tasks
Copy link

@joshuan98 joshuan98 Sep 16, 2024

Choose a reason for hiding this comment

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

This can be renamed to taskList to be more descriptive.

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