diff --git a/src/main/java/commands/AddDeadline.java b/src/main/java/commands/AddDeadline.java index 861577ebc6..d6473f7351 100644 --- a/src/main/java/commands/AddDeadline.java +++ b/src/main/java/commands/AddDeadline.java @@ -6,6 +6,7 @@ import exceptions.EmptyDescriptionException; import exceptions.InvalidDateFormatException; +import exceptions.TooManyParametersException; import tasks.Deadline; import windebot.History; import windebot.Reminder; @@ -30,12 +31,12 @@ public class AddDeadline extends Command { */ public boolean execute(String input, Reminder reminder, Ui ui, History history) - throws EmptyDescriptionException, InvalidDateFormatException { + throws EmptyDescriptionException, InvalidDateFormatException, TooManyParametersException { String[] command = input.split(" ", 2); String[] order = command[1].split(" /by "); String taskDescription = order[0].trim(); try { - if (!(taskDescription.equals("")) && (order.length == 3)) { + if (!(taskDescription.equals("")) && (order.length == 2)) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"); LocalDateTime deadline = LocalDateTime.parse(order[1], formatter); Deadline deadlineTask = new Deadline(taskDescription, deadline); @@ -44,13 +45,19 @@ public boolean execute(String input, Reminder reminder, Ui ui, History history) ui.print(" " + deadlineTask.toString()); ui.print("Now you have " + reminder.size() + " tasks in the list."); history.save(reminder.getSchedule()); + } else if (order.length > 2) { + throw new TooManyParametersException(); } else { - throw new EmptyDescriptionException("ADD THE CORRECT PARAMETERS!"); + throw new EmptyDescriptionException(); } - return true; } catch (DateTimeParseException e) { - throw new InvalidDateFormatException("FOLLOW THE CORRECT DATE FORMAT: DD/MM/YYYY HH:MM"); + ui.invalidDateFormatMessage(); + } catch (EmptyDescriptionException e) { + ui.emptyDescriptionMessage(); + } catch (TooManyParametersException e) { + ui.tooManyParametersMessage(); } + return true; } /** diff --git a/src/main/java/commands/AddEvent.java b/src/main/java/commands/AddEvent.java index 8d48004edc..a22157278a 100644 --- a/src/main/java/commands/AddEvent.java +++ b/src/main/java/commands/AddEvent.java @@ -6,6 +6,7 @@ import exceptions.EmptyDescriptionException; import exceptions.InvalidDateFormatException; +import exceptions.TooManyParametersException; import tasks.Event; import windebot.History; import windebot.Reminder; @@ -27,11 +28,11 @@ public class AddEvent extends Command { * @param ui The Ui object used to interact with the user. * @param history The History object used to save the data * @return true if the command was executed successfully. - * @throws EmptyDescriptionException If the input is incomplete or incorrectly formatted. + * @throws InvalidDateFormatException If the input date is incorrectly formatted. */ public boolean execute(String input, Reminder reminder, Ui ui, History history) - throws EmptyDescriptionException, InvalidDateFormatException { + throws EmptyDescriptionException, InvalidDateFormatException, TooManyParametersException { String[] command = input.split(" ", 2); String[] order = command[1].split(" /from | /to "); String taskDescription = order[0].trim(); @@ -46,13 +47,19 @@ public boolean execute(String input, Reminder reminder, Ui ui, History history) ui.print(" " + eventTask.toString()); ui.print("Now you have " + reminder.size() + " tasks in the list."); history.save(reminder.getSchedule()); + } else if (order.length > 3) { + throw new TooManyParametersException(); } else { - throw new EmptyDescriptionException("ADD THE CORRECT PARAMETERS!"); + throw new EmptyDescriptionException(); } - return true; } catch (DateTimeParseException e) { - throw new InvalidDateFormatException("FOLLOW THE CORRECT DATE FORMAT: DD/MM/YYYY HH:MM"); + ui.invalidDateFormatMessage(); + } catch (EmptyDescriptionException e) { + ui.emptyDescriptionMessage(); + } catch (TooManyParametersException e) { + ui.tooManyParametersMessage(); } + return true; } /** diff --git a/src/main/java/commands/AddMark.java b/src/main/java/commands/AddMark.java index 441fdcddc4..79ece7633d 100644 --- a/src/main/java/commands/AddMark.java +++ b/src/main/java/commands/AddMark.java @@ -3,7 +3,6 @@ import exceptions.EmptyDescriptionException; import exceptions.IndexOutBoundsException; import exceptions.NotIntegerException; -import exceptions.TooManyParametersException; import windebot.History; import windebot.Reminder; import windebot.Ui; @@ -25,34 +24,38 @@ public class AddMark extends Command { * @param history The History object used to save the data * @return true if the command was executed successfully. * @throws EmptyDescriptionException If no index is provided in the input. - * @throws TooManyParametersException If too many parameters are provided in the input. * @throws NotIntegerException If no integer is provided in the input. * @throws IndexOutBoundsException If integer provided is out of bounds. */ public boolean execute(String input, Reminder reminder, Ui ui, History history) - throws EmptyDescriptionException, TooManyParametersException, - NotIntegerException, IndexOutBoundsException { - String[] command = input.split(" "); - assert(command.length == 2); + throws NotIntegerException, IndexOutBoundsException, EmptyDescriptionException { try { - int index = Integer.parseInt(command[1].trim()); - if (command.length == 2) { - ui.print("Nice! I've marked this task as done:"); + String[] command = input.split(" ", 2); + if (command.length < 2) { + throw new EmptyDescriptionException(); + } + String search = command[1].trim(); + if (!(search.equals(""))) { + int index = Integer.parseInt(command[1].trim()); + if (index > reminder.size() + 1) { + throw new IndexOutOfBoundsException(); + } reminder.mark(index - 1); + ui.print("Nice! I've marked this task as done:"); ui.print(" " + reminder.getTask(Integer.parseInt(command[1]) - 1).toString()); history.save(reminder.getSchedule()); - } else if (command.length < 2) { - throw new EmptyDescriptionException("I NEED TO KNOW WHAT I'M MARKING!"); } else { - throw new TooManyParametersException("ONE AT A TIME!"); + throw new EmptyDescriptionException(); } - return true; } catch (NumberFormatException e) { - throw new NotIntegerException("THAT IS NOT AN INTEGER!"); - } catch (StringIndexOutOfBoundsException e) { - throw new IndexOutBoundsException("THIS IS NOT A VALID TASK NUMBER!"); + ui.notIntegerMessage(); + } catch (IndexOutOfBoundsException e) { + ui.indexOutBoundsMessage(); + } catch (EmptyDescriptionException e) { + ui.emptyDescriptionMessage(); } + return true; } /** diff --git a/src/main/java/commands/AddTodo.java b/src/main/java/commands/AddTodo.java index c013052b3d..d8024043d5 100644 --- a/src/main/java/commands/AddTodo.java +++ b/src/main/java/commands/AddTodo.java @@ -27,17 +27,24 @@ public class AddTodo extends Command { public boolean execute(String input, Reminder reminder, Ui ui, History history) throws EmptyDescriptionException { - String[] command = input.split(" ", 2); - String taskDescription = command[1].trim(); - if (!(taskDescription.equals(""))) { - Todos todoTask = new Todos(taskDescription); - reminder.addTodo(todoTask); - ui.print("Got it. I've added this task:"); - ui.print(" " + todoTask.toString()); - ui.print("Now you have " + reminder.size() + " tasks in the list."); - history.save(reminder.getSchedule()); - } else { - throw new EmptyDescriptionException("I NEED TO KNOW WHAT I'M TODO-ING!"); + try { + String[] command = input.split(" ", 2); + if (command.length < 2) { + throw new EmptyDescriptionException(); + } + String taskDescription = command[1].trim(); + if (!(taskDescription.equals(""))) { + Todos todoTask = new Todos(taskDescription); + reminder.addTodo(todoTask); + ui.print("Got it. I've added this task:"); + ui.print(" " + todoTask.toString()); + ui.print("Now you have " + reminder.size() + " tasks in the list."); + history.save(reminder.getSchedule()); + } else { + throw new EmptyDescriptionException(); + } + } catch (EmptyDescriptionException e) { + ui.emptyDescriptionMessage(); } return true; } diff --git a/src/main/java/commands/AddUnmark.java b/src/main/java/commands/AddUnmark.java index 9d6ff39852..02ba41f3d1 100644 --- a/src/main/java/commands/AddUnmark.java +++ b/src/main/java/commands/AddUnmark.java @@ -3,7 +3,6 @@ import exceptions.EmptyDescriptionException; import exceptions.IndexOutBoundsException; import exceptions.NotIntegerException; -import exceptions.TooManyParametersException; import windebot.History; import windebot.Reminder; import windebot.Ui; @@ -25,34 +24,38 @@ public class AddUnmark extends Command { * @param history The History object used to save the data * @return true if the command was executed successfully. * @throws EmptyDescriptionException If no index is provided in the input. - * @throws TooManyParametersException If too many parameters are provided in the input. * @throws NotIntegerException If no integer is provided in the input. * @throws IndexOutBoundsException If integer provided is out of bounds. */ public boolean execute(String input, Reminder reminder, Ui ui, History history) - throws EmptyDescriptionException, TooManyParametersException, - NotIntegerException, IndexOutBoundsException { - String[] command = input.split(" "); - assert(command.length == 2); + throws NotIntegerException, IndexOutBoundsException, EmptyDescriptionException { try { - int index = Integer.parseInt(command[1].trim()); - if (command.length == 2) { - ui.print("Ok! I've marked this task as not done:"); + String[] command = input.split(" ", 2); + if (command.length < 2) { + throw new EmptyDescriptionException(); + } + String search = command[1].trim(); + if (!(search.equals(""))) { + int index = Integer.parseInt(command[1].trim()); + if (index > reminder.size() + 1) { + throw new IndexOutOfBoundsException(); + } reminder.unmark(index - 1); + ui.print("Ok! I've marked this task as not done:"); ui.print(" " + reminder.getTask(Integer.parseInt(command[1]) - 1).toString()); history.save(reminder.getSchedule()); - } else if (command.length < 2) { - throw new EmptyDescriptionException("I NEED TO KNOW WHAT I'M MARKING!"); } else { - throw new TooManyParametersException("ONE AT A TIME!"); + throw new EmptyDescriptionException(); } - return true; } catch (NumberFormatException e) { - throw new NotIntegerException("THAT IS NOT AN INTEGER!"); - } catch (StringIndexOutOfBoundsException e) { - throw new IndexOutBoundsException("THIS IS NOT A VALID TASK NUMBER!"); + ui.notIntegerMessage(); + } catch (IndexOutOfBoundsException e) { + ui.indexOutBoundsMessage(); + } catch (EmptyDescriptionException e) { + ui.emptyDescriptionMessage(); } + return true; } /** diff --git a/src/main/java/commands/ChangeCommand.java b/src/main/java/commands/ChangeCommand.java index 7040bd2a3a..79f46be601 100644 --- a/src/main/java/commands/ChangeCommand.java +++ b/src/main/java/commands/ChangeCommand.java @@ -31,57 +31,63 @@ public class ChangeCommand extends Command { public boolean execute(String input, Reminder reminder, Ui ui, History history) throws EmptyDescriptionException { - String[] command = input.split(" ", 2); - assert(command.length == 2); - int toChange = reminder.getSelected(); - Task task = reminder.getSchedule().get(toChange); - if (command[0].equalsIgnoreCase("change")) { - toChange = Integer.parseInt(command[1]) - 1; - reminder.changeSelected(toChange); - task = reminder.getSchedule().get(toChange); - ui.print("Got it. You want to edit this task:"); - ui.print(" " + task.toString()); - ui.print("To change the task description, input: action (task description)"); - if (task.getClass() == Deadline.class) { - ui.print("To change the deadline, input: cutoff (new deadline)"); - } else if (task.getClass() == Event.class) { - ui.print("To change the start date, input: start (new start)"); - ui.print("To change the end date, input: end (new end)"); + try { + String[] command = input.split(" ", 2); + if (command.length < 2) { + throw new EmptyDescriptionException(); } - } else if (command[0].equalsIgnoreCase("action")) { - task.changeAction(command[1]); - ui.print("Got it. The task has been changed to:"); - ui.print(" " + task.toString()); - ui.print("Now you have " + reminder.size() + " tasks in the list."); - } else if (command[0].equalsIgnoreCase("cutoff") - && task.getClass() == Deadline.class) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"); - LocalDateTime deadline = LocalDateTime.parse(command[1], formatter); - task.changeDate(deadline); - ui.print("Got it. The task has been changed to:"); - ui.print(" " + task.toString()); - ui.print("Now you have " + reminder.size() + " tasks in the list."); - history.save(reminder.getSchedule()); - } else if (command[0].equalsIgnoreCase("start") - && task.getClass() == Event.class) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"); - LocalDateTime start = LocalDateTime.parse(command[1], formatter); - task.changeStartDate(start); - ui.print("Got it. The task has been changed to:"); - ui.print(" " + task.toString()); - ui.print("Now you have " + reminder.size() + " tasks in the list."); - history.save(reminder.getSchedule()); - } else if (command[0].equalsIgnoreCase("end") - && task.getClass() == Event.class) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"); - LocalDateTime end = LocalDateTime.parse(command[1], formatter); - task.changeEndDate(end); - ui.print("Got it. The task has been changed to:"); - ui.print(" " + task.toString()); - ui.print("Now you have " + reminder.size() + " tasks in the list."); - history.save(reminder.getSchedule()); - } else { - throw new EmptyDescriptionException("PUT IN PARAMETERS"); + int toChange = reminder.getSelected(); + Task task = reminder.getSchedule().get(toChange); + if (command[0].equalsIgnoreCase("change")) { + toChange = Integer.parseInt(command[1]) - 1; + reminder.changeSelected(toChange); + task = reminder.getSchedule().get(toChange); + ui.print("Got it. You want to edit this task:"); + ui.print(" " + task.toString()); + ui.print("To change the task description, input: action (task description)"); + if (task.getClass() == Deadline.class) { + ui.print("To change the deadline, input: cutoff (new deadline)"); + } else if (task.getClass() == Event.class) { + ui.print("To change the start date, input: start (new start)"); + ui.print("To change the end date, input: end (new end)"); + } + } else if (command[0].equalsIgnoreCase("action")) { + task.changeAction(command[1]); + ui.print("Got it. The task has been changed to:"); + ui.print(" " + task.toString()); + ui.print("Now you have " + reminder.size() + " tasks in the list."); + } else if (command[0].equalsIgnoreCase("cutoff") + && task.getClass() == Deadline.class) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"); + LocalDateTime deadline = LocalDateTime.parse(command[1], formatter); + task.changeDate(deadline); + ui.print("Got it. The task has been changed to:"); + ui.print(" " + task.toString()); + ui.print("Now you have " + reminder.size() + " tasks in the list."); + history.save(reminder.getSchedule()); + } else if (command[0].equalsIgnoreCase("start") + && task.getClass() == Event.class) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"); + LocalDateTime start = LocalDateTime.parse(command[1], formatter); + task.changeStartDate(start); + ui.print("Got it. The task has been changed to:"); + ui.print(" " + task.toString()); + ui.print("Now you have " + reminder.size() + " tasks in the list."); + history.save(reminder.getSchedule()); + } else if (command[0].equalsIgnoreCase("end") + && task.getClass() == Event.class) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"); + LocalDateTime end = LocalDateTime.parse(command[1], formatter); + task.changeEndDate(end); + ui.print("Got it. The task has been changed to:"); + ui.print(" " + task.toString()); + ui.print("Now you have " + reminder.size() + " tasks in the list."); + history.save(reminder.getSchedule()); + } else { + throw new EmptyDescriptionException(); + } + } catch (EmptyDescriptionException e) { + ui.emptyDescriptionMessage(); } return true; } diff --git a/src/main/java/commands/DateCommand.java b/src/main/java/commands/DateCommand.java index 9e7ad242a6..56322d0fab 100644 --- a/src/main/java/commands/DateCommand.java +++ b/src/main/java/commands/DateCommand.java @@ -2,10 +2,10 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; import java.util.ArrayList; import exceptions.EmptyDescriptionException; -import exceptions.TooManyParametersException; import tasks.Task; import windebot.History; import windebot.Reminder; @@ -27,28 +27,35 @@ public class DateCommand extends Command { * @param history The History object used to save the data * @return true if the command was executed successfully. * @throws EmptyDescriptionException If no date is provided in the input. - * @throws TooManyParametersException If too many parameters are provided in the input. + * @throws DateTimeParseException If date is not correct. */ public boolean execute(String input, Reminder reminder, Ui ui, History history) - throws EmptyDescriptionException, TooManyParametersException { - String[] command = input.split(" "); - assert(command.length == 2); - if (command.length == 2) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); - LocalDate date = LocalDate.parse(command[1], formatter); - ui.print("These are the tasks you have for " + date.toString()); - ArrayList tasksOnDate = reminder.getTasksOnDate(date); - if (tasksOnDate != null) { - for (Task task : tasksOnDate) { - ui.print(task.toString()); + throws EmptyDescriptionException { + try { + String[] command = input.split(" ", 2); + if (command.length < 2) { + throw new EmptyDescriptionException(); + } + String search = command[1].trim(); + if (!(search.equals(""))) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + LocalDate date = LocalDate.parse(command[1], formatter); + ui.print("These are the tasks you have for " + date.toString()); + ArrayList tasksOnDate = reminder.getTasksOnDate(date); + if (tasksOnDate != null) { + for (Task task : tasksOnDate) { + ui.print(task.toString()); + } + } else { + ui.print("Hurray! No tasks on: " + date.toString()); } } else { - ui.print("Hurray! No tasks on: " + date.toString()); + throw new EmptyDescriptionException(); } - } else if (command.length < 2) { - throw new EmptyDescriptionException("I NEED TO KNOW THE DATE!"); - } else { - throw new TooManyParametersException("ONE AT A TIME!"); + } catch (DateTimeParseException e) { + ui.invalidDateFormatMessage(); + } catch (EmptyDescriptionException e) { + ui.emptyDescriptionMessage(); } return true; } diff --git a/src/main/java/commands/FindCommand.java b/src/main/java/commands/FindCommand.java index f330a2737b..11a7030b25 100644 --- a/src/main/java/commands/FindCommand.java +++ b/src/main/java/commands/FindCommand.java @@ -27,26 +27,31 @@ public class FindCommand extends Command { */ public boolean execute(String input, Reminder reminder, Ui ui, History history) - throws EmptyDescriptionException, TooManyParametersException { - String[] command = input.split(" ", 2); - assert(command.length == 2); - if (command.length == 2) { - ui.print("Here are the matching tasks in your list:"); - String keyWord = command[1]; - boolean isTaskFound = true; - for (Task task : reminder.getSchedule()) { - if (task.getAction().contains(keyWord)) { - ui.print(task.toString()); - isTaskFound = false; - } + throws EmptyDescriptionException { + try { + String[] command = input.split(" ", 2); + if (command.length < 2) { + throw new EmptyDescriptionException(); } - if (isTaskFound) { - ui.print("No words matches your query stoopid"); + String search = command[1].trim(); + if (!(search.equals(""))) { + ui.print("Here are the matching tasks in your list:"); + String keyWord = command[1]; + boolean isTaskFound = true; + for (Task task : reminder.getSchedule()) { + if (task.getAction().contains(keyWord)) { + ui.print(task.toString()); + isTaskFound = false; + } + } + if (isTaskFound) { + ui.print("No words matches your query stoopid"); + } + } else { + throw new EmptyDescriptionException(); } - } else if (command.length < 2) { - throw new EmptyDescriptionException("I NEED TO KNOW WHAT I'M MARKING!"); - } else { - throw new TooManyParametersException("ONE AT A TIME!"); + } catch (EmptyDescriptionException e) { + ui.emptyDescriptionMessage(); } return true; } diff --git a/src/main/java/commands/RemoveCommand.java b/src/main/java/commands/RemoveCommand.java index 44e60cf92f..7f7d15b81e 100644 --- a/src/main/java/commands/RemoveCommand.java +++ b/src/main/java/commands/RemoveCommand.java @@ -1,6 +1,7 @@ package commands; import exceptions.EmptyDescriptionException; +import exceptions.IndexOutBoundsException; import exceptions.TooManyParametersException; import tasks.Task; import windebot.History; @@ -28,18 +29,25 @@ public class RemoveCommand extends Command { */ public boolean execute(String input, Reminder reminder, Ui ui, History history) throws EmptyDescriptionException, TooManyParametersException { - String[] command = input.split(" "); - assert(command.length == 2); - if (command.length == 2) { - Task deleted = reminder.remove(Integer.parseInt(command[1]) - 1); - ui.print("Noted. I've removed this task:"); - ui.print(" " + deleted.toString()); - ui.print("Now you have " + reminder.size() + " tasks in the list."); - history.save(reminder.getSchedule()); - } else if (command.length < 2) { - throw new EmptyDescriptionException("I NEED TO KNOW WHAT I'M DELETING!"); - } else { - throw new TooManyParametersException("ONE AT A TIME!"); + try { + String[] command = input.split(" ", 2); + if (command.length < 2) { + throw new EmptyDescriptionException(); + } + String search = command[1].trim(); + if (!(search.equals(""))) { + Task deleted = reminder.remove(Integer.parseInt(command[1]) - 1); + ui.print("Noted. I've removed this task:"); + ui.print(" " + deleted.toString()); + ui.print("Now you have " + reminder.size() + " tasks in the list."); + history.save(reminder.getSchedule()); + } else { + throw new EmptyDescriptionException(); + } + } catch (EmptyDescriptionException e) { + ui.emptyDescriptionMessage(); + } catch (IndexOutBoundsException e) { + ui.indexOutBoundsMessage(); } return true; } diff --git a/src/main/java/exceptions/EmptyDescriptionException.java b/src/main/java/exceptions/EmptyDescriptionException.java index 33ad2a2f94..31d6e10fd0 100644 --- a/src/main/java/exceptions/EmptyDescriptionException.java +++ b/src/main/java/exceptions/EmptyDescriptionException.java @@ -8,10 +8,8 @@ public class EmptyDescriptionException extends Exception { /** * Constructs a new EmptyDescriptionException with the specified detail message. - * - * @param message The detail message explaining the reason for the exception. */ - public EmptyDescriptionException(String message) { - super(message); + public EmptyDescriptionException() { + super("Either you've missed some parameters or you typed the command wrongly"); } } diff --git a/src/main/java/exceptions/IndexOutBoundsException.java b/src/main/java/exceptions/IndexOutBoundsException.java index ad8bd0e8fc..d2b8553392 100644 --- a/src/main/java/exceptions/IndexOutBoundsException.java +++ b/src/main/java/exceptions/IndexOutBoundsException.java @@ -4,14 +4,12 @@ * The IndexOutBoundsException is thrown when the Index is out of bounds. * This exception is typically used in commands that require Integer input. */ -public class IndexOutBoundsException extends Exception { +public class IndexOutBoundsException extends IndexOutOfBoundsException { /** * Constructs a new IndexOutBoundsException with the specified detail message. - * - * @param message The detail message explaining the reason for the exception. */ - public IndexOutBoundsException(String message) { - super(message); + public IndexOutBoundsException() { + super("Input a valid task number"); } } diff --git a/src/main/java/exceptions/InvalidDateFormatException.java b/src/main/java/exceptions/InvalidDateFormatException.java index c34597ae0c..841a1243b7 100644 --- a/src/main/java/exceptions/InvalidDateFormatException.java +++ b/src/main/java/exceptions/InvalidDateFormatException.java @@ -8,8 +8,6 @@ public class InvalidDateFormatException extends Exception { /** * Constructs a new InvalidDateFormatException with the specified detail message. - * - * @param message The detail message explaining the reason for the exception. */ public InvalidDateFormatException(String message) { super(message); diff --git a/src/main/java/exceptions/NotIntegerException.java b/src/main/java/exceptions/NotIntegerException.java index f8d5aca4bc..c92ac6a0d0 100644 --- a/src/main/java/exceptions/NotIntegerException.java +++ b/src/main/java/exceptions/NotIntegerException.java @@ -8,10 +8,8 @@ public class NotIntegerException extends Exception { /** * Constructs a new NotIntegerException with the specified detail message. - * - * @param message The detail message explaining the reason for the exception. */ - public NotIntegerException(String message) { - super(message); + public NotIntegerException() { + super("Input a valid Integer stoopid"); } } diff --git a/src/main/java/exceptions/TooManyParametersException.java b/src/main/java/exceptions/TooManyParametersException.java index 719dae6b10..dc2ed389d3 100644 --- a/src/main/java/exceptions/TooManyParametersException.java +++ b/src/main/java/exceptions/TooManyParametersException.java @@ -8,10 +8,8 @@ public class TooManyParametersException extends Exception { /** * Constructs a new TooManyParametersException with the specified detail message. - * - * @param message The detail message explaining the reason for the exception. */ - public TooManyParametersException(String message) { - super(message); + public TooManyParametersException() { + super("One input at a time!"); } } diff --git a/src/main/java/exceptions/UnsupportedCommandException.java b/src/main/java/exceptions/UnsupportedCommandException.java index aaada10e3d..82b8a0aa83 100644 --- a/src/main/java/exceptions/UnsupportedCommandException.java +++ b/src/main/java/exceptions/UnsupportedCommandException.java @@ -8,10 +8,8 @@ public class UnsupportedCommandException extends Exception { /** * Constructs a new UnsupportedCommandException with the specified detail message. - * - * @param message The detail message explaining the reason for the exception. */ - public UnsupportedCommandException(String message) { - super(message); + public UnsupportedCommandException() { + super("GO TO OUR GITHUB PAGE FOR THE LIST OF COMMANDS STOOPID!"); } } diff --git a/src/main/java/exceptions/UnsupportedFilePathException.java b/src/main/java/exceptions/UnsupportedFilePathException.java index dc50faeea5..4102650986 100644 --- a/src/main/java/exceptions/UnsupportedFilePathException.java +++ b/src/main/java/exceptions/UnsupportedFilePathException.java @@ -8,10 +8,8 @@ public class UnsupportedFilePathException extends Exception { /** * Constructs a new UnsupportedFilePathException with the specified detail message. - * - * @param message The detail message explaining the reason for the exception. */ - public UnsupportedFilePathException(String message) { - super(message); + public UnsupportedFilePathException() { + super("WRONG SAVE FILE!"); } } diff --git a/src/main/java/windebot/Parser.java b/src/main/java/windebot/Parser.java index 5f6bd21330..de66799bff 100644 --- a/src/main/java/windebot/Parser.java +++ b/src/main/java/windebot/Parser.java @@ -13,6 +13,7 @@ import commands.FindCommand; import commands.ListCommand; import commands.RemoveCommand; +import exceptions.EmptyDescriptionException; import exceptions.UnsupportedCommandException; /** @@ -30,7 +31,11 @@ public class Parser { * @throws UnsupportedCommandException If the command is not recognized. */ - public static Command parse(String input) throws UnsupportedCommandException { + public static Command parse(String input) + throws UnsupportedCommandException, EmptyDescriptionException { + if (input.equals("")) { + throw new EmptyDescriptionException(); + } String[] parts = input.split(" ", 2); SubCommandType command = getCommandType(parts[0]); // String arguments = (parts.length > 1) ? parts[1] : ""; @@ -74,10 +79,10 @@ public static Command parse(String input) throws UnsupportedCommandException { commands = new ErrorCommand(); break; default: - throw new UnsupportedCommandException("TYPE /HELP FOR HELP STOOPIDD"); + throw new UnsupportedCommandException(); } } catch (UnsupportedCommandException uce) { - System.out.println("TYPE /HELP FOR HELP STOOPIDD: " + uce.getMessage()); + throw new UnsupportedCommandException(); } return commands; } @@ -90,29 +95,29 @@ public static Command parse(String input) throws UnsupportedCommandException { */ private static SubCommandType getCommandType(String input) { - if (input.startsWith("todo ")) { + if (input.startsWith("todo")) { return SubCommandType.TODO; - } else if (input.startsWith("deadline ")) { + } else if (input.startsWith("deadline")) { return SubCommandType.DEADLINE; - } else if (input.startsWith("event ")) { + } else if (input.startsWith("event")) { return SubCommandType.EVENT; } else if (input.equals("list")) { return SubCommandType.LIST; - } else if (input.startsWith("delete ")) { + } else if (input.startsWith("delete")) { return SubCommandType.DELETE; } else if (input.equals("bye")) { return SubCommandType.BYE; - } else if (input.startsWith("mark ")) { + } else if (input.startsWith("mark")) { return SubCommandType.MARK; - } else if (input.startsWith("unmark ")) { + } else if (input.startsWith("unmark")) { return SubCommandType.UNMARK; - } else if (input.startsWith("date ")) { + } else if (input.startsWith("date")) { return SubCommandType.DATE; - } else if (input.startsWith("find ")) { + } else if (input.startsWith("find")) { return SubCommandType.FIND; - } else if (input.startsWith("change ") || input.startsWith("cutoff ") - || input.startsWith("start ") || input.startsWith("end ") - || input.startsWith("action ")) { + } else if (input.startsWith("change") || input.startsWith("cutoff") + || input.startsWith("start") || input.startsWith("end") + || input.startsWith("action")) { return SubCommandType.CHANGE; } else { return SubCommandType.UNKNOWN; diff --git a/src/main/java/windebot/Reminder.java b/src/main/java/windebot/Reminder.java index 887961a7c0..c6a299d191 100644 --- a/src/main/java/windebot/Reminder.java +++ b/src/main/java/windebot/Reminder.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Hashtable; +import exceptions.IndexOutBoundsException; import tasks.Deadline; import tasks.Event; import tasks.Task; @@ -15,10 +16,10 @@ */ public class Reminder { - private static ArrayList schedule; - private static Hashtable> calendar; + private ArrayList schedule; + private Hashtable> calendar; - private static int selected; + private int selected; /** * Constructs a Reminder object with an empty task list and calendar. @@ -65,7 +66,7 @@ public class Reminder { * @param task The Event task to add. */ - public static void addEvent(Event task) { + public void addEvent(Event task) { schedule.add(task); calendar.computeIfAbsent(task.getDate(), key -> new ArrayList<>()).add(task); } @@ -76,7 +77,7 @@ public static void addEvent(Event task) { * @param task The Deadline task to add. */ - public static void addDeadline(Deadline task) { + public void addDeadline(Deadline task) { schedule.add(task); calendar.computeIfAbsent(task.getDate(), key -> new ArrayList<>()).add(task); } @@ -87,7 +88,7 @@ public static void addDeadline(Deadline task) { * @param task The Todos task to add. */ - public static void addTodo(Todos task) { + public void addTodo(Todos task) { schedule.add(task); } @@ -98,7 +99,10 @@ public static void addTodo(Todos task) { * @return The removed task. */ - public static Task remove(int i) { + public Task remove(int i) throws IndexOutBoundsException { + if (i > size()) { + throw new IndexOutBoundsException(); + } Task task = schedule.remove(i); LocalDate date = task.getDate(); calendar.computeIfPresent(date, (key, value) -> { @@ -116,7 +120,7 @@ public static Task remove(int i) { * @return The removed task. */ - public static Task replace(int i, Task newTask) { + public Task replace(int i, Task newTask) { Task task = schedule.get(i); schedule.set(i, newTask); LocalDate date = task.getDate(); @@ -133,7 +137,10 @@ public static Task replace(int i, Task newTask) { * @param i The index of the task to mark as completed. */ - public static void mark(int i) { + public void mark(int i) throws IndexOutBoundsException { + if (i > size()) { + throw new IndexOutBoundsException(); + } Task task = schedule.remove(i); if (task.getClass() != Todos.class) { LocalDate date = task.getDate(); @@ -154,7 +161,10 @@ public static void mark(int i) { * @param i The index of the task to mark as not completed. */ - public static void unmark(int i) { + public void unmark(int i) throws IndexOutBoundsException { + if (i > size()) { + throw new IndexOutBoundsException(); + } Task task = schedule.remove(i); if (task.getClass() != Todos.class) { LocalDate date = task.getDate(); @@ -176,11 +186,11 @@ public static void unmark(int i) { * @return The list of tasks on the specified date. */ - public static ArrayList getTasksOnDate(LocalDate date) { + public ArrayList getTasksOnDate(LocalDate date) { return calendar.getOrDefault(date, new ArrayList<>()); } - public static ArrayList getSchedule() { + public ArrayList getSchedule() { return schedule; } @@ -194,7 +204,7 @@ public int getSelected() { * @param i The int of the new selected task to edit */ - public static void changeSelected(int i) { + public void changeSelected(int i) { selected = i; } @@ -205,11 +215,11 @@ public static void changeSelected(int i) { * @return The task at the specified index. */ - public static Task getTask(int i) { + public Task getTask(int i) { return schedule.get(i); } - public static int size() { + public int size() { return schedule.size(); } } diff --git a/src/main/java/windebot/Ui.java b/src/main/java/windebot/Ui.java index 235fa496ec..cca76d300e 100644 --- a/src/main/java/windebot/Ui.java +++ b/src/main/java/windebot/Ui.java @@ -82,4 +82,32 @@ public void print(String addWhat) { public String getOutput() { return this.output; } + + public void invalidDateFormatMessage() { + this.print("FOLLOW THE CORRECT DATE FORMAT: DD/MM/YYYY HH:MM"); + } + + public void emptyDescriptionMessage() { + this.print("Either you've missed some parameters or you typed the command wrongly"); + } + + public void indexOutBoundsMessage() { + this.print("Input a valid task number"); + } + + public void notIntegerMessage() { + this.print("Input a valid Integer stoopid"); + } + + public void tooManyParametersMessage() { + this.print("One input at a time!"); + } + + public void unsupportedCommandMessage() { + this.print("GO TO OUR GITHUB PAGE FOR THE LIST OF COMMANDS STOOPID!"); + } + + public void unsupportedFilePathMessage() { + this.print("WRONG SAVE FILE!"); + } }