KEMBAR78
Java Code for Sample Projects Inheritance | DOCX
JavaCode for Sample Projects
                                                         Inheritance Project
                Billing.java File

                        public Billing(Billing otherBilling)
                        {
                        invoiceNumber = "None Assigned";
                        }

                //create methods
                        public void setInvoiceNumber(String i)
                         {
                        invoiceNumber = i;
                         }

                        public String getinvoiceNumber()
                         {
                        returninvoiceNumber;
                         }
                        public void setVisitDate (String i)
                         {
                                 visitDate = i;
                         }

                        public String getVisitDate()
                         {
                        returnvisitDate;
                         }


Inheritance Project                                                            Page 1
public void setPatientSeen(Patient p)
                       {
                               patientSeen = p;
                       }
                      public Patient getPatientSeen()
                       {
                      returnpatientSeen;
                       }
                      public void setAttendingMD(Doctor d)
                       {
                               attendindgMD = d;
                       }
                      public Doctor getAttendingMD()
                       {
                      returnattendindgMD;
                       }
                      publicboolean 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());
                       }
                }


Inheritance Project                                                                                                      Page 2
Doctor.java File
                public class Doctor extends Person
                {
                         //declare fields
                         String specialty;
                         String medSchool;
                         Double officeFee;

                        //set up constructors
                        public 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()
                  {
                returnmedSchool;
                  }
                public void setOfficeFee(Double f)
                  {
                officeFee = f;
                  }
                public Double getOfficeFee()
                  {
                returnofficeFee;
                  }
                publicboolean 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 constructors
                         public Patient(String Name, String i, String bD )
                         {
                                 super(Name);
                                 id = i;
                                 birthdate = bD;
                         }
                         public Patient()
                         {
                                 super();
                                 id ="Unknown";
                                 birthdate = "Month Day, Year";
                         }

                //create methods
                        public 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;
                 }

                publicboolean 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);
                        }

                        publicbooleanhasSameName(Person otherPerson)
                        {
                        returnthis.name.equalsIgnoreCase(otherPerson.name);
                        }
                }

Inheritance Project                                                           Page 7
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
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

Java Code for Sample Projects Inheritance

  • 1.
    JavaCode for SampleProjects Inheritance Project Billing.java File public Billing(Billing otherBilling) { invoiceNumber = "None Assigned"; } //create methods public void setInvoiceNumber(String i) { invoiceNumber = i; } public String getinvoiceNumber() { returninvoiceNumber; } public void setVisitDate (String i) { visitDate = i; } public String getVisitDate() { returnvisitDate; } Inheritance Project Page 1
  • 2.
    public void setPatientSeen(Patientp) { patientSeen = p; } public Patient getPatientSeen() { returnpatientSeen; } public void setAttendingMD(Doctor d) { attendindgMD = d; } public Doctor getAttendingMD() { returnattendindgMD; } publicboolean 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()); } } Inheritance Project Page 2
  • 3.
    Doctor.java File public class Doctor extends Person { //declare fields String specialty; String medSchool; Double officeFee; //set up constructors public 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
  • 4.
    //create methods public void setSpecialty(String sp) { specialty = sp; } public String getSpecialty() { return specialty; } public void setMedSchool(String m) { medSchool = m; } public String getMedSchool() { returnmedSchool; } public void setOfficeFee(Double f) { officeFee = f; } public Double getOfficeFee() { returnofficeFee; } publicboolean 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
  • 5.
    Patient.java File public class Patient extends Person { String id; String birthdate; //set up constructors public Patient(String Name, String i, String bD ) { super(Name); id = i; birthdate = bD; } public Patient() { super(); id ="Unknown"; birthdate = "Month Day, Year"; } //create methods public void setId(String i) { id = i; } public String getPatientId() { return id; } public void setBirthDate(String b) { birthdate= b; } Inheritance Project Page 5
  • 6.
    public String getBirthDate() { return birthdate; } publicboolean equals(Patient other) { return (getName().equals(other.getName()) && (getBirthDate().equals(other.getBirthDate()))); } } Inheritance Project Page 6
  • 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