** Create a constructor that initializes ONLY the name and date-of-birth data-fi
ID: 3765781 • Letter: #
Question
** Create a constructor that initializes ONLY the name and date-of-birth data-fields(i.e. takes two arguments). Also, increment the patient counter static variable.
** Create a constructor that initializes ALL data-fields. Also, increment the patient counter static variable.
** Create getters/setters for ALL the above data-fields. Should be 14 in total.
** Create a getter method for the static variables that keeps tracks of how many patient objects are created.
public class EMR
{
private String name;
private String dob;
private String reasonForVisit;
private double bodyTemp;
private double heartRate;
private String diagnosis;
private String prescribedMedicine;
// static variable initialized to 0
public static int patientCounter = 0;
// default constructor with no arguments
// increments static variable patientCounter
EMR()
{
patientCounter++;
}
//set and get methods for name of the patient
void setName(String name)
{
this.name = name;
}
String getName()
{
return this.name;
}
//set and get methods for date of birth of the patient
void setDOB(String dob)
{
this.dob = dob;
}
String getDOB()
{
return this.dob;
}
//set and get methods for reason for visit of the patient
void setReasonForVisit(String reason)
{
this.reasonForVisit = reason;
}
String getReasonForVisit()
{
return this.reasonForVisit;
}
//set and get methods for body temperature of the patient
void setBodyTemp(double Temp)
{
this.bodyTemp = Temp;
}
double getBodyTemp()
{
return this.bodyTemp;
}
//set and get methods for hrart rate of the patient
void setHeartRate(double heartRate)
{
this.heartRate = heartRate;
}
double getHeartRate()
{
return this.heartRate;
}
//set and get methods for diagnosis of the patient
void setDiagnosis(String diagnosis)
{
this.diagnosis = diagnosis;
}
String getDiagnosis()
{
return this.diagnosis;
}
//set and get methods for prescribed medicine of the patient
void setPrescribedMedicine(String medicine)
{
this.prescribedMedicine = medicine;
}
String getPrescribedMedicine()
{
return this.prescribedMedicine;
}
// Main function which creates 3 patients A, B and C and
// check how patientCounter is behaving after creating each patient
// can add more functionality to main by using set and get methods as per the needs
public static void main(String args[])
{
// print initial value of the patientCounter
// Since it is static variable, it can be used with out using any object
System.out.println("Initial patientCounter value is "+patientCounter);
// create an Object A and print patientCounter value
EMR A = new EMR();
System.out.println("patientCounter value of patient A is "+A.patientCounter);
// create an Object B and print patientCounter value
EMR B = new EMR();
System.out.println("patientCounter value of patient B is "+B.patientCounter);
// create an Object C and print patientCounter value
EMR C = new EMR();
System.out.println("patientCounter value of patient C is "+C.patientCounter);
}
}
Explanation / Answer
Complete code:
package com.chegg.nancy.solutions;
public class EMR {
private String name;
private String dob;
private String reasonForVisit;
private double bodyTemp;
private double heartRate;
private String diagnosis;
private String prescribedMedicine;
// static variable initialized to 0
public static int patientCounter = 0;
// default constructor with no arguments
// increments static variable patientCounter
EMR() {
patientCounter++;
}
// Answering here for: Create a constructor that initializes ONLY the name
// and date-of-birth data-fields(i.e. takes two arguments). Also, increment
// the patient counter static variable.
EMR(String name, String dob) {
this.name = name;
this.dob = dob;
patientCounter++;
}
// Answering here for : Create a constructor that initializes ALL
// data-fields. Also, increment the patient counter static variable.
public EMR(String name, String dob, String reasonForVisit, double bodyTemp, double heartRate, String diagnosis,
String prescribedMedicine) {
super();
this.name = name;
this.dob = dob;
this.reasonForVisit = reasonForVisit;
this.bodyTemp = bodyTemp;
this.heartRate = heartRate;
this.diagnosis = diagnosis;
this.prescribedMedicine = prescribedMedicine;
patientCounter++;
}
// set and get methods for name of the patient
void setName(String name) {
this.name = name;
}
String getName() {
return this.name;
}
// set and get methods for date of birth of the patient
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
// set and get methods for reason for visit of the patient
void setReasonForVisit(String reason) {
this.reasonForVisit = reason;
}
String getReasonForVisit() {
return this.reasonForVisit;
}
// set and get methods for body temperature of the patient
void setBodyTemp(double Temp) {
this.bodyTemp = Temp;
}
double getBodyTemp() {
return this.bodyTemp;
}
// set and get methods for heart rate of the patient
void setHeartRate(double heartRate) {
this.heartRate = heartRate;
}
double getHeartRate() {
return this.heartRate;
}
// set and get methods for diagnosis of the patient
void setDiagnosis(String diagnosis) {
this.diagnosis = diagnosis;
}
String getDiagnosis() {
return this.diagnosis;
}
// set and get methods for prescribed medicine of the patient
void setPrescribedMedicine(String medicine) {
this.prescribedMedicine = medicine;
}
// Answering here for : Create a getter method for the static variables that
// keeps tracks of how many patient objects are created.
public static int getPatientCounter() {
return patientCounter;
}
String getPrescribedMedicine() {
return this.prescribedMedicine;
}
// Main function which creates 3 patients A, B and C and
// check how patientCounter is behaving after creating each patient
// can add more functionality to main by using set and get methods as per
// the needs : Define the needs?
public static void main(String args[]) {
// print initial value of the patientCounter
// Since it is static variable, it can be used with out using any object
System.out.println("Initial patientCounter value is " + patientCounter);
// create an Object A and print patientCounter value
EMR A = new EMR();
System.out.println("patientCounter value of patient A is " + A.patientCounter);
// create an Object B and print patientCounter value
EMR B = new EMR();
System.out.println("patientCounter value of patient B is " + B.patientCounter);
// create an Object C and print patientCounter value
EMR C = new EMR();
System.out.println("patientCounter value of patient C is " + C.patientCounter);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.