java code for sample projects inheritance

11
Inheritance Project Billing.java File public Billing(Billing otherBilling) { invoiceNumber = "None Assigned"; } //create methods public 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; Inheritance Project Page 1 Java

Upload: jwjablonski

Post on 18-Dec-2014

5.693 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Java Code for Sample Projects Inheritance

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

Page 2: Java Code for Sample Projects Inheritance

} 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

Page 3: Java Code for Sample Projects Inheritance

//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

Page 4: Java Code for Sample Projects Inheritance

//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

Page 5: Java Code for Sample Projects Inheritance

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

Page 6: Java Code for Sample Projects Inheritance

public String getBirthDate() { return birthdate; } public boolean equals(Patient other) { return (getName().equals(other.getName()) && (getBirthDate().equals(other.getBirthDate()))); }}

Inheritance Project Page 6

Page 7: Java Code for Sample Projects Inheritance

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

Page 8: Java Code for Sample Projects Inheritance

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

Page 9: Java Code for Sample Projects Inheritance

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