Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. public class Healthy
  2. {
  3. //instance variables
  4. private String name;
  5. private char gender;
  6. private double weight;
  7. private double height;
  8. private int age;
  9. private int actLevel;
  10. private String status;
  11.  
  12. //Constructor
  13. public Healthy()
  14. {
  15.  
  16.  
  17.  
  18.  
  19. }//Healthy
  20.  
  21. //Accessors
  22. public String getName()
  23. {
  24. return name;
  25. }
  26.  
  27. public char getGender()
  28. {
  29. return gender;
  30. }
  31.  
  32. public double getWeight()
  33. {
  34. return weight;
  35. }
  36.  
  37. public double getHeight()
  38. {
  39. return height;
  40. }
  41.  
  42. public int getAge()
  43. {
  44. return age;
  45. }
  46.  
  47. public int getActLevel()
  48. {
  49. return actLevel;
  50. }
  51.  
  52. public double calcBmr()
  53. {
  54.  
  55. double bmr;
  56. if (gender == 'M' || gender == 'm')
  57. {
  58. bmr = (66 + (13.7* calcWeightKg()) + (5 * calcHeightCm()) - (6.8 * age));
  59. }
  60. else
  61. {
  62. bmr = (655 + (9.6 * calcWeightKg()) + (1.8 * calcHeightCm()) - (4.7 * age));
  63. }
  64. return bmr;
  65.  
  66.  
  67. }//calcBmr
  68.  
  69.  
  70. public double calcBmi()
  71. {
  72. return (weight)/ (height * height) * 703;
  73.  
  74.  
  75. }//calcBmi
  76.  
  77. //method to calculate TDEE based on bmr
  78. public double calcTdee()
  79. {
  80. double tdee = 0.0;
  81. switch (actLevel)
  82. {
  83. case 1:
  84. tdee = calcBmr() * 1.2;
  85. break;
  86. case 2:
  87. tdee = calcBmr() * 1.375;
  88. break;
  89. case 3:
  90. tdee = calcBmr() * 1.55;
  91. break;
  92. case 4:
  93. tdee = calcBmr() * 1.725;
  94. break;
  95. case 5:
  96. tdee = calcBmr() * 1.9;
  97. break;
  98. default:
  99. tdee = 0.0;
  100. break;
  101. }
  102. return tdee;
  103. }
  104.  
  105. //calculates weight in kg
  106. private double calcWeightKg()
  107. {
  108. return weight/2.20462262;
  109. }
  110. //calculates height in cm
  111. private double calcHeightCm()
  112. {
  113. return height*2.54;
  114. }
  115.  
  116. //determines weight status
  117. public String calcStatus()
  118. {
  119. if (calcBmi() < 18.5)
  120. {
  121. status = "Your BMI classifies you as Underweight";
  122. }
  123. if (calcBmi() >= 18.5 && calcBmi() < 25)
  124.  
  125. {
  126. status = "Your BMI classifies you as Normal Weight";
  127. }
  128. if (calcBmi() >= 25 && calcBmi() < 30)
  129. {
  130. status ="Your BMI classifies you as Overweight";
  131. }
  132. if (calcBmi() >= 30)
  133. {
  134. status = "Your BMI classifies you as Obese";
  135. }
  136. return status;
  137. }//calcStatus
  138.  
  139. //mutators
  140.  
  141. public boolean setName(String inName)
  142. {
  143. if (inName.length() == 0)
  144. {
  145. return false;
  146. }
  147. else
  148. {
  149. name = inName;
  150. return true;
  151. }
  152. }
  153.  
  154. public boolean setGender(char inGender)
  155. {
  156. //inGender = inGender.toUpperCase();
  157. if (inGender == 'M' || inGender == 'm' || inGender == 'F' || inGender == 'f')
  158. {
  159. gender = inGender;
  160. return true;
  161. }
  162. else
  163. {
  164. return false;
  165. }
  166. }
  167.  
  168. public boolean setWeight(double inWeight)
  169. {
  170. if (inWeight < 100)
  171. {
  172. return false;
  173. }
  174. else
  175. {
  176. weight = inWeight;
  177. return true;
  178. }
  179.  
  180. }
  181.  
  182. public boolean setHeight(double inHeight)
  183. {
  184. if (inHeight >= 85 || inHeight <= 59)
  185. {
  186. return false;
  187. }
  188. else
  189. {
  190. height = inHeight;
  191. return true;
  192. }
  193.  
  194.  
  195. }
  196.  
  197. public boolean setAge(int inAge)
  198. {
  199. if (inAge < 18)
  200. {
  201. return false;
  202. }
  203. else
  204. {
  205. age = inAge;
  206. return true;
  207. }
  208. }
  209.  
  210. public boolean setActLevel(int inActLevel)
  211. {
  212. if (inActLevel < 1 || inActLevel > 5)
  213. {
  214. return false;
  215. }
  216. else
  217. {
  218. actLevel = inActLevel;
  219. return true;
  220. }
  221. }
  222.  
  223.  
  224. }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement