Larkman

Untitled

Oct 2nd, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. package bodymassindex;
  2. import java.util.Scanner;
  3.  
  4. /**
  5. *
  6. * @author cristy
  7. */
  8. public class BodyMassIndex {
  9. public static Person anyPerson;
  10. /**
  11. * @param args the command line arguments
  12. */
  13.  
  14.  
  15. public static void main(String[] args)
  16. {
  17.  
  18. createPersonObject();
  19. displayBMI();
  20.  
  21. }
  22.  
  23. public static void createPersonObject()
  24. {
  25. //Ask user for their first name, height in inches, and weight in pounds.
  26.  
  27. String firstName;
  28. double heightInches;
  29. double weightPounds;
  30.  
  31.  
  32. Scanner glassCup = new Scanner(System.in);
  33.  
  34. System.out.println("What is your First Name?");
  35. firstName = glassCup.nextLine();
  36. System.out.println("How much do you weigh (in pounds)?");
  37. weightPounds = glassCup.nextDouble();
  38. System.out.println("How tall are you(in inches)?");
  39. heightInches = glassCup.nextDouble();
  40.  
  41.  
  42. //Create a Person object and store it in the static variable, anyPerson
  43.  
  44. Person Vanga = new Person(firstName, weightPounds, heightInches);
  45.  
  46. anyPerson = Vanga;
  47.  
  48. }
  49. public static void displayBMI()
  50. {
  51.  
  52. //Call the method in the anyPerson object that calculates BMI
  53. double BMI;
  54.  
  55. BMI = Person.calculateBMI(anyPerson.getWeight(), anyPerson.getHeight());
  56.  
  57. System.out.print("Your BMI is ");
  58. System.out.printf("%.2f",BMI);
  59. System.out.println( );
  60.  
  61.  
  62.  
  63. if(BMI < 18.5)
  64. System.out.println("A BMI below 18.5 is considered underweight.");
  65. else if(BMI < 24.9)
  66. System.out.println("A BMI of 18.5 to 24.9 is considered healthy.");
  67. else if(BMI < 29.9)
  68. System.out.println("A BMI of 25 to 29.9 is considered overweight.");
  69. else if(BMI > 30 )
  70. System.out.println("A BMI of 30 or higher is considered obese.");
  71. else System.out.println();
  72. }
  73.  
  74. //Display the BMI of the anyPerson object.
  75. //Display the appropriate message to the user, depending on
  76. //the following ranges:
  77.  
  78. //A BMI below 18.5 is considered underweight.
  79. //A BMI of 18.5 to 24.9 is considered healthy.
  80. //A BMI of 25 to 29.9 is considered overweight.
  81. //A BMI of 30 or higher is considered obese.
  82. }
  83.  
  84.  
  85. ----
  86.  
  87. PERSON
  88.  
  89. ----
  90.  
  91. /*
  92. * To change this license header, choose License Headers in Project Properties.
  93. * To change this template file, choose Tools | Templates
  94. * and open the template in the editor.
  95. */
  96. package bodymassindex;
  97.  
  98. /**
  99. *
  100. * @author cristy
  101. */
  102. public class Person {
  103.  
  104. private String firstName;
  105. private double heightInches;
  106. private double weightPounds;
  107.  
  108.  
  109. public Person (String aFirstName, double aWeightPounds, double aHeightInches)
  110. {
  111. //Complete constructor here.
  112.  
  113. firstName = aFirstName;
  114. heightInches = aHeightInches;
  115. weightPounds = aWeightPounds;
  116.  
  117.  
  118.  
  119.  
  120. //Remember to move each parameter to its corresponding instance variable:
  121. }
  122.  
  123. //Create all the getters for the attributes here:
  124.  
  125.  
  126. public String getFirstName(){
  127. return firstName;
  128. }
  129. public double getHeight(){
  130. return heightInches;
  131. }
  132. public double getWeight(){
  133. return weightPounds;
  134. }
  135.  
  136. //Create all the setters for the attributes here:
  137.  
  138.  
  139. //Create the .toString() method here:
  140.  
  141.  
  142.  
  143.  
  144. //Create the calculateBMI() method here, using the following formulat:
  145. //BMI= [weight in pounds / (height in inches) X (height in inches)] X 703
  146. public static double calculateBMI(double weight, double height) {
  147.  
  148. double finalBMI;
  149. finalBMI = (weight / (height * height)) * 703;
  150. return finalBMI;
  151.  
  152. }
  153.  
  154.  
  155. }
Advertisement
Add Comment
Please, Sign In to add comment