Skip to content

Commit

Permalink
Recover GoalCommand class
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Y-Yan committed Nov 14, 2023
1 parent 5133f60 commit 07875cb
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/main/java/seedu/duke/commands/goal/GoalCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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 (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);
}

}

0 comments on commit 07875cb

Please sign in to comment.