Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Build a new Patient class(“Patient.java”). This class will be a sub-class of Per

ID: 3850485 • Letter: B

Question

Build a new Patient class(“Patient.java”). This class will be a sub-class of Person. So it will inherit all the properties of Person(FirstName, LastName, Address and Email). Also add 3 new properties: patientId, insCo and appointment. A total of 7 properties. Create this class, make sure to add 2 constructors, all set and get methods, a display() method, and a toString method. Then use main to test out this class.

Main Code

Patient p1;

p1 = new Patient(“A909”, “Frank”, “Martin”, new Address(“123 Main”, “Houston”, “TX”, 50111), “ HYPERLINK "mailto:fm@msn.com" fm@msn.com”, “Aetna”, new Appointment(“A909”, “D201”, new MyDateTime(7,1,2017, 9,0,0), “P114”));

p1.display(); //prints all 7 properties

============================================================================================

import java.util.*;
import java.lang.*;
import java.io.*;
class Person
{
//class properties
   private String firstName;
   private String lastName;
   private Address address;
   private String email;

   //constructor with parameters
   Person(String firstName,String lastName,Address address,String email)
   {
       this.firstName = firstName;
       this.lastName = lastName;
       this.address = address;
       this.email = email;
   }

   //constructor with no parameters
   Person()
   {
       this.firstName = "";
       this.lastName = "";
       this.address = new Address();
       this.email = "";
   }

   //set methods
//method that sets firstname
   public void setFirstName(String firstName)
   {
       this.firstName = firstName;
   }

//method that sets lastname
   public void setLastName(String LastName)
   {
       this.lastName = lastName;
   }

//method that sets address
   public void setAddress(Address address)
   {
       this.address = address;
   }

//method that sets email
   public void setEmail(String email)
   {
       this.email = email;
   }

   //get methods
//method that returns firstname
   public String getFirstName()
   {
       return this.firstName;
   }

//method that returns lastname
   public String getLastName()
   {
       return this.lastName;
   }

//method that returns address
   public Address getAddress()
   {
       return this.address;
   }

//method that returns email
   public String getEmail()
   {
       return this.email;
   }

//method that displays person data
   void display()
   {
//print the person details
       System.out.println("FIRST NAME : "+this.firstName);
       System.out.println("LAST NAME : "+this.lastName);
       this.address.display(); //in order to print the address use the display method of Address class
       System.out.println("EMAIL :"+this.email);
   }

//overridding toString method
   public String toString()
   {
       return "First name : "+getFirstName() + " Last name : "+getLastName() + " " +this.address.toString() +" Email :"+getEmail();
   }

//main method
   public static void main (String[] args) throws java.lang.Exception
   {
       Person p1;
       p1 = new Person("James", "Jones", new Address ("123 Main St.","Dallas","TX",56565), "jj@yahoo.com");
       p1.display();
   }
}

Address.java

import java.util.*;
import java.lang.*;
import java.io.*;
class Address
{
private String street;
private String city;
private String state;
private int zipcode;
  
Address(String street,String city,String state,int zipcode){
this.street=street;
this.city=city;
this.state=state;
this.zipcode=zipcode;
}
Address(){
street="";
city="";
state="";
zipcode=0;
}
  
void display(){
System.out.println("ADDRESS: ");
System.out.println("STREET : "+this.street);
System.out.println("CITY : "+this.city);
System.out.println("STATE : "+this.state);
System.out.println("ZIPCODE :"+this.zipcode);
}

public String toString()
{
return "STREET : "+this.street + " CITY : "+this.city + " STATE : " +this.state +" ZIPCODE :"+this.zipcode;
}


public static void main (String[] args) throws java.lang.Exception
{
Address a1;
a1=new Address("1313 MockingBirdLn","Atlanta","GA",30001);
a1.display();
}
}

Explanation / Answer

Below are the classes: -

Patient.java


public class Patient extends Person {
   private String patientId;
   private String insCo;
   private Appointment appointment;

   //Constructor 1
   Patient() {
       this.patientId = "";
       this.insCo = "";
       this.appointment = new Appointment();
   }

   //Constructor 2
   public Patient(String patientId, String firstName, String lastName, Address address, String email, String insCo,
           Appointment appointment) {
       super(firstName, lastName, address, email);
       this.patientId = patientId;
       this.insCo = insCo;
       this.appointment = appointment;
   }

   //Setters and Getters
   public String getPatientId() {
       return patientId;
   }

   public void setPatientId(String patientId) {
       this.patientId = patientId;
   }

   public String getInsCo() {
       return insCo;
   }

