-
Notifications
You must be signed in to change notification settings - Fork 4
/
Day.java
142 lines (102 loc) · 3.26 KB
/
Day.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package model;
import java.time.LocalDate;
import java.util.ArrayList;
import controllers.food.AddFoodController;
public class Day implements Comparable<Day> {
private LocalDate date;
public static ArrayList<LocalDate> dates = new ArrayList<LocalDate>();
public Day(LocalDate date) {
validateDate(date);
this.date = date;
}
private void validateDate(LocalDate date) {
// Loop through dates arraylist to see if this date already exists
for(int i=0; i<dates.size(); i++) {
if(dates.get(i).equals(date)) {
throw new IllegalArgumentException("Tryig to create day: This date already exists!");
}
}
// Else, store it inside dates
dates.add(date);
}
/**
* Destructively Loads the exercises on this day into the ArrayList passed
*/
public static void loadAddedExercises(Day currentDay, ArrayList<Exercise> addedExercises) {
// loop through the currentDay food
for (int i = 0; i < currentDay.getExercises().size(); i++) {
Exercise f = currentDay.getExercises().get(i);
addedExercises.add(f);
}
}
public static boolean updateQuantity(Day currentDay, AddFoodController controller, boolean found) {
for (int i = 0; i < currentDay.getFoods().size(); i++) {
// Assumes we don't have foods with exactly the same name.. (try adding id in
// later)
if (currentDay.getFoods().get(i).getName().equals(controller.getFood().getName())) {
found = true;
System.out.println("Updating quantity on addEntry");
currentDay.getFoods().get(i).setQuantity(currentDay.getFoods().get(i).getQuantity() + controller.getQuantity());
break;
}
}
return found;
}
private ArrayList<Food> foods = new ArrayList<Food>();
private ArrayList<Exercise> exercises = new ArrayList<Exercise>();
public ArrayList<Exercise> getExercises() {
return exercises;
}
public boolean addExercise(Exercise ex) {
return this.exercises.add(ex);
}
public ArrayList<Food> getFoods() {
return foods;
}
public LocalDate getDate() {
return date;
}
public boolean addFood(Food food) {
return this.foods.add(food);
}
public boolean deleteFood(Food food) {
// Loop backwards into food
for (int i = foods.size() - 1; i >= 0; i--) {
if (foods.get(i).getName().equals(food.getName())) {
return foods.remove(food);
}
}
// Couldn't return a delete
return false;
}
public double getTotalFoodCalories() {
// Loop through all foods and calculate the total calories
double sum = 0;
for (int i = 0; i < foods.size(); i++) {
sum += foods.get(i).getCalories();
}
return sum;
}
public double getTotalExerciseCalories() {
double sum = 0;
for(int i=0; i <exercises.size(); i++) {
sum += exercises.get(i).getCaloriesBurned();
}
return sum;
}
@Override
public int compareTo(Day arg0) {
return date.compareTo(arg0.getDate());
}
public boolean deleteExercise(Exercise exercise) {
// Loop backwards into exercises
for (int i = exercises.size() - 1; i >= 0; i--) {
// Check if these are the same objects
if (exercises.get(i).equals(exercise)) {
return exercises.remove(exercise);
}
}
// Couldn't return a delete
return false;
}
}