Advertisement
Guest User

Untitled

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