Skip to content

Commit

Permalink
Merge pull request #118 from MustafaAH10/branch-Mustafa
Browse files Browse the repository at this point in the history
Fix bugs
  • Loading branch information
MustafaAH10 authored Mar 31, 2023
2 parents a31cb03 + 403943e commit 04c9b6e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
8 changes: 2 additions & 6 deletions myLogFile.log
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
Mar 28, 2023 6:43:16 PM seedu.logger.LogFileHandler logInfo
INFO: Breakfast was consumed on 1/1/2023
Total Calories are: 12.5
Here are the foods you ate:
1) White Chicken (1 Pax) from Chicken Rice

Mar 31, 2023 12:24:20 PM seedu.logger.LogFileHandler logInfo
INFO: User exited the programme.
3 changes: 2 additions & 1 deletion src/main/java/seedu/commands/TrackCalorieCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public void execute(GeneralUi ui, FoodStorage foodStorage, MealStorage mealStora
System.out.println("No Meals and Exercises Found!");
return;
}
System.out.println("Showing your history from " + startDate + " to " + endDate);

while (startDate.compareTo(endDate) < 0) {
while (startDate.compareTo(endDate) <= 0) {
caloriesConsumed = caloriesBurnt = 0;
filteredMeals = mealStorage.getMealByDate(startDate);
filteredExercises = exerciseStorage.getExercisesByDate(startDate);
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/seedu/entities/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Exercise {
public class Exercise implements Comparable<Exercise>{
protected String exerciseName;
protected float caloriesBurnt;
protected String exerciseDescription;
Expand Down Expand Up @@ -66,4 +66,16 @@ public void setDate(LocalDate date) {
this.date = date;
}

@Override
public int compareTo(Exercise otherExercise) {
if (getDate() == null || otherExercise.getDate() == null) {
return 0;
}
int comparator = this.getDate().compareTo(otherExercise.getDate());
if (comparator != 0) {
return comparator;
} else {
return Float.compare(this.getCaloriesBurnt(), otherExercise.getCaloriesBurnt());
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/seedu/storage/ExerciseStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -66,6 +67,7 @@ public void write() throws IOException {
CSVWriter.RFC4180_LINE_END);
String[] header = { "Exercise Name", "Exercise Description", "Calories Burnt" };
writer.writeNext(header);
Collections.sort(exercises);
for (Exercise exercise : exercises) {
writer.writeNext(exercise.toWriteFormat(CSV_DELIMITER, DTF));
}
Expand Down
4 changes: 2 additions & 2 deletions text-ui-test/myLogFile.log
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Mar 28, 2023 9:44:19 PM seedu.logger.LogFileHandler logInfo
Mar 31, 2023 12:25:37 PM seedu.logger.LogFileHandler logInfo
INFO: User exited the programme.
Mar 28, 2023 9:44:19 PM seedu.logger.LogFileHandler logInfo
Mar 31, 2023 12:25:37 PM seedu.logger.LogFileHandler logInfo
INFO: Error saving databases!

0 comments on commit 04c9b6e

Please sign in to comment.