Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

10. Are you a. a leader? b. a follower? _______

Answered: 1 week ago