Hello Im working on an assignment that tests inheritance and

Hello. I\'m working on an assignment that tests inheritance and composition but I\'m still learning so I\'m having trouble. I will provide the code I have so far.. The class i need help creating is going to be a patient class. \"Design the class Patient, inherited from the class Person, with additional data members to store a patient’s ID, age, date of birth, attending physician, the date when the patient was admitted in the hospital, and the date when the patient was discharged from the hospital. Therefore, the Patient IS-A Person and HAS-A Doctor and several Dates (i.e., date of birth, admit date, discharge date). You should use the class Date to store the date of birth, admit date, discharge date, and the class Doctor to store the attending physician. Add appropriate constructors and methods to initialize, access, and manipulate data members.\" Thank you for the help! I\'m still learning so if you don\'t mind leaving documentation comments so I can follow the code, it would be a huge help. Thanks again.


Person.java

-----------------


public class Person {
  
   private String lastName;
   private String firstName;
  
   public Person(String last, String first)
   {
       this.lastName = last;
       this.firstName = first;
   }

   public String getLastName() {
       return lastName;
   }

   public void setLastName(String lastName) {
       this.lastName = lastName;
   }

   public String getFirstName() {
       return firstName;
   }

   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }
  
   public String toString()
   {
       return lastName + \", \" + firstName;
   }

}

------------------------

Date.java

---------------------------


public class Date {
  
   private int year;
   private int month;
   private int day;
  
   public Date()
   {
       year = 1900;
       month = 1;
       day = 1;
   }
  
   public Date(int y, int m, int d)
   {
       year = y;
       month = m;
       day = d;
   }
  
   public String toString()
   {
       return month + \"/\" + day + \"/\" + year;
   }

   public int getYear() {
       return year;
   }

   public void setYear(int year) {
       this.year = year;
   }

   public int getMonth() {
       return month;
   }

   public void setMonth(int month) {
       this.month = month;
   }

   public int getDay() {
       return day;
   }

   public void setDay(int day) {
       this.day = day;
   }
  
-----------------------

Doctor.java

------------------------

public class Doctor extends Person { // doctor class that inherits the person class

   String Speciality;

   public Doctor(String last, String first) { // constructor
       super(last, first);
   }

   @Override
   public String toString() { // method that return the data
       return \"Doctor{\" + \"Speciality=\" + Speciality + \'}\';
   }

   public String getSpeciality() {
       return Speciality;
   }

   public void setSpeciality(String Speciality) {
       this.Speciality = Speciality;
   }

}

--------------------------

}

--------------------------

Solution


public class Patient extends Person{
  
    private int PatientId;
    private int age;
    private Doctor attendingPhysician;
    private Date dob;
    private Date admitted,discharged;
  
    public Patient(String firstName,String lastName,int PatientId,int age,Doctor attendingPhysician,Date dob,Date admitted,Date discharged)
    {
        super(lastName,firstName);
        this.PatientId = PatientId;
        this.age = age;
        this.admitted = admitted;
        this.discharged = discharged;
        this.dob = dob;
        this.attendingPhysician = attendingPhysician;
    }
  
    public int getPatientId()
    {
        return PatientId;
    }
  
    public int getAge()
    {
        return age;
    }
  
    public Date getAdmissionDate()
    {
        return admitted;
    }
  
    public Date getDischargedDate()
    {
        return discharged;
    }
  
    public Date getDOB()
    {
        return dob;
    }
  
    public Doctor getPhysician()
    {
        return attendingPhysician;
    }
  
    public void setPatientId(int PatientId)
    {
       this.PatientId = PatientId;
    }
  
    public void setAge(int age)
    {
        this.age = age;
    }
  
    public void setAdmissionDate(Date admitted)
    {
        this.admitted = admitted;
    }
  
    public void setDischargedDate(Date discharged)
    {
        this.discharged = discharged;
    }
  
    public void setDOB(Date dob)
    {
        this.dob = dob;
    }
  
    public void setPhysician(Doctor attendingPhysician)
    {
        this.attendingPhysician = attendingPhysician;
    }
  
}

Hello. I\'m working on an assignment that tests inheritance and composition but I\'m still learning so I\'m having trouble. I will provide the code I have so fa
Hello. I\'m working on an assignment that tests inheritance and composition but I\'m still learning so I\'m having trouble. I will provide the code I have so fa
Hello. I\'m working on an assignment that tests inheritance and composition but I\'m still learning so I\'m having trouble. I will provide the code I have so fa
Hello. I\'m working on an assignment that tests inheritance and composition but I\'m still learning so I\'m having trouble. I will provide the code I have so fa

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site