Write an abstract class Worker , two concrete subclasses HourlyWorker and SalariedWorker , and a test program TestWorker . Each of these classes is described below.
The abstract Worker class has a name field and a salary rate (in dollars per hour) field. The Worker class has an abstract instance method computeWeeklyPay(int hours) (each subclass of Worker will have its own way of computing weekly pay). The Worker class should have appropriate constructors, appropriate (concrete) set and get methods for the name and salary fields, and it should also have a (concrete) toString method that returns the name and salary rate in an appropriate string.
The HourlyWorker class has a boolean instance field called isUnionMemeber and a String instance field called unionName (which should be set to null if isUnionMemeber is false ). The HourlyWorker class has a computeWeeklyPay(int hours) method that implements the same method from the super class (an hourly worker gets paid for the actual number of hours worked, with overtime over 40 hours paid at time and a half). The HourlyWorker class should have appropriate constructors (that make use of the super class constructors), appropriate set and get methods, and it should also have a toString method that both overrides and calls the toString method in the super class, and that returns the name, salary rate, and union status in an appropriate string.
The SalariedWorker class has an int instance field called subordinates that records the number of workers that the salaried worker manages. The SalariedWorker class has a computeWeeklyPay(int hours) method that implements the same method from the super class (a salaried worker always gets paid for 40 hours, no matter what the actual hours worked is). The SalariedWorker class should have appropriate constructors (that make use of the super class constructors), appropriate set and get methods, and it should also have a toString method that both overrides and calls the toString method in the super class, and that returns the name, salary rate, and number of subordinates in an appropriate string.
Write a test class called TestWorker . It should create an array of type Worker and fill it with some HourlyWorker and some SalariedWorker objects. Then the program should loop through the array and use polymorphism to compute the pay and print out all of the information for each object in the array. The test class should also show that your constructor, get, and set methods all work.
When you are done you will have four program files, Worker.java , HourlyWorker.java , SalariedWorker.java and TestWorker.java . Put these four files together into one zip file.
This assignment is due Monday, December 1.
|