10.8 - / Employee abstract superclass. public abstract...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
// Employee abstract superclass. public abstract class Employee { private String firstName; private String lastName; private String socialSecurityNumber; private Date birthDate; // six-argument constructor public Employee( String first, String last, String ssn, int month, int day, int year ) { firstName = first; lastName = last; socialSecurityNumber = ssn; birthDate = new Date( month, day, year ); } // end six-argument Employee constructor // set first name public void setFirstName( String first ) { firstName = first; } // end method setFirstName // return first name public String getFirstName() { return firstName; } // end method getFirstName // set last name public void setLastName( String last ) { lastName = last; } // end method setLastName // return last name public String getLastName() { return lastName; } // end method getLastName // set social security number public void setSocialSecurityNumber( String ssn )
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
{ socialSecurityNumber = ssn; // should validate } // end method setSocialSecurityNumber // return social security number public String getSocialSecurityNumber() { return socialSecurityNumber; } // end method getSocialSecurityNumber // set birth date public void setBirthDate( int month, int day, int year ) { birthDate = new Date( month, day, year ); } // end method setBirthDate // return birth date public Date getBirthDate() { return birthDate; } // end method getBirthDate // return String representation of Employee object public String toString() { return String.format( "%s %s\n%s: %s\n%s: %s", getFirstName(), getLastName(), "social security number", getSocialSecurityNumber(), "birth date", getBirthDate() ); } // end method toString // abstract method overridden by subclasses public abstract double earnings(); } // end abstract class Employee // Date class declaration with get methods added. public class Date { private int month; // 1-12 private int day; // 1-31 based on month private int year; // any year // constructor: call checkMonth to confirm proper value for month; // call checkDay to confirm proper value for day public Date( int theMonth, int theDay, int theYear )
Background image of page 2
{ month = checkMonth( theMonth ); // validate month year = theYear; // could validate year day = checkDay( theDay ); // validate day System.out.printf( "Date object constructor for date %s\n", toString() ); } // end Date constructor // utility method to confirm proper month value private int checkMonth( int testMonth ) { return testMonth; else // month is invalid { System.out.printf( "Invalid month (%d) set to 1.\n", testMonth ); return 1; // maintain object in consistent state } // end else } // end method checkMonth // utility method to confirm proper day value based on month and year private int checkDay( int testDay ) { int daysPerMonth[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // check if day in range for month
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

10.8 - / Employee abstract superclass. public abstract...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online