Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOPPA1 committed Nov 14, 2023
2 parents 4fcc5df + 34bbb4e commit 28cb8d4
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import seedu.duke.commands.Command;
import seedu.duke.commands.CommandResult;
import seedu.duke.commands.ExitCommand;
import seedu.duke.data.GoalList;
import seedu.duke.goal.GoalList;
import seedu.duke.parser.Parser;
import seedu.duke.exerciselog.Log;
import seedu.duke.storagefile.AchmStorage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import seedu.duke.commands.Command;
import seedu.duke.commands.CommandResult;

import seedu.duke.data.GoalList;
import seedu.duke.goal.GoalList;
import seedu.duke.data.exception.IncorrectFormatException;

public class AchieveGoalCommand extends Command {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import seedu.duke.commands.Command;
import seedu.duke.commands.CommandResult;
import seedu.duke.data.GoalList;
import seedu.duke.goal.GoalList;
import seedu.duke.data.exception.IncorrectFormatException;
import seedu.duke.ui.TextUi;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

import java.io.IOException;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/commands/goal/GoalCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import seedu.duke.Duke;
import seedu.duke.commands.Command;
import seedu.duke.commands.CommandResult;
import seedu.duke.data.GoalList;
import seedu.duke.goal.GoalList;
import seedu.duke.data.exception.IncorrectFormatException;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import seedu.duke.commands.Command;
import seedu.duke.commands.CommandResult;
import seedu.duke.data.GoalList;
import seedu.duke.goal.GoalList;
import seedu.duke.data.exception.IncorrectFormatException;
import seedu.duke.ui.TextUi;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/duke/data/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class Date {

/**
* @param rawData refers to the date String
* @param NotAllowPast true for all goal related commands only
* @throws IncorrectFormatException if failed to parse date string input
*/
public Date(String rawData, Boolean NotAllowPast) throws IncorrectFormatException {
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/seedu/duke/goal/GoalList.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.duke.data;
package seedu.duke.goal;

import seedu.duke.Duke;
import seedu.duke.data.Date;
import seedu.duke.data.exception.IllegalValueException;
import seedu.duke.data.exception.IncorrectFormatException;
import seedu.duke.storagefile.GoalStorage;
Expand Down Expand Up @@ -32,6 +33,9 @@ public int getGoalCount() {
* This method removes a goal object from the global field goals list by indexing
* It also decrements goalCount by 1
* @param cmd Raw user Command
* @throws IOException if failed to access output file
* @throws NumberFormatException if index is invalid number
* @throws IncorrectFormatException is user command is in incorrect format
* @return message of succeeding to delete goal and tell user the updated total number of goals
*/
public static String deleteGoal(String cmd) throws IncorrectFormatException,
Expand Down Expand Up @@ -139,22 +143,24 @@ private static void verifyAchieveGoalInput(String cmd) throws IncorrectFormatExc
* If not, terminate the method and throws error message.
* If yes, continue to add a new goal object into the goals list.
* @param userCmd represents raw user input
* @param Targetlist represents to target list to add new goal
* @param target represents to target list to add new goal
* @param storage represents the target storage to update goal data
* @throws IncorrectFormatException if user input is in wrong format
* @throws NumberFormatException if the user does not input a valid number
* @throws IOException if failed to access and update output file
* @return String about succeeding to create goal object
*/
public static String addGoal(String userCmd, GoalList Targetlist, GoalStorage storage) throws IncorrectFormatException,
public static String addGoal(String userCmd, GoalList target, GoalStorage storage) throws IncorrectFormatException,
NumberFormatException, IOException {
verifyGoalInput(userCmd); //if invalid, exceptions is thrown

String[] cmdSplit = userCmd.split(" ");
int calories = Integer.parseInt(cmdSplit[1]);
String date = cmdSplit[3];

Targetlist.goals.add(new Goal(calories, date));
Targetlist.goalCount++;
storage.overwriteGoalToFile(Targetlist);
target.goals.add(new Goal(calories, date));
target.goalCount++;
storage.overwriteGoalToFile(target);

return TextUi.addGoalSuccessMessage();
}
Expand Down Expand Up @@ -201,5 +207,5 @@ public String toString() {
return "Consume " + this.calories + " kcal on " + this.date;
}
}
}

}
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Parser {
*
* @param userInput full user input string
* @return the command based on the user input
* @throws Exception
* @throws Exception if unexpected exception occurs
*/
public Command parseCommand(String userInput) throws Exception {
final Matcher matcher = BASIC_COMMAND_FORMAT.matcher(userInput.trim());
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/duke/storagefile/AchmStorage.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.duke.storagefile;

import seedu.duke.Duke;
import seedu.duke.data.GoalList;
import seedu.duke.goal.GoalList;
import seedu.duke.ui.TextUi;

import java.io.FileNotFoundException;
Expand Down Expand Up @@ -57,9 +57,9 @@ public void restoreGoalRecord() throws IOException {
}

/**
*
* This method convert the saved text command into the goal object
* @param goalRecord refers to saved goal record
* @throws Exception
* @throws Exception if failed to access file
*/
@Override
protected void textToGoalObject(String goalRecord) throws Exception {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/duke/storagefile/GoalStorage.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.duke.storagefile;

import seedu.duke.Duke;
import seedu.duke.data.GoalList;
import seedu.duke.goal.GoalList;
import seedu.duke.ui.TextUi;

import java.io.FileNotFoundException;
Expand All @@ -28,6 +28,7 @@ public static GoalStorage initializeGoalStorage(String dirName, String textFileP
* if error occurs in loading saved date, the app will start with empty list immediately
* without loading part of data
* Note that this method also set up the file writer into overwrite mode
* @throws IOException if failed to access file or create file
*/
public void restoreGoalRecord() throws IOException {
if (dir.exists() && textFile.exists()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/ui/TextUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import seedu.duke.Duke;
import seedu.duke.commands.CommandResult;
import seedu.duke.data.GoalList;
import seedu.duke.goal.GoalList;
import seedu.duke.data.Printable;

/**
Expand Down

0 comments on commit 28cb8d4

Please sign in to comment.