Question: 1. Create a class named BloodData that includes fields that hold a blood type (the four blood types are O , A , B ,

1. 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 Oand +, and an overloaded constructor that requires values for both fields. Include get and set methods for each field.

2. 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 values to O and +. Create an overloaded constructor that provides values for each field. Also provide get methods for each field.

public class BloodData {

private String bloodType;

private String rhFactor;

public BloodData() {

}

public BloodData(String bType, String rh) {

}

public void setBloodType(String bType) {

}

public String getBloodType() {

}

public void setRhFactor(String rh) {

}

public String getRhFactor() {

}

}

public class Patient {

private String id;

private int age;

private BloodData bloodData;

public Patient() {

}

public Patient(String id, int age, String bType, String rhFactor) {

}

public String getId() {

}

public void setId(String id) {

}

public int getAge() {

}

public void setAge(int age) {

}

public BloodData getBloodData() {

}

public void setBloodData(BloodData b) {

}

}

public class TestBloodData {

public static void main(String[] args) {

BloodData b1 = new BloodData();

BloodData b2 = new BloodData("A", "-");

display(b1);

display(b2);

b1.setBloodType("AB");

b1.setRhFactor("-");

display(b1);

}

public static void display(BloodData b) {

System.out.println("The blood is type " + b.getBloodType() + b.getRhFactor());

}

}

public class TestPatient {

public static void main(String[] args) {

Patient p1 = new Patient();

Patient p2 = new Patient("1234", 35, "B", "+");

BloodData b2 = new BloodData("A", "-");

display(p1);

display(p2);

p1.setId("3456");

p1.setAge(42);

BloodData b = new BloodData("AB", "-");

p1.setBloodData(b);

display(p1);

}

public static void display(Patient p) {

BloodData bt = p.getBloodData();

System.out.println("Patient #" + p.getId() + " age: " + + p.getAge() + " The blood is type " + bt.getBloodType() + bt.getRhFactor());

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!