java code for sample projects inheritance
DESCRIPTION
TRANSCRIPT
Inheritance ProjectBilling.java File
public Billing(Billing otherBilling){
invoiceNumber = "None Assigned";}
//create methodspublic void setInvoiceNumber(String i) { invoiceNumber = i; }
public String getinvoiceNumber() { return invoiceNumber; } public void setVisitDate (String i) {
visitDate = i; }
public String getVisitDate() { return visitDate; } public void setPatientSeen(Patient p) {
patientSeen = p; } public Patient getPatientSeen() { return patientSeen;
Inheritance Project Page 1
Java Code for
} public void setAttendingMD(Doctor d) {
attendindgMD = d; } public Doctor getAttendingMD() { return attendindgMD; } public boolean equals(Billing other) {
return (getVisitDate().equals(other.getVisitDate()) && ((getPatientSeen()).getBirthDate().equals((other.getPatientSeen()).getBirthDate())) &&((getPatientSeen()).getName().equals((other.getPatientSeen()).getName())) && ((getAttendingMD()).getName().equals((other.getAttendingMD()).getName())));
} public void printInvoice() {
System.out.println("MEDICAL CENTER INVOICE"); System.out.println(" "); System.out.println("Invoice #"+ getinvoiceNumber()); System.out.println("Date of Service: " + getVisitDate());System.out.println("Patient Name: " + getPatientSeen().getName() + " - ID Number: " +
getPatientSeen().getPatientId()); System.out.println("Attending Physician: " + getAttendingMD().getName()); System.out.println("Amount Due for Office Visit: $" + getAttendingMD().getOfficeFee());
}}
Doctor.java Filepublic class Doctor extends Person{
//declare fieldsString specialty;String medSchool;Double officeFee;
Inheritance Project Page 2
//set up constructorspublic Doctor(String Name, String s, String ms, Double of) {
super(Name);specialty = s;medSchool =ms;officeFee = of;
}
public Doctor(){
super();specialty = "GP";medSchool ="Unknown";officeFee = 150.00;
}
public Doctor(Doctor otherDoctor){
super();specialty = otherDoctor.specialty;medSchool = otherDoctor.medSchool;officeFee = otherDoctor.officeFee;
}
Inheritance Project Page 3
//create methods
public void setSpecialty(String sp) { specialty = sp; } public String getSpecialty() { return specialty; } public void setMedSchool(String m) { medSchool = m; } public String getMedSchool() { return medSchool; } public void setOfficeFee(Double f) { officeFee = f; } public Double getOfficeFee() { return officeFee; } public boolean equals(Doctor other) { return (getName().equals(other.getName())); } public void writeDoctorInfo() {
System.out.println("Dr. " + getName() + " graduated from " + getMedSchool() + " and is a " + getSpecialty() + ". The doctor's fee is $" + getOfficeFee() + " per visit.");
}}
Inheritance Project Page 4
Patient.java File
public class Patient extends Person{String id;String birthdate;
//set up constructorspublic Patient(String Name, String i, String bD ) {
super(Name);id = i;birthdate = bD;
}public Patient(){
super();id ="Unknown";birthdate = "Month Day, Year";
}
//create methodspublic void setId(String i)
{ id = i;
}
public String getPatientId() { return id; }
public void setBirthDate(String b) {
birthdate= b; }
Inheritance Project Page 5
public String getBirthDate() { return birthdate; } public boolean equals(Patient other) { return (getName().equals(other.getName()) && (getBirthDate().equals(other.getBirthDate()))); }}
Inheritance Project Page 6
Person.java File
public class Person{
private String name;
public void setName(String newName){
name = newName;}
public Person(){
name = "no name yet " ;}
public Person(String initialName){
name = initialName;}
public String getName(){
return name;}
public void writeOutput(){System.out.println("Name: " + name);}
public boolean hasSameName(Person otherPerson){return this.name.equalsIgnoreCase(otherPerson.name);}
}
Inheritance Project Page 7
testDoctorMethods.java File
public class testDoctorMethods {
public static void main(String[] args){
//first constructorDoctor ManagingDirector = new Doctor();ManagingDirector.setName("Friedman");ManagingDirector.setMedSchool("Harvard");ManagingDirector.setSpecialty("Obstetrician");ManagingDirector.setOfficeFee(200.00);
//second constructorDoctor Staff = new Doctor("Schwartz ", "Dermatologist", "John Hopkins", 150.00);
//third constructorDoctor intern = new Doctor(Staff);intern.setName("Schreiber");
//equals methodSystem.out.println("The Managing Director Doctor has the same name as the Staff Doctor is a " +
ManagingDirector.hasSameName(Staff) + " statement!") ;
//reportSystem.out.println(" ");System.out.println("First Doctor Constructor");ManagingDirector.writeDoctorInfo();System.out.println(" ");System.out.println("Second Doctor Constructor");Staff.writeDoctorInfo();System.out.println(" ");System.out.println("Third Doctor Constructor");intern.writeDoctorInfo();
}}
Inheritance Project Page 8
testPatientBillingMethods.java File
public class testPatientBillingMethods {
public static void main(String[] args){
//declare invoice total variableDouble totalInvoices;//re-create doctorDoctor Staff = new Doctor("Dr. Schwartz ", "Dermatologist", "John Hopkins", 150.00);// create new patientsPatient johnDoe = new Patient("John Doe", "000001", "January 11, 1971");Patient marySmith = new Patient("Mary Smith", "000002", "May 11, 1975");//create billing objectsBilling i00001 = new Billing(johnDoe, Staff, "i00001", "May 1, 2012");Billing i00002 = new Billing(marySmith, Staff, "i00002", "May 1, 2012");//verify that the 2 billing records are not duplicatesif (i00001.equals(i00002) == true)
{System.out.println("These 2 billing records are for the same patient visit ");}
else{System.out.println("These 2 billing records are NOT for the same patient visit ");}
System.out.println(" ");//generate invoices for patient visitsi00001.printInvoice();System.out.println(" ");i00002.printInvoice();//generate total of invoicestotalInvoices = (i00001.getAttendingMD().getOfficeFee() + i00002.getAttendingMD().getOfficeFee() );System.out.println(" ");System.out.println("Total Office Receipts for May 1, 2012 were: $" + totalInvoices);
}}
Inheritance Project Page 9