a.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).Include methods to get and set each of the fields.Include a method named computeRatio()
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/24 08:31:43
a.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).Include methods to get and set each of the fields.Include a method named computeRatio()
a.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).Include methods to get and set each of the fields.Include a method named computeRatio() that divides LDL cholesterol by HDL cholesterol and displays the result.Include an additional method named explainRatio() that explains that HDL is know 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.Call a getData() method four times.Within the method,prompt a user for values for each field for a Checkup,and return a Checkup object to the main() method where it is assigned to one of main()'s Checkup objects.Then,in main(),pass each Checkup object in trun to a showValues() method that displays the data.Blood pressure values are usually displayed with a slash between the systolic and diastolic numbers.(Typical blood pressure values are 110/78 or 130/90.) With the cholesterol figures,display the explanation of the cholesterol ratio calculation.(Typical cholesterol values are 100 and 40 or 180 and 70.) Save the application as TestCheckup.java.
那位大侠能解请帮帮忙...
a.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).Include methods to get and set each of the fields.Include a method named computeRatio()
这道题目按照题目要求一共要生成2个JAVA类文件,
第一个Checkup.java
public class Checkup{
private int patientId;
private float systolic;
private float diastolic;
private float ldl;
private float hdl;
public String explainRatio(){
return computeRatio() > 3.5? "good cholesterol": "optimum";
}
public float computeRatio(){
float ratio = ldl / hdl;
System.out.println("Ratio is: " + ratio);
return ratio;
}
public int getPatientId() {
return patientId;
}
public void setPatientId(int patientId) {
this.patientId = patientId;
}
public float getSystolic() {
return systolic;
}
public void setSystolic(float systolic) {
this.systolic = systolic;
}
public float getDiastolic() {
return diastolic;
}
public void setDiastolic(float diastolic) {
this.diastolic = diastolic;
}
public float getLdl() {
return ldl;
}
public void setLdl(float ldl) {
this.ldl = ldl;
}
public float getHdl() {
return hdl;
}
public void setHdl(float hdl) {
this.hdl = hdl;
}
}
第二个文件TestCheckup.java
import java.util.Scanner;
public class TestCheckup {
public static void main(String[] args) {
final int patientNum = 4;
Checkup[] patients = new Checkup[patientNum];
for(int i = 0; i < patientNum; i++){
patients[i] = getData();
showValues(patients[i]);
}
}
public static void showValues(Checkup patient){
System.out.println("Blood pressure is: "
+ String.valueOf(patient.getSystolic()) + "/"
+ String.valueOf(patient.getDiastolic()));
System.out.println("LDL is " + patient.getLdl() + ", HDL is " + patient.getHdl()
+ ". Cholesterol figures is: "
+ String.valueOf(patient.explainRatio()));
}
public static Checkup getData(){
Checkup patient = new Checkup();
Scanner scanner = new Scanner(System.in);
System.out.println("Please input patient ID:");
int patientID = scanner.nextInt();
System.out.println("Please input patient's systolic:");
float systolic = scanner.nextFloat();
System.out.println("Please input patient's diastolic:");
float diastolic = scanner.nextFloat();
System.out.println("Please input patient's LDL:");
float ldl = scanner.nextFloat();
System.out.println("Please input patient's HDL:");
float hdl = scanner.nextFloat();
patient.setPatientId(patientID);
patient.setSystolic(systolic);
patient.setDiastolic(diastolic);
patient.setLdl(ldl);
patient.setHdl(hdl);
return patient;
}
}
--------------测试结果
Please input patient ID:
1
Please input patient's systolic:
110
Please input patient's diastolic:
90
Please input patient's LDL:
150
Please input patient's HDL:
30
Blood pressure is: 110.0/90.0
Ratio is: 5.0
LDL is 150.0, HDL is 30.0. Cholesterol figures is: good cholesterol
Please input patient ID:
130
Please input patient's systolic:
78
Please input patient's diastolic:
120
Please input patient's LDL:
130
Please input patient's HDL:
45
Blood pressure is: 78.0/120.0
Ratio is: 2.8888888
LDL is 130.0, HDL is 45.0. Cholesterol figures is: optimum
Please input patient ID:
3
Please input patient's systolic:
160
Please input patient's diastolic:
95
Please input patient's LDL:
135
Please input patient's HDL:
96
Blood pressure is: 160.0/95.0
Ratio is: 1.40625
LDL is 135.0, HDL is 96.0. Cholesterol figures is: optimum
Please input patient ID:
45
Please input patient's systolic:
180
Please input patient's diastolic:
120
Please input patient's LDL:
170
Please input patient's HDL:
40
Blood pressure is: 180.0/120.0
Ratio is: 4.25
LDL is 170.0, HDL is 40.0. Cholesterol figures is: good cholesterol