Design a class that can be used by a health care professional to keep track of a patient’s vital statistics. The following are the details.
Name of the class - Patient
Member Variables - patientName(String),height(double),width(double)
Member Function - double computeBMI()
The above method should compute the BMI and return the result. The formula for the computation of BMI is weight (in kg) ÷ height*height(in metres).
Create an object of the Patient class and check the results.
Source code:
1: public class Patient {
2: String patientName;
3: double height, weight;
4: Patient(String name, double height, double weight){
5: this.patientName = name;
6: this.height = height;
7: this.weight = weight;
8: }
9: double computeBMI() {
10: // BMI = ( Weight in Pounds / ( Height in inches x Height in inches ) ) x 703
11: return ( weight / ( height * height ) ) * 703;
12: }
13: public static void main(String[] args) {
14: // TODO Auto-generated method stub
15: Patient patient = new Patient("XYZ", 177/2.54, 59*2.2);
16: System.out.println("Name: " + patient.patientName + "\nBMI: " + patient.computeBMI());
17: }
18: }