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

[felibunnyy] iP #540

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

Conversation

felibunnyy
Copy link

No description provided.

@ZD292
Copy link

ZD292 commented Sep 5, 2023

Looks good to me! 😄

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();
}
Copy link

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

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 :-(");
}
Copy link

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

Copy link

@lawruixi lawruixi left a 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!

if (userInput.equals("bye")) {
System.out.println("Bye. Hope to see you again soon!");
isRunning = false;
} else if (userInput.equals("list")){
Copy link

Choose a reason for hiding this comment

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

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();
Copy link

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?

} 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();
Copy link

Choose a reason for hiding this comment

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

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) {
Copy link

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

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.

5 participants