Java Help 1. Create a class named Checkup with fields that hold a patient number
ID: 3601000 • Letter: J
Question
Java Help
1. Create a class named Checkup with fields that hold a patient number, two blood pressure figures (systolic and diastolic), and two cholesterol figures (LDL and HDL).
a. Include a constructor that initializes the patient number.
b. Include methods to get and set each of the fields.
c. Include a method double computeRatio() that divides LDL cholesterol by HDL cholesterol and returns the result.
d. Include a method String toString() that returns a string containing the values of all instance variables, as well as the result of computeRatio(), and a statement explaining that HDL is known as “good cholesterol” and that a ratio of 3.5 or lower is considered optimum.
2. Write an application called TestCheckup that instantiates at least two Checkup objects and calls each method of the class at least once.
Explanation / Answer
Question 1
Program
import java.util.*;
public class Checkup{
private int patientNumber;
private float systolic;
private float diastolic;
private float ldl;
private float hdl;
// constructor that initializes the patient number by Including methods to get and set each of the fields.
public void setpatientNumber(int patientNumber) { // Constructor for patientNumber
this.patientNumber = patientNumber;
}
public int getpatientnumber() { // get method for Patientnumber
return patientNumber;
}
// Get and set methods for Systolic
public void setSystolic(float systolic) { // constructor
this.systolic = systolic;
}
public float getSystolic() { // get method for Systolic having return type float.
return systolic;
}
// Get and set methods for diastolic
public float getDiastolic() { // get method for Diastolic having return type float.
return diastolic;
}
public void setDiastolic(float diastolic) { // constructor for setDiastolic method
this.diastolic = diastolic;
}
// Get and set methods for LD1
public void setLdl(float ldl) { // constructor
this.ldl = ldl;
}
public float getLdl() {
return ldl;
}
// Get and set methods for HD1
public void setHdl(float hdl) { // constructor
this.hdl = hdl;
}
public float getHdl() {
return hdl;
}
// computeRatio function definition that simply calculates ld1/hd1 and store the value in "result" variable with double as return type.
public double computeRatio(){
double result = ldl / hdl;
System.out.println("Ratio of ld1 and hd1 is -->" + result);
return result;
}
public String toString(){
System.out.println("HDL is known as “good cholesterol” and that a ratio of 3.5 or lower is considered optimum");
}
} // end of Checkup class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.