Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class LifestyleTracker {
- ArrayList <Food> food;
- ArrayList <Activity> activity;
- ArrayList <String> foodeaten;
- ArrayList <String> activitydone;
- double totalcaloriesburned;
- double totalcaloriesconsumed;
- public LifestyleTracker() {
- food = new ArrayList<Food>();
- activity = new ArrayList<Activity>();
- foodeaten = new ArrayList<String>();
- activitydone = new ArrayList<String>();
- }
- public String addFood(String n, double c) {
- food.add(new Food(n, c));
- String temp = "Added Food " + n + " with " + c + " kcal." ;
- System.out.println(temp);
- return temp;
- }
- public String addActivity(String n, double c) {
- activity.add(new Activity(n,c));
- String temp = "Added Activity " + n + " with " + c + " kcal.";
- System.out.println(temp);
- return temp;
- }
- public String eat(String fn, double servings) {
- if (servings < 0) {
- System.out.println("Number of servings cannot be negative");
- }
- else {
- for(int x = 0; x < food.size(); x++) {
- if( food.get(x).getFoodName().equals(fn)) {
- String message = servings + "serving (s) of" + fn + "," + food.get(x).getFoodCalories() + "kcal";
- foodeaten.add(message);
- totalcaloriesconsumed += (food.get(x).getFoodCalories() * servings);
- String temp = "Ate " + servings + " serving (s) of " + food.get(x).getFoodName() + ", " + (food.get(x).getFoodCalories() * servings) + " kcal";
- System.out.println(temp);
- return temp;
- }
- else {
- String feedback = ("The specific food does not exist");
- System.out.println(feedback);
- return feedback;
- }
- }
- }
- String y = " ";
- return y;
- }
- public String perform(String act, double hours) {
- if (hours < 0) {
- System.out.println("Number of servings cannot be negative");
- }
- else {
- for(int x = 0; x < activity.size(); x++) {
- if( activity.get(x).getActivityName().equals(act)) {
- String message = hours + "hour (s) of" + act + ", " + activity.get(x).getActivityCalories() + "kcal";
- foodeaten.add(message);
- totalcaloriesburned += (activity.get(x).getActivityCalories() * hours);
- String temp = "Performed " + hours + " hour (s) of " + activity.get(x).getActivityName() + ", " + (activity.get(x).getActivityCalories() * hours) + " kcal";
- System.out.println(temp);
- return temp;
- }
- else {
- String feedback = "The specific food does not exist";
- System.out.println(feedback);
- return feedback;
- }
- }
- }
- String y = " ";
- return y;
- }
- public String report() {
- String feedback = "finished";
- return feedback;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement