Question
Could use some help with this program, much appreciated! 1. Define the class Date which has the data attributes (fields) month, day, and year, and
Could use some help with this program, much appreciated!
1. Define the class Date which has the data attributes (fields) month, day, and year, and the methods constructor Date( String m, int d, int y), toString() and validate(). The toString converts an object of type Date into a string of the following format July, 16, 2018. The validate() is called by the constructor to validate the date before initializing the month, day, and year( you may use the enum type for the months See chapter 8. The year should be five digits <2050 and the day must be between 1 31 or 30 28 29 depending on month ). If the date is invalid, the constructor prints an error message and asks you to renter the date.
2. Define the class Employee which the data attributes: name, ssn, position, dateOfBirth, and pay. The first three attributes of type string, dataofBirth of type Date, and pay of type float. The class Employee has the following methods:
The method toString(): returns the employee info as a string of the following format:
Name:
SSN:
Position:
Date of Birth:
Pay:
The method raise ( float per) which increases the pay by the given percentage, per.
The methods set and get for each attributes including the dateOfBirth.
3. Define the class PTEmployee as an extended class of Employee and include two additional attributes: nHours and wages. The constructor of the extended class is defined by calling the constructor of the superclass Employee (assuming the pay =0)and then initializing the nHours , wages , and pay. The pay is computed as nHours*wages. The method raise( float amount) for this subclass increases the wages by the given amount( it is not percentage) and re compute the pay . Also, this class has get and set methods for nHours and wages. The method toString for the subclass PTEmployee uses the toString of the super class Employee and adds to it nHours and wages.
4. Write the program EmployeeDemo which inputs employee info from the keyboard and creates two objects E of type Employee and the second one PE of type PTEmployee. Test your program for the following:
Entering invalid date;
Call every method above for each of E and PE and print the return value( if it returns a value);
Declare two variables EV of type Employee and PEV of type PTEmployee and the following four assignments:
EV=E
Call every one of the following methods: EV.setPay, EV.getPay, EV.setWages EV.getWages,
EV.raise( 4.0), getDateOfBirth() and then print the info of EV.
EV=PE
Call every one of the following methods: EV.setPay, EV.getPay, EV.setWages EV.getWages,
EV.raise( 4.0), getDateOfBirth() and then print the info of EV.
PEV=E
Call every one of the following methods: EV.setPay, EV.getPay, EV.setWages EV.getWages, EV.raise( 4.0), getDateOfBirth() and then print the info of PEV.
PEV=E
Call every one of the following methods: EV.setPay, EV.getPay, EV.setWages EV.getWages, EV.raise( 4.0), getDateOfBirth() and then print the info of PEV.
You may get error messages when you run some of the above methods. Explain the reason and comment out those methods, one at time, and rerun the program.
Step 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