在我的EMR類中,我試圖在帶有2個變量的構造函數後增加患者計數器數據字段。我也試圖在用5個變量構造我的構造之後增加患者計數器數據字段。在構造函數中計數實例
在Main中,最終目標是創建5個新的患者記錄(我曾這樣做)並打印前後可用的患者記錄數。
我很確定我必須在我的EMR類中使用public static long numofpatients
,但不知道該從哪裏去。
主要代碼:
package studenthealthservices;
public class Studenthealthservices {
public static void main(String[] args) {
EMR p1 = new EMR("Colin", "10-22-74", "Strained Ankle", 99, 110, "hurt during football", "ankle brace");
System.out.println(p1.toString());
EMR p2 = new EMR("Anquan", "9-30-77", "stomach ache", 98, 120, "stress", "Tylenol");
System.out.println(p2.toString());
EMR p3 = new EMR("Buster", "3-27-1987", "Broken ankle", 99, 113, "Scott Cousins", "None");
System.out.println(p3.toString());
EMR P4 = new EMR("Frank The Tank", "4/1/89");
EMR p5 = new EMR("Merton Hanks", "03-12-1968");
}
}
EMR類代碼:
package studenthealthservices;
public class EMR {
private String name;
private String dob;
private String rfv;
private double bodyt;
private double hr;
private String diag;
private String pmeds;
public void setName(String name) {
this.name = name;
}
public EMR(String name, String dob) {
this.name = name;
this.dob = dob;
}
public String getName() {
return name;
}
public EMR(String name, String dob, String rfv, double bodyt, double hr, String diag, String pmeds) {
this.name = name;
this.dob = dob;
this.rfv = rfv;
this.bodyt = bodyt;
this.hr = hr;
this.diag = diag;
this.pmeds = pmeds;
}
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
public String getRfv() {
return rfv;
}
public void setRfv(String rfv) {
this.rfv = rfv;
}
public double getBodyt() {
return bodyt;
}
public void setBodyt(double bodyt) {
this.bodyt = bodyt;
}
public double getHr() {
return hr;
}
public void setHr(double hr) {
this.hr = hr;
}
public String getDiag() {
return diag;
}
public void setDiag(String diag) {
this.diag = diag;
}
public String getPmeds() {
return pmeds;
}
public void setPmeds(String pmeds) {
this.pmeds = pmeds;
}
public void redFlags() {
String help = "get help!";
if (bodyt >= 97.3 && bodyt <= 99.1)
this.bodyt = bodyt;
if (hr >= 60 && hr <= 100)
this.hr = hr;
else {
System.out.printf(help);
}
}
@Override
public String toString() {
return "\nname : " + this.name
+ "\nDate of Birth: " + this.dob
+ "\nReason for visit: " + this.rfv
+ "\nBody Temperature: " + this.bodyt
+ "\nHeart Rate " + this.hr
+ "\nDiagnosis: " + this.diag
+ "\nPrescribed Meds " + this.pmeds;
}
}
爲什麼不跟蹤初始化EMR類對象的類中的患者數,在您的情況下,它將是Studenthealthservices類? – nullPointer
你想要有一個櫃檯來記錄已經創建了多少個EMR?但是您需要EMR課程中的計數器而不是創建它的計數器? –
每個EMR構造函數中的numofpatients ++? – Divers