   public void setInsCo(String insCo) {
       this.insCo = insCo;
   }

   public Appointment getAppointment() {
       return appointment;
   }

   public void setAppointment(Appointment appointment) {
       this.appointment = appointment;
   }

   //toString override
   public String toString() {
       return super.toString() + " patientId:" + this.patientId + " insCo:" + this.insCo + " appointmentDetails:"
               + this.appointment;
   }

   //display details
   public void display() {
       super.display();
       System.out.println("PatientID: " + this.patientId);
       System.out.println("InsCo: " + this.insCo);
       System.out.println("Appointment Details: " );
       this.appointment.display();
   }

   //main function to test
   public static void main(String[] args) {
       Patient p1;
       p1 = new Patient("A909", "Frank", "Martin", new Address("123 Main", "Houston", "TX", 50111),
               " HYPERLINK "mailto:fm@msn.com" fm@msn.com", "Aetna",
               new Appointment("A909", "D201", new MyDateTime(7, 1, 2017, 9, 0, 0), "P114"));
       p1.display(); // prints all 7 properties
   }
}

Appointment.java


public class Appointment {
   private String patientId;
   private String dentistId;
   private MyDateTime datetime;
   private String procCode;

   public Appointment(String patientId, String dentistId, MyDateTime datetime, String procCode) {
       this.patientId = patientId;
       this.dentistId = dentistId;
       this.datetime = datetime;
       this.procCode = procCode;
   }

   public Appointment() {
       this.datetime = new MyDateTime();
       this.procCode = "";
   }

   public String getPatientId() {
       return patientId;
   }

   public void setPatientId(String patientId) {
       this.patientId = patientId;
   }

   public String getDentistId() {
       return dentistId;
   }

   public void setDentistId(String dentistId) {
       this.dentistId = dentistId;
   }

   public MyDateTime getDatetime() {
       return datetime;
   }

   public void setDatetime(MyDateTime datetime) {
       this.datetime = datetime;
   }

   public String getProcCode() {
       return procCode;
   }

   public void setProcCode(String procCode) {
       this.procCode = procCode;
   }

   @Override
   public String toString() {
       return "Appointment [patientId=" + patientId + ", dentistId=" + dentistId + ", procCode=" + procCode + "]";
   }

   @SuppressWarnings("static-access")
   public void display() {
       System.out.println(this);
       System.out.println("Date and Time of Appointment: ");
       this.datetime.display();
   }

   public static void main(String[] args) {
       Appointment a1;
       a1 = new Appointment("A901", "D201", new MyDateTime(7, 1, 2017, 9, 0, 0), "P114");
       a1.display();
   }

}

MyDateTime.java


public class MyDateTime {
   static int hr, min, sec, year, day, month;

   public MyDateTime() {
       hr = 0;
       min = 0;
       sec = 0;
       year = 0;
       day = 0;
       month = 0;
   }

   public MyDateTime(int m, int d, int y, int h, int mn, int s) {
       hr = h;
       min = mn;
       sec = s;
       year = y;
       day = d;
       month = m;
   }

   public void setMonth(int a) {
       month = a;
   }

   public int getMonth() {
       return month;
   }

   public void setDay(int b) {
       day = b;
   }

   public int getDay() {
       return day;
   }

   public void setYear(int c) {
       year = c;
   }

   public int getYear() {
       return year;
   }

   public void setHour(int d) {
       hr = d;
   }

   public int getHour() {
       return hr;
   }

   public void setMinute(int e) {
       min = e;
   }

   public int getMinute() {
       return min;
   }

   public void setSecond(int f) {
       sec = f;
   }

   public int getSecound() {
       return sec;
   }

   public static String toString(int i) {
       return " " + i;
   }

   public static void display() {
       System.out.println("Month:" + toString(month));
       System.out.println("Day:" + toString(day));
       System.out.println("Year:" + toString(year));
       System.out.println("Hour:" + toString(hr));
       System.out.println("Minute:" + toString(min));
       System.out.println("Second:" + toString(sec));
   }
}

Sample Output: -

FIRST NAME : Frank
LAST NAME : Martin
ADDRESS:
STREET : 123 Main
CITY : Houston
STATE : TX
ZIPCODE :50111
EMAIL : HYPERLINK "mailto:fm@msn.com" fm@msn.com
PatientID: A909
InsCo: Aetna
Appointment Details:
Appointment [patientId=A909, dentistId=D201, procCode=P114]
Date and Time of Appointment:
Month: 7
Day: 1
Year: 2017
Hour: 9
Minute: 0
Second: 0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote