Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bodymassindex;
- import java.util.Scanner;
- /**
- *
- * @author cristy
- */
- public class BodyMassIndex {
- public static Person anyPerson;
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- createPersonObject();
- displayBMI();
- }
- public static void createPersonObject()
- {
- //Ask user for their first name, height in inches, and weight in pounds.
- String firstName;
- double heightInches;
- double weightPounds;
- Scanner glassCup = new Scanner(System.in);
- System.out.println("What is your First Name?");
- firstName = glassCup.nextLine();
- System.out.println("How much do you weigh (in pounds)?");
- weightPounds = glassCup.nextDouble();
- System.out.println("How tall are you(in inches)?");
- heightInches = glassCup.nextDouble();
- //Create a Person object and store it in the static variable, anyPerson
- Person Vanga = new Person(firstName, weightPounds, heightInches);
- anyPerson = Vanga;
- }
- public static void displayBMI()
- {
- //Call the method in the anyPerson object that calculates BMI
- double BMI;
- BMI = Person.calculateBMI(anyPerson.getWeight(), anyPerson.getHeight());
- System.out.print("Your BMI is ");
- System.out.printf("%.2f",BMI);
- System.out.println( );
- if(BMI < 18.5)
- System.out.println("A BMI below 18.5 is considered underweight.");
- else if(BMI < 24.9)
- System.out.println("A BMI of 18.5 to 24.9 is considered healthy.");
- else if(BMI < 29.9)
- System.out.println("A BMI of 25 to 29.9 is considered overweight.");
- else if(BMI > 30 )
- System.out.println("A BMI of 30 or higher is considered obese.");
- else System.out.println();
- }
- //Display the BMI of the anyPerson object.
- //Display the appropriate message to the user, depending on
- //the following ranges:
- //A BMI below 18.5 is considered underweight.
- //A BMI of 18.5 to 24.9 is considered healthy.
- //A BMI of 25 to 29.9 is considered overweight.
- //A BMI of 30 or higher is considered obese.
- }
- ----
- PERSON
- ----
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package bodymassindex;
- /**
- *
- * @author cristy
- */
- public class Person {
- private String firstName;
- private double heightInches;
- private double weightPounds;
- public Person (String aFirstName, double aWeightPounds, double aHeightInches)
- {
- //Complete constructor here.
- firstName = aFirstName;
- heightInches = aHeightInches;
- weightPounds = aWeightPounds;
- //Remember to move each parameter to its corresponding instance variable:
- }
- //Create all the getters for the attributes here:
- public String getFirstName(){
- return firstName;
- }
- public double getHeight(){
- return heightInches;
- }
- public double getWeight(){
- return weightPounds;
- }
- //Create all the setters for the attributes here:
- //Create the .toString() method here:
- //Create the calculateBMI() method here, using the following formulat:
- //BMI= [weight in pounds / (height in inches) X (height in inches)] X 703
- public static double calculateBMI(double weight, double height) {
- double finalBMI;
- finalBMI = (weight / (height * height)) * 703;
- return finalBMI;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment