12. a. Create a class named Checkup with fields that hold a patient Number, two
ID: 3625498 • Letter: 1
Question
12. a. Create a class named Checkup with fields that hold a patient Number, two blood pressure figures(systolic and diastolic), and two cholesterol figure(LDL and HDL). Include methods to get and set each of the fields. Include a method named computeRatio() that divides LDL choloesterol by HDL cholesterol and displays the result. Inclue additional method named ExplainRatio() that explains that HDL is known as "good cholesterol' and that a ratio of 3.5 or lower is considered optimum. Save the class as Checkup.java.b. Create a class named TestCheckup whose main() method declares four Checkup objects. Provide values for each field for each patient. Then display the values. Blood pressure numbers are usually displayed with a slash between the systolic and diastolic values.(Typical numbers are values such as 110/78 or 130/90.)With the cholesterol figures, display the explanation of the cholesterol ratio calculation.(Typical numbers are values such as 100 and 40 or 10 and 70.) Save the program as TestCheckup.java.
Explanation / Answer
Checkup.java
public class Checkup {
private int patientNumber;
private int systolic;
private int diastolic;
private int ldl;
private int hdl;
public Checkup(int patientNumber, int systolic, int diastolic, int ldl,
int hdl) {
this.patientNumber = patientNumber;
this.systolic = systolic;
this.diastolic = diastolic;
this.ldl = ldl;
this.hdl = hdl;
}
public int getPatientNumber() {
return patientNumber;
}
public void setPatientNumber(int patientNumber) {
this.patientNumber = patientNumber;
}
public int getSystolic() {
return systolic;
}
public void setSystolic(int systolic) {
this.systolic = systolic;
}
public int getDiastolic() {
return diastolic;
}
public void setDiastolic(int diastolic) {
this.diastolic = diastolic;
}
public int getLdl() {
return ldl;
}
public void setLdl(int ldl) {
this.ldl = ldl;
}
public int getHdl() {
return hdl;
}
public void setHdl(int hdl) {
this.hdl = hdl;
}
public double computeRatio() {
return ((double) ldl) / hdl;
}
public void explainRatio() {
System.out.println("HDL is known as 'good cholesterol'. A ratio of 3.5 or lower is considered optimum.");
}
}
------------------------------------------
TestCheckup.java
public class TestCheckup {
public static void displayCheckup(Checkup c) {
System.out.println("Results for patient "+c.getPatientNumber());
System.out.println("Blood pressure: "+c.getSystolic()+"/"+c.getDiastolic());
System.out.println("LDL cholesterol: "+c.getLdl());
System.out.println("HDL cholesterol: "+c.getHdl());
System.out.println("Cholesterol ratio: "+c.computeRatio());
c.explainRatio();
}
public static void main(String[] args) {
Checkup c1 = new Checkup(999,110,78,100,40);
Checkup c2 = new Checkup(1000,110,78,10,70);
Checkup c3 = new Checkup(1001,130,90,100,40);
Checkup c4 = new Checkup(1002,130,90,10,70);
displayCheckup(c1);
displayCheckup(c2);
displayCheckup(c3);
displayCheckup(c4);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.