Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. /*
  2. * Author: Jennifer Blom
  3. * Assignment #3
  4. * Calculate net pay after taking out medicare and Social security from the gross pay.
  5. */
  6.  
  7. package ProgramAssignment3;
  8.  
  9. import javax.swing.*;
  10. import java.util.*;
  11.  
  12. public class Main {
  13.  
  14. private static double SHIFT_RATE = 1.25;
  15. private static double WEEKEND_RATE = 1.50;
  16. private static double SS_TAX_PERCENT = .062;
  17. private static double MEDI_TAX_PERCENT = .0145;
  18. private static double socialSecurityWithholding;
  19. private static double netPay;
  20.  
  21. public static void main(String[] args) {
  22.  
  23. GetInputData();
  24. }
  25. public static void GetInputData() {
  26. // Create an instance of Scanner so I can get input from the keyboard
  27. Scanner keyboard = new Scanner(System.in);
  28. // input of variables first will display a prompt next gets input
  29. System.out.println("Employee Name: ");
  30. String employeeName = keyboard.nextLine();
  31. System.out.println("Enter Hourly Rate: ");
  32. double hourlyRate = keyboard.nextDouble();
  33. System.out.println("Enter Regular Hours: ");
  34. double regularHours = keyboard.nextDouble();
  35. System.out.println("Enter Overtime Hours: ");
  36. double overtimeHours = keyboard.nextDouble();
  37. System.out.println("Enter Shift Hours: ");
  38. double shiftHours = keyboard.nextDouble();
  39. System.out.println("Enter Weekend Hours: ");
  40. double weekendHours = keyboard.nextDouble();
  41.  
  42. double regularPay = regularHours * hourlyRate;
  43. double overtimePay = overtimeHours * (hourlyRate * 1.5);
  44. double shiftPay = shiftHours * SHIFT_RATE;
  45. double weekendPay = weekendHours * WEEKEND_RATE;
  46.  
  47. double grossPay = CalculateGrossPay(regularPay, overtimePay, shiftPay, weekendPay);
  48. double socialSecurityWithholding = CalculateSocSec(grossPay);
  49. double medicareWitholding = CalculateMedicare(grossPay);
  50. double netPay = CalculateNetPay(socialSecurityWithholding, medicareWitholding);
  51.  
  52. PrintResults(employeeName, regularHours, overtimeHours, shiftHours, weekendHours, hourlyRate, regularPay, overtimePay, shiftPay, weekendPay, grossPay, medicareWithholding, socialSecurityWithholding, netPay);
  53. }
  54.  
  55.  
  56. public static double CalculateGrossPay(double regularPay, double overtimePay, double shiftPay, double weekendPay){
  57. double grossPay = regularPay + overtimePay + shiftPay + weekendPay;
  58. return grossPay;
  59. }
  60.  
  61. public static double CalculateSocSec(double grossPay){
  62. socialSecurityWithholding = grossPay * SS_TAX_PERCENT;
  63. return socialSecurityWithholding;
  64. }
  65.  
  66. public static double CalculateMedicare(double grossPay){
  67. double medicareWithholding = grossPay * MEDI_TAX_PERCENT;
  68. return medicareWithholding;
  69. }
  70. public static double CalculateNetPay(double grossPay, double medicareWithholding){
  71. netPay = grossPay - (socialSecurityWithholding + medicareWithholding);
  72. return netPay;
  73. }
  74.  
  75. public static void PrintResults(double employeeName, double regularHours, double overtimeHours, double shiftHours,
  76. double weekendHours, double hourlyRate, double regularPay, double overtimePay, double shiftPay, double weekendPay,
  77. double grossPay, double medicareWithholding, double socialSecurityWithholding, double netPay) {
  78. //print the results to screen.
  79. System.out.println();
  80. System.out.println("Employee: " + employeeName);
  81. System.out.println("Regular hours worked: " + regularHours);
  82. System.out.println("Overtime Hours Worked: " + overtimeHours);
  83. System.out.println("Shift Hours Worked: " + shiftHours);
  84. System.out.println("Weekend Hours Worked: " + weekendHours);
  85. System.out.println("Hourly Rate: " + hourlyRate);
  86. System.out.println("Regular pay: " + regularPay);
  87. System.out.println("Overtime pay: " + overtimePay);
  88. System.out.println("Shift pay: " + shiftPay);
  89. System.out.println("Weekend pay: " + weekendPay);
  90. System.out.println("Gross pay: " + grossPay);
  91. System.out.println("Medicare Withholding: " + medicareWithholding);
  92. System.out.println("Social Security: " + socialSecurityWithholding);
  93. System.out.println();
  94. System.out.println("Net Pay: " + netPay);
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement