Question
Constructors The two jobs of the constructor is to create an instance of the object and fully specify the state of that new object. Empty
Constructors The two jobs of the constructor is to create an instance of the object and fully specify the state of that new object. Empty constructor uses default values Copy constructor parameter is of the same type as the class; makes a deep copy
Accessors Accessors allow access to some or all of the state, usually through a copy
Mutators Mutators allow alteration of the state of the object
Members Member methods perform some operation that is specific to the class static members can be invoked by the class name itself. non-static members can only be invoked by an instance of the class; they act on their arguments and nothing more. Some classes in Java have only static members; e.g. Math. You cant even create an object of type Math any more (the constructor is private!)
Interface In Java an interface is a class that contains only method signatures and constant declarations. They cannot have state, nor can they include method definitions; they are used as the name implies) to specify an interface. Inheritance in Java In Java we have a limited form of multiple inheritance; an object can inherit from only one "stateful parent but many interfaces. We use the keyword "extends for our one and only stateful parent, and implements for as many interfaces as we desire. public class MyClass extends Parent implements Interfacel, Interface2, Interface3 CLASS CONSTRUCTION AND INHERITANCE We'll start with a parent class... Person - firstName: String - lastName: String -dob: OCCCDate + Person (String firstName, String lastName) + Person (String firstName, String lastName, OCCCDate dob) + Person (Person p) // copy constructor + String getFirstName() + String getLastName() + void setFirstName(String firstName) + void setLastName(String lastName) + OCCCDate getDOBO; + int getAge(); // returns age in years, truncated not rounded + String toString() // format lastName, firstName (birthdate) // Freeman, Gordon (05/19/1955) // birth date is generated by OCCCDate's toString method + 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. We'll add to this a couple of derived classes: RegisteredPerson - govID: String + RegisteredPerson (String firstName, String lastName, OCCCDate dob, String govID) + RegisteredPerson (Person p, String govID) + RegisteredPerson (RegisteredPerson p) + String getGovernmentIDO + boolean equals(RegisteredPerson p) // the usual equals method + boolean equals(Person p) // compare only Person fields, ignore government ID + String toString(); // adds [govID] to end of string OCCCPerson - studentID: String + OCCCPerson (RegisteredPerson p, String studentID) + OCCCPerson (OCCCPerson p) + String getStudentID () + boolean equals(OCCCPerson p) // the usual equals method + boolean equals(RegisteredPerson p) // compare only RegisteredPerson fields, ignore stud ID + boolean equals(Person p) // compare only name and DOB fields + String toString (); // adds {studentID} to end of string Hint: For the first pass, write these without any use of the OCCCDate object. Both of these classes make use of OCCCDate, which will be a "wrapper around the built-in Java class GregorianCalendar. OCCCDate - dayOfMonth: int // 1..31 - monthOfYear: int // 1..12 - year: int // e.g. 2020 - gc: GregorianCalendar // a private helper object - dateFormat: boolean // default is DATE FORMAT US - dateStyle: boolean // default is DATE_STYLE_NUMBERS - dateDayName: boolean // default is SHOW_DAY_NAME + static final boolean FORMAT US + static final boolean FORMAT EURO + static final boolean STYLE NUMBERS + static final boolean STYLE NAMES + static final boolean SHOW DAY NAME + static final boolean HIDE DAY NAME + OCCCDate() // default constructor, uses current date and time + OCCCDate(int day, int month, int year) + OCCCDate(GregorianCalendar gc) + OCCCDate(OCCCDate d) // copy constructor + int getDayOfMonth() // 1, 2, 3... + String getDayName() // Sunday, Monday, Tuesday.. // GregorianCalender does this + int get MonthNumber() // 1, 2, 3... + String getMonthName() // January, February, March... + int getYear() // Gregorian year, e.g. 2020 + void setDateFormat(boolean df) + void setStyleFormat(boolean sf) + void setDayName(boolean nf) + int getDifferenceInYears(); // difference in years between this OCCCDate and now + int getDifferenceInYears(OCCCDate d); // difference in years between this date and d + boolean equals(OCCCDate 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 Once you have OCCCDate working to your satisfaction, add it to the Person classes. HOMEWORK Write a program in which you implement all four classes above and demonstrate every behavior of each. Make sure that the user has ample opportunity to input names and dates. Submit your source codes on Moodle as usual. If you follow the UML, my test program should work with your class filesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started