|
package model; |
|
|
|
import java.text.DateFormat; |
|
import java.text.SimpleDateFormat; |
|
import java.util.ArrayList; |
|
import java.util.Date; |
|
import java.time.*; |
|
|
|
public class DietLog { |
|
|
|
protected int totalCalories; |
|
protected double totalCaloriesBurned; |
|
protected double totalFat; |
|
protected double totalProtein; |
|
protected double totalCarbs; |
|
protected double dailyLimit; |
|
protected double dailyWeight; |
|
protected String currentDate; |
|
|
|
private int fatPerc; |
|
private int carbPerc; |
|
private int proteinPerc; |
|
|
|
|
|
protected DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); |
|
protected Date date = new Date(); |
|
|
|
private ArrayList<Food> dailyFood = new ArrayList<>(); |
|
private ArrayList<Exercise> dailyExercise = new ArrayList<>(); |
|
|
|
|
|
public DietLog() { |
|
currentDate = dateFormat.format(date); |
|
} |
|
|
|
|
|
public int getTotalCalories() { |
|
return totalCalories; |
|
} |
|
|
|
public double getTotalCaloriesBurned(){ return totalCaloriesBurned;} |
|
|
|
|
|
public double getTotalFat() { |
|
return totalFat; |
|
} |
|
|
|
|
|
public double getTotalProtein() { |
|
return totalProtein; |
|
} |
|
|
|
|
|
public double getTotalCarbs() { |
|
return totalCarbs; |
|
} |
|
|
|
public double getDailyWeight() { |
|
return dailyWeight; |
|
} |
|
|
|
public double getDailyLimit() { return dailyLimit; } |
|
|
|
public double getFatPerc() { |
|
return fatPerc; |
|
} |
|
|
|
public double getCarbPerc() { |
|
return carbPerc; |
|
} |
|
|
|
public double getProteinPerc() { |
|
return proteinPerc; |
|
} |
|
|
|
|
|
public void setDailyLimit(double calorieLimit) { |
|
dailyLimit = calorieLimit; |
|
} |
|
|
|
|
|
public void setDailyWeight(double weight) { |
|
dailyWeight = weight; |
|
} |
|
|
|
|
|
public double getNetCals(){ |
|
return totalCalories - totalCaloriesBurned; |
|
} |
|
|
|
|
|
public void logFood(Food foodItem, double servings) { |
|
foodItem.setServing(servings); |
|
dailyFood.add(foodItem); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public double caloriesBurned(Exercise exer, double time){ |
|
double burnedCals = exer.getCaloriesBurned() * (this.dailyWeight / 100.0) * (time / 60); |
|
totalCaloriesBurned += burnedCals; |
|
return burnedCals; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
public void logExercise(Exercise exer, double time){ |
|
double burnedCalories = caloriesBurned(exer, time); |
|
|
|
exer.setCaloriesBurned(burnedCalories); |
|
exer.setTime(time); |
|
dailyExercise.add(exer); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void removeExerciseByIndex(int index){ |
|
dailyExercise.remove(index); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ArrayList<Exercise> getDailyExercise() { |
|
return dailyExercise; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ArrayList<String> getExerciseInfo() { |
|
ArrayList<String> ExerciseInfoList = new ArrayList<>(); |
|
for(Exercise e: dailyExercise){ |
|
String eName = e.getName(); |
|
double calsBurned = e.getCaloriesBurned(); |
|
String exerInfo = "Name: " + eName + "\nCalories: " + calsBurned; |
|
ExerciseInfoList.add(exerInfo); |
|
} |
|
|
|
return ExerciseInfoList; |
|
|
|
} |
|
|
|
|
|
public void removeFood(Food foodItem) { |
|
dailyFood.remove(foodItem); |
|
} |
|
|
|
public void removeFoodByIndex(int index) { |
|
dailyFood.remove(index); |
|
} |
|
|
|
public ArrayList<Food> getDailyFood() { |
|
return dailyFood; |
|
} |
|
|
|
|
|
|
|
public ArrayList<String> getFoodInfo() { |
|
ArrayList<String> foodInfoList = new ArrayList<>(); |
|
|
|
for(Food food : dailyFood) { |
|
String foodName = food.getName(); |
|
int foodCalories = food.getCalories(); |
|
double foodServings = food.getServing(); |
|
|
|
String foodInfo = "Name: " + foodName + "\nCalories: " + foodCalories + "\nServings: " + foodServings; |
|
foodInfoList.add(foodInfo); |
|
} |
|
|
|
return foodInfoList; |
|
} |
|
|
|
|
|
|
|
public DietLog calcTotals() { |
|
int totalCals = 0; |
|
double totalBurned = 0; |
|
double totalFats = 0; |
|
double totalProtein = 0; |
|
double totalCarbs = 0; |
|
|
|
for(Food food : dailyFood) { |
|
double foodServing = food.getServing(); |
|
totalCals += (food.getCalories() * foodServing); |
|
totalFats += (food.getFat() * foodServing); |
|
totalProtein += (food.getProtein() * foodServing); |
|
totalCarbs += (food.getCarbs() * foodServing); |
|
} |
|
|
|
for(Exercise e: dailyExercise){ |
|
totalBurned += e.getCaloriesBurned(); |
|
} |
|
|
|
this.totalCalories = totalCals; |
|
this.totalCaloriesBurned = totalBurned; |
|
this.totalFat = totalFats; |
|
this.totalProtein = totalProtein; |
|
this.totalCarbs = totalCarbs; |
|
|
|
calcPercentages(); |
|
|
|
return this; |
|
} |
|
|
|
public double calcCalDiff() { |
|
int caloriesEaten = this.totalCalories; |
|
double caloriesBurned = this.totalCaloriesBurned; |
|
double caloriesLeft = dailyLimit - caloriesEaten + caloriesBurned; |
|
|
|
return caloriesLeft; |
|
} |
|
|
|
public void calcPercentages() { |
|
double totalNutrients = this.totalCarbs + this.totalProtein + this.totalFat; |
|
|
|
|
|
this.fatPerc = (int) Math.rint(this.totalFat/totalNutrients * 100); |
|
this.carbPerc = (int) Math.rint(this.totalCarbs/totalNutrients * 100); |
|
this.proteinPerc = (int) Math.rint(this.totalProtein/totalNutrients * 100); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
} |