Question: CLASS CONSTRUCTION AND INHERITANCE Write a program in which you implement all three classes below and demonstrate every behavior of each. Make sure that the

CLASS CONSTRUCTION AND INHERITANCE

Write a program in which you implement all three classes below and demonstrate every behavior of each. Make sure that the user has an opportunity to input names and dates.

Well start with a parent class

Person

- firstName: String

- lastName: String

- dob: Date

+ Person (String firstName, String lastName)

+ Person (String firstName, String lastName, Date dob)

+ Person (Person p) // copy constructor

+ String getFirstName()

+ String getLastName()

+ void setFirstName(String fn)

+ void setLastName(String ln)

+ Date getDOB();

+ int getAge(); // returns age in years, not rounded

+ String toString() // format lastName, firstName (birthdate)

// LastName, First (05/19/1955)

+ boolean equals(Person) // ignore case on the first and last names

+ void eat() // simply prints Person is eating on the console

+ void sleep() // as above

+ void play() // as above

+ void run() // as above

On the eat / sleep / play / run methods make sure you obtain the identity of the class using a method; that way when the children invoke it their class types will be displayed.

and a calendar class that is really a wrapper around the built-in GregorianCalendar class.

Date

- dayOfMonth: int // 1..31

- monthOfYear: int // 1..12

- year: int // e.g. 2013

- gc: GregorianCalendar // a private helper object

- dateFormat: boolean // true for US date format, false for Euro format; default is true

- dateStyle: boolean // true for months as numbers, false as months as names

+ static final boolean DATE_US (true) // for the convenience of our clients

+ static final boolean DATE_EURO (false) // another one

+ static final boolean DATE_STYLE_NUMBERS (true)

+ static final boolean DATE_STYLE_NAMES (false)

+ Date() // default constructor, uses current date and time

+ Date(int day, int month, int year)

+ Date(GregorianCalendar gc)

+Date(Date d) // copy constructor

+ int getDayofMonth()

+ String getDayOfWeek() // Sunday, Monday, Tuesday..

+ int getMonth() // 1 = January, 2 = February

+ String getNameOfMonth() // January, February, March

+ int getYear() // Gregorian year, e.g. 2016

+ void setDateFormat(boolean df)

+ void setStyleFormat(boolean sf)

+ int getDifferenceInYears(); // difference in years between this Date and now

+ int getDifferenceInYears(Date d); // difference in years between this date and d

+ boolean equals(Date dob) // compare only day, month, and year

+ String toString() // US format mm/dd/yyyy or monthName dd, yyyy

// Euro format dd/mm/yyyy or dd monthName yyyy

Well add to this a derived class:

RegisteredPerson

- govID: String

+ RegisteredPerson (String firstName, String lastName, Date dob, String govID)

+ RegisteredPerson (Person p, String govID)

+ RegisteredPerson (RegisteredPerson rp)

+ String getGovernmentID()

+ boolean equals(RegisteredPerson rp) // the usual equals method

+ boolean equals(Person p) // compare only Person fields, ignore government ID

+ String toString(); // adds [id] to end of string

JAVA

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!