JAVA The class will have a constructor BMI(String name, double height, double weight).

JAVA

  • The class will have a constructor BMI(String name, double height, double weight).
  • The class should have a public instance method, getBMI() that returns a double reflecting the person’s BMI (Body Mass Index = weight (kg) / height2 (m2) ).
  • The class should have a public toString() method that returns a String like Fred is 1.9m tall and is 87.0Kg and has a BMI of 24.099722991689752Kg/m^2 (just print the doubles without special formatting).
  • Implement this class (if you wish you may implement a main method that demonstrates its use).

Here is my code:

Don't use plagiarized sources. Get Your Custom Essay on
JAVA The class will have a constructor BMI(String name, double height, double weight).
Just from $8 /Page 0r 300 words
Order Now
public class BMI {
    private String name;
    private Double height;
    private Double weight;


    Double getBMI(){
        return weight/(height*height);
    }
    public BMI(String name, Double height, Double weight){
        this.name = name;
        this.height = height;
        this.weight = weight;
    }

    @Override
    public String toString(){
        return name + " is " + height +"m tall and " + weight + "kg and has a BMI of" + getBMI() ;
    }
}

 

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now

In: Computer Science

Looking for a similar assignment? Get help from our qualified experts!

Order Now