-
Notifications
You must be signed in to change notification settings - Fork 116
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
base: master
Are you sure you want to change the base?
[andreusxcarvalho] iP #108
Conversation
src/main/java/Andy.java
Outdated
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("_______________________________________"); |
There was a problem hiding this comment.
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
src/main/java/Andy.java
Outdated
} | ||
|
||
// Task class to represent each task in the list | ||
static class Task { |
There was a problem hiding this comment.
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?
src/main/java/Andy.java
Outdated
System.out.println("Item added to the list: " + item); | ||
} | ||
|
||
private static void showList() { |
There was a problem hiding this comment.
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!
src/main/java/Andy.java
Outdated
private static void handleListInput(String input) { | ||
String[] parts = input.split(" ", 2); // Split the input into command and item | ||
|
||
if (parts.length > 1) { |
There was a problem hiding this comment.
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
There was a problem hiding this 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.
src/main/java/Andy.java
Outdated
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(); | ||
} |
There was a problem hiding this comment.
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
src/main/java/Andy.java
Outdated
|
||
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("_______________________________________"); |
There was a problem hiding this comment.
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?
src/main/java/Andy.java
Outdated
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; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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?
src/main/java/Andy.java
Outdated
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."); | ||
} | ||
} |
There was a problem hiding this comment.
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
src/main/java/Andy.java
Outdated
|
||
public class Andy { | ||
|
||
private static List<Task> itemList = new ArrayList<>(); // List to store tasks |
There was a problem hiding this comment.
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.
Added Javadoc comments to all relevant classes
No description provided.