Create a class named BloodData that includes fields that hold a blood type (the
ID: 671718 • Letter: C
Question
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 t hat 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
b)
public class Patient { private int patientIdentification; private int patientAge; private BloodData patientBloodData; public Patient() { patientIdentification = 0; patientAge = 0; patientBloodData = new BloodData("O", '-'); class BloodData { String type; char factor; public BloodData(String typ, char fact) { type = typ; factor = fact; } } } public Patient(int id, int age, String type, char factor) { patientIdentification = id; patientAge = age; BloodData patientBloodData = new BloodData("O", '+'); } public int getPatientIdentification() { return patientIdentification; } public int getPatientAge() { return patientAge; } public String getPatientBloodData(String type) { return type; } public char getPatientBloodData(char factor) { return factor; } }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.