Skip to content

Commit

Permalink
remove InvaliDateException class
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Y-Yan committed Nov 14, 2023
1 parent 1dc8963 commit 3b52146
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
53 changes: 53 additions & 0 deletions src/main/java/seedu/duke/commands/goal/AddGoalCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package seedu.duke.commands.goal;

import seedu.duke.Duke;
import seedu.duke.commands.Command;
import seedu.duke.commands.CommandResult;
import seedu.duke.data.GoalList;
import seedu.duke.data.exception.IncorrectFormatException;

import java.io.IOException;


public class GoalCommand extends Command {

public static final String COMMAND_WORD = "set";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Add a new goal into the goal list\n"
+ "\tExample: " + COMMAND_WORD + " 123 on 18/12/2023";
public String feedbackToUser;


public GoalCommand(String cmd) {
super(cmd);
}

/**
* The execution of goalCommand new a goal record into the goal list.
* If error occurs in creating goal record, possibly includes
* incorrect format of command or invalid number is input.
* @return result of adding goal successfully message
*/
@Override
public CommandResult execute() {
try {
feedbackToUser = GoalList.addGoal(this.userCommand, Duke.goalList, Duke.goalStorage);
} catch (IncorrectFormatException ife) {
feedbackToUser = ife.getMessage();
} catch (NumberFormatException nfe) {
feedbackToUser = "Please input a valid number for calories.";
} catch (InvalidDateException ide) {
feedbackToUser = ide.getMessage();
} catch (IOException io) {
feedbackToUser = "Failed to save data. Please check the output file and restart the app.";
} catch (Exception e) {
feedbackToUser = "Something went wrong, please try again.";
}




return new CommandResult(feedbackToUser);
}

}

5 changes: 2 additions & 3 deletions src/main/java/seedu/duke/data/GoalList.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import seedu.duke.Duke;
import seedu.duke.data.exception.IllegalValueException;
import seedu.duke.data.exception.IncorrectFormatException;
import seedu.duke.data.exception.InvalidDateException;
import seedu.duke.storagefile.GoalStorage;
import seedu.duke.storagefile.StorageFile;
import seedu.duke.ui.TextUi;
Expand Down Expand Up @@ -151,8 +150,8 @@ private static void verifyAchieveGoalInput(String cmd) throws IncorrectFormatExc
* @throws IncorrectFormatException if user input is in wrong format
* @throws NumberFormatException if the user does not input a valid number
*/
public static String addGoal(String userCmd, GoalList Targetlist, GoalStorage storage) throws IncorrectFormatException, NumberFormatException,
InvalidDateException, IOException {
public static String addGoal(String userCmd, GoalList Targetlist, GoalStorage storage) throws IncorrectFormatException,
NumberFormatException, IOException {
verifyGoalInput(userCmd); //if invalid, exceptions is thrown

String[] cmdSplit = userCmd.split(" ");
Expand Down

0 comments on commit 3b52146

Please sign in to comment.