fork download
  1. // Name : ياره احمد محمود
  2. // ID :202200588
  3. import java.text.DecimalFormat;
  4. import java.util.*;
  5. import java.lang.*;
  6. import java.io.*;
  7. public class Main {
  8. private String[] employeeNames;
  9. private double[] hoursWorked;
  10. private double[] hourlyWages;
  11.  
  12. public Main(String[] employeeNames, double[] hoursWorked, double[] hourlyWages)
  13. {
  14. this.employeeNames = employeeNames;
  15. this.hoursWorked = hoursWorked;
  16. this.hourlyWages = hourlyWages;
  17. }
  18.  
  19. public double calculateGrossPay(int employeeIndex)
  20. {
  21. double hours = hoursWorked[employeeIndex];
  22. double wage = hourlyWages[employeeIndex];
  23. return hours * wage;
  24. }
  25.  
  26. public double calculateTax(double grossPay, double taxRate)
  27. {
  28. return grossPay * taxRate;
  29. }
  30.  
  31. public double calculateNetPay(double grossPay, double deductions)
  32. {
  33. return grossPay - deductions;
  34. }
  35.  
  36. public void generatePayStub(int employeeIndex)
  37. {
  38. String name = employeeNames[employeeIndex];
  39. double hours = hoursWorked[employeeIndex];
  40. double wage = hourlyWages[employeeIndex];
  41. double grossPay = calculateGrossPay(employeeIndex);
  42. double tax = calculateTax(grossPay, 0.2);
  43. double netPay = calculateNetPay(grossPay, tax);
  44.  
  45. DecimalFormat decimalFormat = new DecimalFormat("#0.00");
  46.  
  47. System.out.println("Pay Stub for Employee: " + name);
  48. System.out.println("Hours Worked: " + hours);
  49. System.out.println("Hourly Wage: $" + decimalFormat.format(wage));
  50. System.out.println("Gross Pay: $" + decimalFormat.format(grossPay));
  51. System.out.println("Tax: $" + decimalFormat.format(tax));
  52. System.out.println("Net Pay: $" + decimalFormat.format(netPay));
  53. System.out.println();
  54. }
  55.  
  56. public static void main(String[] args)
  57. {
  58. String[] employeeNames =
  59. {
  60. "John","Jane"
  61. };
  62. double[] hoursWorked =
  63. {
  64. 40.0, 35.5
  65. };
  66. double[] hourlyWages =
  67. {
  68. 15.0, 20.0
  69. };
  70.  
  71. Main payrollSystem = new Main(employeeNames, hoursWorked, hourlyWages);
  72. payrollSystem.generatePayStub(0);
  73. payrollSystem.generatePayStub(1);
  74. }
  75. }
Success #stdin #stdout 0.15s 58276KB
stdin
Standard input is empty
stdout
Pay Stub for Employee: John
Hours Worked: 40.0
Hourly Wage: $15.00
Gross Pay: $600.00
Tax: $120.00
Net Pay: $480.00

Pay Stub for Employee: Jane
Hours Worked: 35.5
Hourly Wage: $20.00
Gross Pay: $710.00
Tax: $142.00
Net Pay: $568.00