a. Create a class named BloodData that includes fields that hold a blood type (t
ID: 3551279 • Letter: A
Question
a. Create a class named BloodData that includes fields that hold a blood type (the four blood types are O, A, B, and AB) and an Rh factor (the factors are + and -). Create a default constructor that sets the fields to "O" and "+", and an overloaded constructor that requires values for both fields. Include get and set methods for each field. Save this file as BloodData.java. Create an application named TestBloodData that demonstrates that each method works correctly. Save the application as TestBloodData.java.
b. Create a class named Patient that includes an ID number, age, and BloodData. Provide a default constructor that sets the ID number to "0", the age to 0, and the BloodData to "O" and "+". Create an overloaded constructor that provides values for each field. Also provide get methods for each field. Save the file as Patient.java. Create an application named TestPatient that demonstrates that each method works correctly, and save it as TestPatient.java.
Explanation / Answer
Part a: Check indented code at :
https://dl.dropboxusercontent.com/u/42883368/chegg/CheggNetbeans/src/BloodData.java
https://dl.dropboxusercontent.com/u/42883368/chegg/CheggNetbeans/src/TestBloodData.java
Part a: Check indented code at :
https://dl.dropboxusercontent.com/u/42883368/chegg/CheggNetbeans/src/Patient.java
https://dl.dropboxusercontent.com/u/42883368/chegg/CheggNetbeans/src/TestPatient.java
/****************************************************************/
public class BloodData {
public enum BloodGroup {
O, A, B, AB
}
BloodGroup type;
public BloodData(BloodGroup t) {
type = t;
}
public void printBloodGroup(){
System.out.println("BloodGroup is "+type);
}
}
/***************************************************************/
public class TestBloodData {
public static void main(String[] args) {
BloodData bd1 = new BloodData(BloodData.BloodGroup.AB);
bd1.printBloodGroup();
BloodData bd2 = new BloodData(BloodData.BloodGroup.A);
bd2.printBloodGroup();
BloodData bd3 = new BloodData(BloodData.BloodGroup.B);
bd3.printBloodGroup();
BloodData bd4 = new BloodData(BloodData.BloodGroup.O);
bd4.printBloodGroup();
}
}
/******************************************************************/
public class Patient {
int id, age;
BloodData bloodType;
public Patient() {
id = 0;
age = 0;
bloodType = new BloodData(BloodData.BloodGroup.O);
}
public Patient(int id, int age, BloodData bloodType) {
this.id = id;
this.age = age;
this.bloodType = bloodType;
}
public int getId() {
return id;
}
public int getAge() {
return age;
}
public BloodData getBloodType() {
return bloodType;
}
public void printPatientDetails(){
System.out.println("PatientId: "+id+" Patient Age: "+age+" BloodGroup: "+bloodType.type);
}
}
/******************************************************************/
public class TestPatient {
public static void main(String[] args) {
Patient p1 = new Patient();
p1.printPatientDetails();
Patient p2 = new Patient(232, 24, new BloodData(BloodData.BloodGroup.AB));
p2.printPatientDetails();
}
}
/*****************************************************************/
Output of TestPatient:
PatientId: 0 Patient Age: 0 BloodGroup: O
PatientId: 232 Patient Age: 24 BloodGroup: AB
Output of TestBloodData:
BloodGroup is AB
BloodGroup is A
BloodGroup is B
BloodGroup is O
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.