Skip to content

Commit

Permalink
Merge pull request #13
Browse files Browse the repository at this point in the history
  • Loading branch information
JJtan2002 authored Sep 10, 2024
2 parents a5eff0d + 86781a9 commit 34e85dc
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 58 deletions.
125 changes: 68 additions & 57 deletions src/main/java/echobot/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,19 @@ private void listTasks() {
private void handleMarkCommand(String[] inputParts) {
if (inputParts.length < 2) {
System.out.println(" Please specify the task number to mark as done.");
} else {
int taskNumber = Integer.parseInt(inputParts[1]) - 1;
if (taskNumber < tasks.size() && taskNumber >= 0) {
tasks.get(taskNumber).markAsDone();
Storage.saveTasksToFile(tasks);
System.out.println(" Great! I've marked this task as done:");
System.out.println(" " + tasks.get(taskNumber));
} else {
System.out.println(" Oops! That task number doesn't exist.");
}
return;
}

int taskNumber = Integer.parseInt(inputParts[1]) - 1;
if (taskNumber < tasks.size() && taskNumber >= 0) {
tasks.get(taskNumber).markAsDone();
Storage.saveTasksToFile(tasks);
System.out.println(" Great! I've marked this task as done:");
System.out.println(" " + tasks.get(taskNumber));
return;
}

System.out.println(" Oops! That task number doesn't exist.");
}

/**
Expand All @@ -154,17 +156,19 @@ private void handleMarkCommand(String[] inputParts) {
private void handleUnmarkCommand(String[] inputParts) {
if (inputParts.length < 2) {
System.out.println(" Please specify the task number to unmark.");
} else {
int taskNumber = Integer.parseInt(inputParts[1]) - 1;
if (taskNumber < tasks.size() && taskNumber >= 0) {
tasks.get(taskNumber).markAsNotDone();
Storage.saveTasksToFile(tasks);
System.out.println(" OK! I've marked this task as not done yet:");
System.out.println(" " + tasks.get(taskNumber));
} else {
System.out.println(" Oops! That task number doesn't exist.");
}
return;
}

int taskNumber = Integer.parseInt(inputParts[1]) - 1;
if (taskNumber < tasks.size() && taskNumber >= 0) {
tasks.get(taskNumber).markAsNotDone();
Storage.saveTasksToFile(tasks);
System.out.println(" OK! I've marked this task as not done yet:");
System.out.println(" " + tasks.get(taskNumber));
return;
}

System.out.println(" Oops! That task number doesn't exist.");
}

/**
Expand All @@ -175,12 +179,13 @@ private void handleUnmarkCommand(String[] inputParts) {
private void handleTodoCommand(String[] inputParts) {
if (inputParts.length < 2 || inputParts[1].trim().isEmpty()) {
System.out.println(" The description of a todo cannot be empty.");
} else {
tasks.addTask(new Todo(inputParts[1]));
System.out.println(" Got it. I've added this task:");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println(" Now you have " + tasks.size() + " tasks in the list.");
return;
}

tasks.addTask(new Todo(inputParts[1]));
System.out.println(" Got it. I've added this task:");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println(" Now you have " + tasks.size() + " tasks in the list.");
}

/**
Expand All @@ -191,17 +196,20 @@ private void handleTodoCommand(String[] inputParts) {
private void handleDeadlineCommand(String[] inputParts) {
if (inputParts.length < 2 || !inputParts[1].contains("/by ")) {
System.out.println(" The description of a deadline must include a due date.");
} else {
String[] details = inputParts[1].split(" /by ");
if (details.length < 2 || details[0].trim().isEmpty()) {
System.out.println(" The description of a deadline cannot be empty.");
} else {
tasks.addTask(new Deadline(details[0], details[1]));
System.out.println(" Got it. I've added this task:");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println(" Now you have " + tasks.size() + " tasks in the list.");
}
return;
}

String[] details = inputParts[1].split(" /by ");

if (details.length < 2 || details[0].trim().isEmpty()) {
System.out.println(" The description of a deadline cannot be empty.");
return;
}

tasks.addTask(new Deadline(details[0], details[1]));
System.out.println(" Got it. I've added this task:");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println(" Now you have " + tasks.size() + " tasks in the list.");
}

/**
Expand All @@ -212,17 +220,20 @@ private void handleDeadlineCommand(String[] inputParts) {
private void handleEventCommand(String[] inputParts) {
if (inputParts.length < 2 || !inputParts[1].contains("/from ") || !inputParts[1].contains("/to ")) {
System.out.println(" The description of an event must include start and end times.");
} else {
String[] details = inputParts[1].split(" /from | /to ");
if (details.length < 3 || details[0].trim().isEmpty()) {
System.out.println(" The description of an event cannot be empty.");
} else {
tasks.addTask(new Event(details[0], details[1], details[2]));
System.out.println(" Got it. I've added this task:");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println(" Now you have " + tasks.size() + " tasks in the list.");
}
return;
}

String[] details = inputParts[1].split(" /from | /to ");

if (details.length < 3 || details[0].trim().isEmpty()) {
System.out.println(" The description of an event cannot be empty.");
return;
}

tasks.addTask(new Event(details[0], details[1], details[2]));
System.out.println(" Got it. I've added this task:");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println(" Now you have " + tasks.size() + " tasks in the list.");
}

/**
Expand All @@ -233,21 +244,21 @@ private void handleEventCommand(String[] inputParts) {
private void handleDeleteCommand(String[] inputParts) {
if (inputParts.length < 2) {
System.out.println(" Please specify the task number to delete.");
} else {
try {
int taskNumber = Integer.parseInt(inputParts[1]) - 1;
if (taskNumber < tasks.size() && taskNumber >= 0) {
Task removedTask = tasks.removeTask(taskNumber);
System.out.println(" Noted. I've removed this task:");
System.out.println(" " + removedTask);
System.out.println(" Now you have " + tasks.size() + " tasks in the list.");
} else {
System.out.println(" Oops! That task number doesn't exist.");
return;
}
try {
int taskNumber = Integer.parseInt(inputParts[1]) - 1;
if (taskNumber < tasks.size() && taskNumber >= 0) {
Task removedTask = tasks.removeTask(taskNumber);
System.out.println(" Noted. I've removed this task:");
System.out.println(" " + removedTask);
System.out.println(" Now you have " + tasks.size() + " tasks in the list.");
return;
}
} catch (NumberFormatException e) {
System.out.println(" Oops! That task number doesn't exist.");
} catch (NumberFormatException e) {
System.out.println("Please enter an item number to delete!");
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/echobot/task/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Deadline extends Task {
*/
public Deadline(String description, String by) {
super(description);
this.by = parseDate(by); // Parse the string into a LocalDate
this.by = parseDate(by);
}

/**
Expand Down

0 comments on commit 34e85dc

Please sign in to comment.