Question: This project promotes the following Student Learning Outcomes: 1. Identify objects associated with a stated problem, then design, code, and test a set of classes
This project promotes the following Student Learning Outcomes:
1. Identify objects associated with a stated problem, then design, code, and test a set of classes for their representation that demonstrates encapsulation, data abstraction, and information hiding.
2. Organize programs based on separate declaration, definition, and usage files that demonstrate security considerations.
3. Develop applications based on code designed for reuse and extensibility using best practice software engineering techniques.
4. Formulate programming solutions that use inheritance, polymorphism and class hierarchies to promote reuse of program design and code.
5. Identify objects associated with a stated problem, then design, code, and test a set of classes for their representation that demonstrates encapsulation, data abstraction, and information hiding using simple ADTs.
Problem Statement
A company pays its workers on a weekly basis. The workers are of 3 types:
1. FixedWeekly workers are paid a fixed salary regardless of the number of hours worked
2. ByTheHour workers are paid by the hour and receive overtime pay for all hours worked in excess of 40
3. PercentOfSales workers are paid a percentage of their sales
Create a class called Worker. This class will represent the general concept of a worker. All 4 types of workers are considered Workers. The Worker class will be Comparable.Comparable is an interface in the Java API. You will base your comparison on their first name concatenated onto their last names. The Workerclass will also be Payable. You will need to create the Payable interface. It will contain just one method called earnings().
A Worker has a first name, last name, and social security number. A FixedWeekly worker has a first name, last name, social security number and fixed weekly salary. A ByTheHour worker has a first name, last name, social security number, an hourly wage, and number of hours worked. A PercentOfSales worker has a first name, last name, social security number, gross sales amount, and commission rate.
The Worker class will contain an appropriate 3 parameter constructor and a default constructor, appropriate accessors and mutators, toString, equals, and compareTo methods. It will also contain an earnings method which must be implemented by the subclasses. The constructor will validate that the social security number is in the proper format (999-99-9999). If not in the proper format, the constructor will assign XXX-XX-XXXX for the social security number.
The FixedWeekly class will contain an appropriate 4 parameter constructor and a default constructor, appropriate accessors and mutators, earnings, toString, equals, and compareTo methods. The constructor will validate that the fixed weekly salary is not negative. If the salary figure is negative the fixed weekly salary value will be set to 0.
The ByTheHour class will contain an appropriate 5 parameter constructor and a default constructor, appropriate accessors and mutators, earnings, toString, equals, and compareTo methods. The constructor will validate that the hourly wage is not negative and that the hours worked is between 0 and 60 inclusive. If the hourly wage is negative set the hourly wage to 0. If hours worked is not in the proper range, set the hours worked 0.
The PercentOfSales class will contain an appropriate 5 parameter constructor and a default constructor, appropriate accessors and mutators, earnings, toString, equals, and compareTo methods. The constructor will validate that the gross sales amount is not negative and that the commission rate is a value between 0.0 and 1.0 inclusive. If these conditions are not met then set the appropriate variable values to 0.
Write a GUI class to test your inheritance hierarchy. In that class do the following:
4. Allow the user to create Worker objects.
FixedWeekly workers will have a code of 1 and require a salary entry.
ByTheHour workers will have a code of 2 and require an Hours worked and Hourly rate entry.
PercentOfSales workers will have a code of 3 and require a sales and commission % entry.
5. Sample Data:
(1, "Nick", "Foles", "111-11-1111", 800.00 );
(2, "Ben", "Simmons", "222-22-2222", 16.75, 40 );
(3, "Donte", "DiVincenzo", "333-33-3333", 10000, .06 );
6. Store these objects in an array of Workers.
7. When the user clicks on the Run Report button, your program should process these objects polymorphically displaying a string representation of each Worker and their earnings as shown at the end of this document in the textarea.
8. In the report, display each worker and their class type as shown at the end of this document. Hint: You can inherit an appropriate method from class Object. Note what that method returns and then check out that class for an appropriate method to return a string containing the name of the class.
9. Clicking on the Write to File button will polymorphically access the Worker objects and write their data to a line in a file.
10. Clicking on the Run from File button will read the data from the file, create appropriate objects, and store them in the array.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
