Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. import java.util.ArrayList;
  2. public class LifestyleTracker {
  3. ArrayList <Food> food;
  4. ArrayList <Activity> activity;
  5. ArrayList <String> foodeaten;
  6. ArrayList <String> activitydone;
  7. double totalcaloriesburned;
  8. double totalcaloriesconsumed;
  9.  
  10. public LifestyleTracker() {
  11. food = new ArrayList<Food>();
  12. activity = new ArrayList<Activity>();
  13. foodeaten = new ArrayList<String>();
  14. activitydone = new ArrayList<String>();
  15. }
  16.  
  17. public String addFood(String n, double c) {
  18. food.add(new Food(n, c));
  19. String temp = "Added Food " + n + " with " + c + " kcal." ;
  20. System.out.println(temp);
  21. return temp;
  22.  
  23. }
  24. public String addActivity(String n, double c) {
  25. activity.add(new Activity(n,c));
  26. String temp = "Added Activity " + n + " with " + c + " kcal.";
  27. System.out.println(temp);
  28. return temp;
  29. }
  30. public String eat(String fn, double servings) {
  31.  
  32. if (servings < 0) {
  33. System.out.println("Number of servings cannot be negative");
  34. }
  35. else {
  36. for(int x = 0; x < food.size(); x++) {
  37. if( food.get(x).getFoodName().equals(fn)) {
  38. String message = servings + "serving (s) of" + fn + "," + food.get(x).getFoodCalories() + "kcal";
  39. foodeaten.add(message);
  40. totalcaloriesconsumed += (food.get(x).getFoodCalories() * servings);
  41. String temp = "Ate " + servings + " serving (s) of " + food.get(x).getFoodName() + ", " + (food.get(x).getFoodCalories() * servings) + " kcal";
  42. System.out.println(temp);
  43. return temp;
  44. }
  45. else {
  46. String feedback = ("The specific food does not exist");
  47. System.out.println(feedback);
  48. return feedback;
  49. }
  50. }
  51. }
  52. String y = " ";
  53. return y;
  54.  
  55. }
  56. public String perform(String act, double hours) {
  57. if (hours < 0) {
  58. System.out.println("Number of servings cannot be negative");
  59. }
  60. else {
  61. for(int x = 0; x < activity.size(); x++) {
  62. if( activity.get(x).getActivityName().equals(act)) {
  63. String message = hours + "hour (s) of" + act + ", " + activity.get(x).getActivityCalories() + "kcal";
  64. foodeaten.add(message);
  65. totalcaloriesburned += (activity.get(x).getActivityCalories() * hours);
  66. String temp = "Performed " + hours + " hour (s) of " + activity.get(x).getActivityName() + ", " + (activity.get(x).getActivityCalories() * hours) + " kcal";
  67. System.out.println(temp);
  68. return temp;
  69. }
  70. else {
  71. String feedback = "The specific food does not exist";
  72. System.out.println(feedback);
  73. return feedback;
  74. }
  75. }
  76. }
  77. String y = " ";
  78. return y;
  79.  
  80.  
  81. }
  82. public String report() {
  83.  
  84. String feedback = "finished";
  85. return feedback;
  86.  
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement