Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1.  
  2. public class Payroll {
  3.  
  4. private int NUM_EMPLOYEES = 7;
  5. private int[] employeeID, hours;
  6. private double[] payRate, wages;
  7.  
  8. public Payroll()
  9. {
  10. employeeID = new int[NUM_EMPLOYEES];
  11. hours = new int[NUM_EMPLOYEES];
  12. payRate = new double[NUM_EMPLOYEES];
  13. wages = new double[NUM_EMPLOYEES];
  14. }
  15.  
  16. public double getGrossPay(int i)
  17. {
  18. return hours[i] * payRate[i];
  19. }
  20.  
  21. public void setEmployeeIDAt(int i, int id)
  22. {
  23. employeeID[i] = id;
  24. }
  25.  
  26. public void setHoursAt(int i, int h)
  27. {
  28. hours[i] = h;
  29. }
  30.  
  31. public void setPayRateAt(int i, double p)
  32. {
  33. payRate[i] = p;
  34. }
  35.  
  36. public void setWagesAt(int i, double w)
  37. {
  38. wages = new double[NUM_EMPLOYEES];
  39. wages[i] = w;
  40. }
  41.  
  42. public int getEmployeeIdAt(int i)
  43. {
  44. return employeeID[i];
  45. }
  46.  
  47. public int getHoursAt(int i)
  48. {
  49. return hours[i];
  50. }
  51.  
  52. public double getPayRateAt(int i)
  53. {
  54. return payRate[i];
  55. }
  56.  
  57. public double getWagesAt(int i)
  58. {
  59. return wages[i];
  60. }
  61.  
  62. }
  63.  
  64.  
  65.  
  66. import java.util.Scanner;
  67.  
  68. public class PayrollDemo {
  69.  
  70. public static void main(String[] args) {
  71. int[] employeeID = {5658845,4520125,7895122,8777541,8451277,1302850,7580489};
  72. int[] hours;
  73. double[] payRate, wages;
  74. int eId;
  75.  
  76. Scanner input = new Scanner(System.in);
  77. Payroll acct = new Payroll();
  78.  
  79. for (int index = 0; index < employeeID.length - 4; index++)
  80. {
  81. eId = employeeID[index];
  82. acct.setEmployeeIDAt(index, eId);
  83. System.out.print("Enter the hours worked by employee number " + acct.getEmployeeIdAt(index) + ": ");
  84. hours = new int[employeeID.length];
  85. hours[index] = input.nextInt();
  86. acct.setHoursAt(index, hours[index]);
  87. System.out.print("Enter the hourly pay rate for employee number " + acct.getEmployeeIdAt(index) + ": ");
  88. payRate = new double[employeeID.length];
  89. payRate[index] = input.nextDouble();
  90. acct.setPayRateAt(index, payRate[index]);
  91. }
  92.  
  93. System.out.println("\nPAYROLL DATA");
  94. System.out.println("==================");
  95. for (int index = 0; index < employeeID.length -4; index ++)
  96. {
  97. System.out.println("Employee " acct.getEmployeeIdAt(index) + " " +
  98. acct.getGrossPay(index));
  99. }
  100.  
  101.  
  102. input.close();
  103. }
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement