Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Does someone have this problem done? I have been working on it for a while and I

ID: 670004 • Letter: D

Question

Does someone have this problem done? I have been working on it for a while and I cannot get it to work for me. Please, i would really appreciate the help! thank you!!

Chapter 4, exercise 4. Java Pro. Joyce Farrell

A) create a class name BloodData that includes fields that hold bood type ( the four blood types are O, A, B, AB) and an Rh factor (Factors are + -). create a default constructor that sets the fields to O and + , and an overload constructor that requires values for both fields. include get and set methods for each field. save file as BloodData.java. create and application named TestBloodData that demostrates that each method works correctly. save 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 + . rceatean overloaded constrcutor that provides values for each field. also provide get methods for each field. save the file as patient.java. create and application named TestPatient that demonstrates that each method works correctly, save it as TestPatient.java.

Explanation / Answer

Hi,

Below is the solution to your question:

import java.util.Scanner;
/*
* Main class that uses methods
*/
public class PatientBuilder
{
public static void main(String[] args)
{
String patientID;
int patientAge;
String patientRh;
String patientBlood;
Scanner input = new Scanner(System.in);
System.out.print("what is the patients ID?");
patientID=input.nextLine();
Scanner input = new Scanner(System.in);
System.out.print("what is the patients age?");
patientAge=input.nextInt();
input.nextLine();
Scanner input = new Scanner(System.in);
System.out.print("what is the patients RH?");
patientRh=input.nextLine();
Scanner input = new Scanner(System.in);
System.out.print("What is the patients blood type?");
patientBlood=input.nextLine();
Patient newpatient = new Patient(blood,rh,id,age);
System.out.println("The patients blood type is " +newpatient.getBlood()+". The patients RH is " +newpatient.getRh()+". The patients ID is " +newpatient.getID()+". The patients age is " +newpatient.getAge()+".");

}
}
/*
* This is a class that contains constructors
* And setter and getter methods
*/
public class BloodData
{
private String blood;
private String rh;

public BloodData()
{
blood="O";
rh="+";
}
public BloodData(String proposedBlood, String proposedRh)
{
blood=proposedBlood;
rh=proposedRh;
}
public String getblood()
{
return blood;
}
public String getrh()
{
return rh;
}
public void setblood(String proposedBlood)
{
blood=proposedBlood;
}
public void setRh(String proposedRh)
{
rh=proposedRh;
}
}
/*
* Class for initalizing patient information
*
*/
class Patient
{
private String ID;
private int age;
private BloodData bloodData;

public Patient()
{
bloodData = new BloodData(blood, rh);
ID="0";
age=0;
}
public Patient(String aBlood, String aRh, String aID, int aAge)
{
age=aAge;
ID=aID;
blood=aBlood;
rh=aRh;
}
public String getID()
{
return ID;
}
public int getAge()
{
return age;
}
public String getBlood()
{
return blood;
}
public String getRh()
{
return rh;
}
public void setID(String aID)
{
ID=aID;
}
public void setAge(int aAge)
{
age=aAge;
}
public void setBlood(String aBlood)
{
blood=aBlood;
}
public void setRh(String aRh)
{
rh=aRh;
}
}

Hope that helps...HAPPY ANSWERING!!!!!!!!!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote