[felibunnyy] iP#540
Open
felibunnyy wants to merge 20 commits into
Open
Conversation
|
Looks good to me! 😄 |
Heran9
reviewed
Sep 6, 2023
Comment on lines
3
to
80
| public class Duke { | ||
| public static void main(String[] args) { | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| Scanner scanner = new Scanner(System.in); | ||
| boolean isRunning = true; | ||
| int taskCount = 0; | ||
| ArrayList<Task> tasks = new ArrayList<>(); | ||
| // Task[] tasks = new Task[100]; | ||
| System.out.println("Hello! I'm Chatty\nWhat can I do for you?"); | ||
| System.out.println("____________________________________________________________"); | ||
| while (isRunning) { | ||
| try { | ||
| String userInput = scanner.nextLine(); | ||
| System.out.println("____________________________________________________________"); | ||
| if (userInput.equals("bye")) { | ||
| System.out.println("Bye. Hope to see you again soon!"); | ||
| isRunning = false; | ||
| } else if (userInput.equals("list")){ | ||
| System.out.println("Here are the tasks in your list:"); | ||
| for (int i = 0; i < taskCount; i++) { | ||
| System.out.println(i + 1 + "." + tasks.get(i)); | ||
| } | ||
| } else if (userInput.startsWith("mark ")) { | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| int taskIndex = Integer.parseInt(userInput.substring(5)) - 1; | ||
| tasks.get(taskIndex).switchCheck(); | ||
| System.out.println(tasks.get(taskIndex).toString()); | ||
| } else if (userInput.startsWith("unmark ")) { | ||
| System.out.println("OK, I've marked this task as not done yet:"); | ||
| int taskIndex = Integer.parseInt(userInput.substring(7)) - 1; | ||
| tasks.get(taskIndex).switchCheck(); | ||
| System.out.println(tasks.get(taskIndex).toString()); | ||
| } else if (userInput.startsWith("todo ")) { | ||
| if (userInput.length() <= 5) { | ||
| throw new DukeException("OOPS!!! The description of a todo cannot be empty."); | ||
| } | ||
| Task newToDo = new Todo(userInput.substring(5)); | ||
| System.out.println("Got it. I've added this task:"); | ||
| tasks.add(new Todo(userInput)); | ||
| taskCount++; | ||
| System.out.println(newToDo.toString()); | ||
| System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
| } else if (userInput.startsWith("deadline ")) { | ||
| System.out.println("Got it. I've added this task:"); | ||
| String description = userInput.substring(9, userInput.indexOf("/by")).trim(); | ||
| String by = userInput.substring(userInput.indexOf("/by") + 4).trim(); | ||
| Task newDeadline = new Deadline(description, by); | ||
| tasks.add(newDeadline); | ||
| taskCount++; | ||
| System.out.println(newDeadline.toString()); | ||
| System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
| } else if (userInput.startsWith("event ")) { | ||
| System.out.println("Got it. I've added this task:"); | ||
| String description = userInput.substring(6, userInput.indexOf("/from")).trim(); | ||
| String from = userInput.substring(userInput.indexOf("/from") + 6, userInput.indexOf("/to")).trim(); | ||
| String to = userInput.substring(userInput.indexOf("/to") + 4).trim(); | ||
| Task newEvent = new Event(description, from, to); | ||
| tasks.add(newEvent); | ||
| taskCount++; | ||
| System.out.println(newEvent.toString()); | ||
| System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
| } else if (userInput.startsWith("delete ")) { | ||
| System.out.println("Noted. I've removed this task:"); | ||
| int taskIndex = Integer.parseInt(userInput.substring(7)) - 1; | ||
| System.out.println(tasks.get(taskIndex)); | ||
| tasks.remove(taskIndex); | ||
| taskCount--; | ||
| System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
| } else { | ||
| throw new DukeException("OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
| } | ||
| } catch (DukeException e) { | ||
| // Handle Duke-specific exceptions with meaningful error messages | ||
| System.out.println(e.getMessage()); | ||
| } | ||
| System.out.println("____________________________________________________________"); | ||
| } | ||
| scanner.close(); | ||
| } |
Comment on lines
+12
to
+72
| while (isRunning) { | ||
| try { | ||
| String userInput = scanner.nextLine(); | ||
| System.out.println("____________________________________________________________"); | ||
| if (userInput.equals("bye")) { | ||
| System.out.println("Bye. Hope to see you again soon!"); | ||
| isRunning = false; | ||
| } else if (userInput.equals("list")){ | ||
| System.out.println("Here are the tasks in your list:"); | ||
| for (int i = 0; i < taskCount; i++) { | ||
| System.out.println(i + 1 + "." + tasks.get(i)); | ||
| } | ||
| } else if (userInput.startsWith("mark ")) { | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| int taskIndex = Integer.parseInt(userInput.substring(5)) - 1; | ||
| tasks.get(taskIndex).switchCheck(); | ||
| System.out.println(tasks.get(taskIndex).toString()); | ||
| } else if (userInput.startsWith("unmark ")) { | ||
| System.out.println("OK, I've marked this task as not done yet:"); | ||
| int taskIndex = Integer.parseInt(userInput.substring(7)) - 1; | ||
| tasks.get(taskIndex).switchCheck(); | ||
| System.out.println(tasks.get(taskIndex).toString()); | ||
| } else if (userInput.startsWith("todo ")) { | ||
| if (userInput.length() <= 5) { | ||
| throw new DukeException("OOPS!!! The description of a todo cannot be empty."); | ||
| } | ||
| Task newToDo = new Todo(userInput.substring(5)); | ||
| System.out.println("Got it. I've added this task:"); | ||
| tasks.add(new Todo(userInput)); | ||
| taskCount++; | ||
| System.out.println(newToDo.toString()); | ||
| System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
| } else if (userInput.startsWith("deadline ")) { | ||
| System.out.println("Got it. I've added this task:"); | ||
| String description = userInput.substring(9, userInput.indexOf("/by")).trim(); | ||
| String by = userInput.substring(userInput.indexOf("/by") + 4).trim(); | ||
| Task newDeadline = new Deadline(description, by); | ||
| tasks.add(newDeadline); | ||
| taskCount++; | ||
| System.out.println(newDeadline.toString()); | ||
| System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
| } else if (userInput.startsWith("event ")) { | ||
| System.out.println("Got it. I've added this task:"); | ||
| String description = userInput.substring(6, userInput.indexOf("/from")).trim(); | ||
| String from = userInput.substring(userInput.indexOf("/from") + 6, userInput.indexOf("/to")).trim(); | ||
| String to = userInput.substring(userInput.indexOf("/to") + 4).trim(); | ||
| Task newEvent = new Event(description, from, to); | ||
| tasks.add(newEvent); | ||
| taskCount++; | ||
| System.out.println(newEvent.toString()); | ||
| System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
| } else if (userInput.startsWith("delete ")) { | ||
| System.out.println("Noted. I've removed this task:"); | ||
| int taskIndex = Integer.parseInt(userInput.substring(7)) - 1; | ||
| System.out.println(tasks.get(taskIndex)); | ||
| tasks.remove(taskIndex); | ||
| taskCount--; | ||
| System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
| } else { | ||
| throw new DukeException("OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
| } |
There was a problem hiding this comment.
Can put all these into another class, which makes it more simple and clear
lawruixi
reviewed
Sep 9, 2023
lawruixi
left a comment
There was a problem hiding this comment.
I noticed some minor mistakes with adhering to the code standards, but overall, looks good to me!
| if (userInput.equals("bye")) { | ||
| System.out.println("Bye. Hope to see you again soon!"); | ||
| isRunning = false; | ||
| } else if (userInput.equals("list")){ |
There was a problem hiding this comment.
Suggested change
| } else if (userInput.equals("list")){ | |
| } else if (userInput.equals("list")) { |
Comment on lines
+46
to
+47
| String description = userInput.substring(9, userInput.indexOf("/by")).trim(); | ||
| String by = userInput.substring(userInput.indexOf("/by") + 4).trim(); |
There was a problem hiding this comment.
Would there be issues if no /by parameter is specified? Perhaps a DukeException could be thrown in that case?
| } else if (userInput.startsWith("event ")) { | ||
| System.out.println("Got it. I've added this task:"); | ||
| String description = userInput.substring(6, userInput.indexOf("/from")).trim(); | ||
| String from = userInput.substring(userInput.indexOf("/from") + 6, userInput.indexOf("/to")).trim(); |
There was a problem hiding this comment.
Suggested change
| String from = userInput.substring(userInput.indexOf("/from") + 6, userInput.indexOf("/to")).trim(); | |
| String from = userInput.substring( | |
| userInput.indexOf("/from") + 6, userInput.indexOf("/to") | |
| ).trim(); |
the original line is over 100 characters ;-;
| // Task[] tasks = new Task[100]; | ||
| System.out.println("Hello! I'm Chatty\nWhat can I do for you?"); | ||
| System.out.println("____________________________________________________________"); | ||
| while (isRunning) { |
There was a problem hiding this comment.
I like that there are spaces around the brackets :D
package all classes into chatty package
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.