This week's book giveaway is in the NodeJS forum. We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line! See this thread for details.
Assume the employees' names, salary, base salary, commission rate, hourly rate are already entered into the system (from the database, for example). You run this program weekly to enter the data depending on the employee's position:
Salarid employee: No data to be entered.
Commission employee: Enter the amount of gross sales.
Base plus commission employee: Enter the amount of gross sales.
Hourly employee: Enter the hours worked.
You are required to write a GUI program instead of a console program.
For this assignment you should add an abstract method, e.g. enterData into the superclass Employee, and override it in each of its subclasses. To test, create an array of Employees. Loop through the array to enter data. Then loop through the array again to calculate and output their earnings. Here are the detailed steps:
1/ Copy Employee.java and its 4 subclasses into a folder Assign9. In Eclipse create a project on this folder.
2/ Create a new class Assign with public static void main(String args)
3/ In Employee.java, add public abstract void enterData();
4/ Implement the method enterData() in the class SalariedEmployee, CommissionEmployee, and HourlyEmployee. You don't have to implement it in BasePlusCommissionEmployee. It should input data by calling JOptionPane.showInputDialog() with the specific prompt, and call the corresponding setGrossSales() or setHours().
5/ In Assign main() method, create an array of Employee. Construct the 4 subclass objects as did in PayrollSystemTest.java except that the sales or hours should be zero. Store them into the array.
6/In a loop through the array, call employee.enterData();
7/ After all data are entered, loop through the array again and output the payroll by calling employee.toString() and employee.earnings()
8/Append the output into a String, and call JOptionPane.showMessageDialog() after the loop.
I'm done with 1,2,3, but the rest i can't figue it out. Can someone help me?
After you enter a value in the input dialog, the showInputDialog() method returns and gives you the input in String form. You can parse this and then perform the appropriate action on that data.
What specifically don't you understand?
I'm also breaking up your code to show the separate classes.
posted 3 years ago
I don't understand in step 4 that is call the corresponding setGrossSales() or setHours(). And In a loop through the array, call employee.enterData();
Stephan van Hulst
posted 3 years ago
Well, each employee has an enterData() method, in which you should prompt the user to fill in the necessary data to determine the earnings of an employee.
That means that an hourly employee should prompt the user to fill in the amount of hours that employee works, after which it parses the value and passes it to the setHours() method. Do similar things for the other types of employees.
In the Assign class you have an array of employees. You can use the (enhanced) for-loop to perform an action for each employee in the array, which in this case is calling the enterData() method.
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
global solutions you can do in your home or backyard