Question: (Employee and ProductionWorker Classes) Design a class named Employee.
ID: 3617102 • Letter: Q
Question
Question: (Employee and ProductionWorker Classes)
Design a class named Employee. The class should keep thefollowing information in fields:
- Employee name
- Employee number in the format XXX-L, where X is a digitwithin the range 0-9 and the L is a letter withinthe range A-M.
- Hire date
Write one or more constructors and the appropriate accessor andmutator methods for the class.
Next, write a class named ProductionWorker that inherits fromthe Employee class. The ProductionWorker class should have fieldsto hold the following information:
- Shift (an integer)
- Hourly pay rate (a double)
The work day is divided into two shifts: day and night. Theshift field will be an integer value representing the shift thatthe employee works. The day shift is shift 1 and the night shift isshift 2. Write one or more constructors and the appropriateaccessor and mutator methods for the class. Demonstrate the classesby writing a program that uses a ProductionWorker object.
Explanation / Answer
publicclass Employee { // instancevariables privateString name; privateString number; privateString hireDate; // can be a Date object if desired //constructors publicEmployee(String name, String number, StringhireDate) { setName(name); setNumber(number); setHireDate(hireDate); } // accessors publicString getName() { return name; } publicString getNumber() { return number; } publicString getHireDate() { return hireDate; } // modifiers publicvoid setName(String n) { name = n; } publicvoid setNumber(String n) { number = n; } publicvoid setHireDate(String h) { hireDate = h; } } public classProductionWorker extends Employee { // instancevariables privateint shift; privatedouble hourlyRate; //constructors publicProductionWorker(String name,String number, String hireDate, intshift, double hourlyRate) { super(name, number, hireDate); setShift(shift); setHourlyRate(hourlyRate); } // accessors publicint getShift() { return shift; } publicdouble getHourlyRate() { return hourlyRate; } // modifiers publicvoid setShift(int s) { shift = s; } publicvoid setHourlyRate(double h) { hourlyRate = h; } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.