Open
Conversation
telferang
reviewed
Feb 22, 2025
telferang
left a comment
There was a problem hiding this comment.
Please try to work on IP during the recess week to catch up.
src/main/java/Capy.java
Outdated
| Scanner inputObj = new Scanner(System.in); // Create Scanner object | ||
| String userInput; // Declare string to hold user input | ||
|
|
||
| Task[] tasks = new Task[100]; // Declare array of Task objects |
There was a problem hiding this comment.
Consider declaring 100 as a constant to avoid magic numbers.
src/main/java/Capy.java
Outdated
Comment on lines
+26
to
+105
| if (userInput.equals("bye")) { | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("Bye. Hope to see you again soon!"); | ||
| System.out.println("____________________________________________________________"); | ||
| break; // Break loop when "bye" is received | ||
| } else if (userInput.equals("list")) { | ||
| // Print stored tasks as a list | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("Here are the tasks in your list:"); | ||
| for (int i = 0; i < counter; i++) { | ||
| // Iterate through task array to print stored tasks | ||
| System.out.println(i + 1 +". " + tasks[i]); | ||
| } | ||
| System.out.println("____________________________________________________________"); | ||
| } else if (userInput.startsWith("mark")) { | ||
| // Mark task as done | ||
| int taskNumber = Integer.parseInt(userInput.split(" ")[1]) - 1; | ||
| if (taskNumber >= 0 && taskNumber < counter) { | ||
| tasks[taskNumber].mark(); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("Nice! I've marked this task as done: "); | ||
| System.out.println(tasks[taskNumber]); | ||
| System.out.println("____________________________________________________________"); | ||
| } else { | ||
| System.out.println("Invalid task number."); | ||
| } | ||
| } else if (userInput.startsWith("unmark")) { | ||
| // Unmark task as not done | ||
| int taskNumber = Integer.parseInt(userInput.split(" ")[1]) - 1; | ||
| if (taskNumber >= 0 && taskNumber < counter) { | ||
| tasks[taskNumber].unmark(); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("Ok, I've marked this task as not done yet: "); | ||
| System.out.println(tasks[taskNumber]); | ||
| System.out.println("____________________________________________________________"); | ||
| } else { | ||
| System.out.println("Invalid task number."); | ||
| } | ||
| } else if (userInput.startsWith("todo")) { | ||
| String description = userInput.substring(5); // beginindex determined by length of command | ||
| tasks[counter] = new ToDo(description); | ||
| counter++; | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(" " + tasks[counter - 1]); | ||
| System.out.println("Now you have " + counter + " tasks in the list."); | ||
| System.out.println("____________________________________________________________"); | ||
| } else if (userInput.startsWith("deadline")) { | ||
| String[] parts = userInput.split(" /by "); | ||
| String description = parts[0].substring(9); // beginindex determined by length of command | ||
| String dueDate = parts[1]; | ||
| tasks[counter] = new Deadline(description, dueDate); | ||
| counter++; | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(" " + tasks[counter - 1]); | ||
| System.out.println("Now you have " + counter + " tasks in the list."); | ||
| System.out.println("____________________________________________________________"); | ||
| } else if (userInput.startsWith("event")) { | ||
| String[] parts = userInput.split(" /from | /to "); | ||
| String description = parts[0].substring(6); // beginindex determined by length of command | ||
| String start = parts[1]; | ||
| String end = parts[2]; | ||
| tasks[counter] = new Event(description, start, end); | ||
| counter++; | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(" " + tasks[counter - 1]); | ||
| System.out.println("Now you have " + counter + " tasks in the list."); | ||
| System.out.println("____________________________________________________________"); | ||
| } else { | ||
| // Add user input to string array | ||
| tasks[counter] = new Task(userInput); | ||
| counter++; // Update counter | ||
|
|
||
| // Echo that user input has been added | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("added: " + userInput); | ||
| System.out.println("____________________________________________________________"); | ||
| } |
There was a problem hiding this comment.
Consider refactoring the code to reduce the length of the loop.
A-JavaDoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.