• Post Reply Bookmark Topic Watch Topic
  • New Topic

Payroll System  RSS feed

 
David Tran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?





 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

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.
 
David Tran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!