7. 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);
}
publicbooleanhasSameName(Person otherPerson)
{
returnthis.name.equalsIgnoreCase(otherPerson.name);
}
}
Inheritance Project Page 7
8. testDoctorMethods.java File
public class testDoctorMethods
{
public static void main(String[] args)
{
//first constructor
Doctor ManagingDirector = new Doctor();
ManagingDirector.setName("Friedman");
ManagingDirector.setMedSchool("Harvard");
ManagingDirector.setSpecialty("Obstetrician");
ManagingDirector.setOfficeFee(200.00);
//second constructor
Doctor Staff = new Doctor("Schwartz ", "Dermatologist", "John Hopkins", 150.00);
//third constructor
Doctor intern = new Doctor(Staff);
intern.setName("Schreiber");
//equals method
System.out.println("The Managing Director Doctor has the same name as the Staff Doctor is a " +
ManagingDirector.hasSameName(Staff) + " statement!") ;
//report
System.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
9. testPatientBillingMethods.java File
public class testPatientBillingMethods
{
public static void main(String[] args)
{
//declare invoice total variable
Double totalInvoices;
//re-create doctor
Doctor Staff = new Doctor("Dr. Schwartz ", "Dermatologist", "John Hopkins", 150.00);
// create new patients
Patient johnDoe = new Patient("John Doe", "000001", "January 11, 1971");
Patient marySmith = new Patient("Mary Smith", "000002", "May 11, 1975");
//create billing objects
Billing 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 duplicates
if (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 visits
i00001.printInvoice();
System.out.println(" ");
i00002.printInvoice();
//generate total of invoices
totalInvoices = (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