-
Notifications
You must be signed in to change notification settings - Fork 484
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
[felibunnyy] iP #540
base: master
Are you sure you want to change the base?
[felibunnyy] iP #540
Conversation
Looks good to me! 😄 |
src/main/java/Duke.java
Outdated
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(); | ||
} |
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.
Can add more Javadosc to the code
src/main/java/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can put all these into another class, which makes it more simple and clear
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 noticed some minor mistakes with adhering to the code standards, but overall, looks good to me!
src/main/java/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else if (userInput.equals("list")){ | |
} else if (userInput.equals("list")) { |
src/main/java/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there be issues if no /by
parameter is specified? Perhaps a DukeException could be thrown in that case?
src/main/java/Duke.java
Outdated
} 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ;-;
src/main/java/Duke.java
Outdated
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that there are spaces around the brackets :D
package all classes into chatty package
No description provided.