Skip to content

Commit

Permalink
Add comments to ExerciseLog and associated classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Remy9926 committed Oct 20, 2023
1 parent 15f9e6c commit 29e56e7
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public DeleteLogCommand(List<String> exerciseDetails) {
this.exerciseDetails = exerciseDetails;
}

/**
* Extracts the details of the delete command and deletes the specified exercise.
*
* @return CommandResult that tells the user whether an exercise was successfully removed.
*/
public CommandResult execute() {
int month = Integer.parseInt(exerciseDetails.get(0));
int day = Integer.parseInt(exerciseDetails.get(1));
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/duke/commands/logcommands/LogCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public LogCommand(List<String> exerciseDetails) {
this.exerciseDetails = exerciseDetails;
}

/**
* Extracts the details of the log command and logs the exercise with its specific details.
*
* @return CommandResult telling the user that the exercise was successfully added along with the exercise details.
*/
public CommandResult execute() {
int month = Integer.parseInt(exerciseDetails.get(0));
int day = Integer.parseInt(exerciseDetails.get(1));
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/duke/commands/logcommands/ViewLogCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public ViewLogCommand() {
super();
}

/**
* Assigns the view attribute a specific enum based on the scope at which the user wants to view the exercise log.
*
* @param viewArgs the details of the scope at which the user wants to view the exercise log.
*/
public ViewLogCommand(List<String> viewArgs) {
super();
switch (viewArgs.get(0)) {
Expand All @@ -43,6 +48,11 @@ public ViewLogCommand(List<String> viewArgs) {
}
}

/**
* A different message is returned depending on the scope at which a user wants to view their exercises.
*
* @return CommandResult telling the user their total number of exercises in total, for a month, or for a day.
*/
public CommandResult execute() {
String numberOfExercises;
switch (view) {
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/seedu/duke/exerciselog/Day.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,63 @@ public Day() {
exercises = new ArrayList<>();
}

/**
* Instantiates and adds a new Exercise Object into the Day.
*
* @param exerciseName the name of the exercise to be added to the day
* @param caloriesBurned the number of calories burned during the exercise
* @return a string representing the new exercise
*/
public String addExercise(String exerciseName, int caloriesBurned) {
Exercise newExercise = new Exercise(exerciseName, caloriesBurned);
exercises.add(newExercise);
return newExercise.toString();
}

/**
* Attempts to remove an exercise with the specified details and returns whether or not removal was successful.
*
* @param exerciseName the name of the exercise to be removed
* @param caloriesBurned the number of calories burned during the exercise
* @return true if an exercise was successfully removed, false otherwise
*/
public boolean removeExercise(String exerciseName, int caloriesBurned) {
return exercises.remove(new Exercise(exerciseName, caloriesBurned));
}

/**
* Returns the exercise object at the specified index for the Day.
*
* @param index the number of the exercise the user wants to check on
* @return the exercise object at the specified index
*/
public Exercise getExercise(int index) {
return exercises.get(index - 1);
}

/**
* Returns the total number of exercises logged for the day.
*
* @return the total number of exercises logged for the day.
*/
public Integer getNumberOfExercises() {
return exercises.size();
}

/**
* Returns whether the Day has exercises or not
*
* @return true if there are exercises, false if not
*/
public boolean containsExercises() {
return !exercises.isEmpty();
}

/**
* Returns a string representing all the exercises contained for the Day.
*
* @return a string representing all the exercises for the day
*/
public String toString() {
if (exercises.isEmpty()) {
return "\tNO EXCERCISES FOR THIS DAY!\n";
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/seedu/duke/exerciselog/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,37 @@ public Log() {
exerciseLog.add(new Month(31, "dec")); // Dec 31
}

/**
* Adds an exercise to the specified month and day with the specified name and number of calories burned.
*
* @param month the month of the exercise to be added to the log
* @param day the day of the month of the exercise to be added to the log
* @param exerciseName the name of the exercise to be added to the log
* @param caloriesBurned the number of calories burned by the exercise
* @return the string representation of the exercise that is added to the log
*/
public String addExercise(int month, int day, String exerciseName, int caloriesBurned) {
return exerciseLog.get(month - 1).addExercise(day, exerciseName, caloriesBurned);
}

/**
* Attempts to remove the specified exercise from the log and returns true only if removal is successful.
*
* @param month the month of the exercise to be deleted from the log
* @param day the day of the month of the exercise to be deleted from the log
* @param exerciseName the name of the exercise to be deleted from the log
* @param caloriesBurned the number of calories burned by the exercise
* @return true if the exercise was removed, false otherwise
*/
public boolean removeExercise(int month, int day, String exerciseName, int caloriesBurned) {
return exerciseLog.get(month - 1).removeExercise(day, exerciseName, caloriesBurned);
}

/**
* Returns the total number of exercises logged
*
* @return the total number of exercises logged
*/
public int getNumberOfExercises() {
int totalNumber = 0;
for (Month m: exerciseLog) {
Expand All @@ -37,22 +60,53 @@ public int getNumberOfExercises() {
return totalNumber;
}

/**
* Returns the total number of exercises logged for the specific month
*
* @param month the month to be checked
* @return the total number of exercises logged for the specific month
*/
public int getNumberOfExercisesForMonth(int month) {
return exerciseLog.get(month - 1).getTotalNumberOfExercises();
}

/**
* Returns the total number of exercises logged for the specific day of the specified month
*
* @param month the month to be checked
* @param day the day of the month to be checked
* @return the total number of exercises logged for a specific day of the month
*/
public int getNumberOfExercisesForDay(int month, int day) {
return exerciseLog.get(month - 1).getNumberOfExercisesForDay(day);
}

/**
* Returns the Month object of the specified month.
*
* @param month the month to be checked
* @return the Month object of the specified month
*/
public Month getMonth(int month) {
return exerciseLog.get(month - 1);
}

/**
* Returns the Day object of the specified day.
*
* @param month the month to be checked
* @param day the day of the month to be checked
* @return the Day object of the specified month and day
*/
public Day getDay(int month, int day) {
return exerciseLog.get(month - 1).getDay(day - 1);
}

/**
* The string representation of the exercise log, showing each month with their days and exercises
*
* @return the string representation of the exercise log
*/
public String toString() {
String newString = "";
for (Month m: exerciseLog) {
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/seedu/duke/exerciselog/Month.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,35 @@ public Month(int days, String name) {
}
}

/**
* Adds an exercise with the specified name and calories burned to the specified day.
*
* @param day the day to add the exercise to
* @param exerciseName the name of the exercise
* @param caloriesBurned the number of calories burned by the exercise
* @return the string representation of the new exercise created
*/
public String addExercise(int day, String exerciseName, int caloriesBurned) {
return dates.get(day - 1).addExercise(exerciseName, caloriesBurned);
}

/**
* Attempts to remove the specified exercise at the specified day of the month
*
* @param day the day to remove the exercise from
* @param exerciseName the name of the exercise to be removed
* @param caloriesBurned the number of calories burned by the exercise
* @return true if the exercise was removed, false otherwise
*/
public boolean removeExercise(int day, String exerciseName, int caloriesBurned) {
return dates.get(day - 1).removeExercise(exerciseName, caloriesBurned);
}

/**
* Returns the total number of exercises for the month
*
* @return the total number of exercises for the month
*/
public int getTotalNumberOfExercises() {
int totalExercises = 0;
for (Day d: dates) {
Expand All @@ -30,22 +51,50 @@ public int getTotalNumberOfExercises() {
return totalExercises;
}

/**
* Returns a Day object of the day specified
*
* @param day the number of the day to be returned
* @return a Day object of the specified day
*/
public Day getDay(int day) {
return dates.get(day - 1);
}

/**
* Returns the total number of exercises for the specified day
*
* @param day the day to be checked
* @return the total number of exercises for the specified day
*/
public int getNumberOfExercisesForDay(int day) {
return dates.get(day - 1).getNumberOfExercises();
}

/**
* Returns the name of the month
*
* @return the name of the month
*/
public String getName() {
return name;
}

/**
* Returns the number of days in the month
*
* @return the number of days in the month
*/
public int getNumberOfDays() {
return dates.size();
}

/**
* Returns the string representation of the month by showing the name of the month and each of its days and
* exercises
*
* @return the string representation of the month
*/
public String toString() {
String newString = "Month: " + name.toUpperCase() + "\n";
for (int i = 0; i < dates.size(); i++) {
Expand Down

0 comments on commit 29e56e7

Please sign in to comment.