So, the problem is: 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. 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.The exisitng code is - 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() + "\n The blood is type " + bt.getBloodType() + bt.getRhFactor()); } }
So, the problem is:
-
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.
-
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.The exisitng code is -
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() +"\n The blood is type " + bt.getBloodType() + bt.getRhFactor());}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images