Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. import java.util.Scanner;
  2. /**
  3. * 2PayStub class is part of Lab 3 and
  4. * creates a simple pay stub.
  5. *
  6. * @author Elizabeth Gibson
  7. * @version September 19, 2017
  8. */
  9. public class PayStub
  10. {
  11. public static final double OVERTIME_FACTOR = 1.5;
  12. public static final double SOCIAL_WITHHOLDING = .10;
  13. public static final double FEDERAL_TAX = .20;
  14. private String employeeName;
  15. private String ssN;
  16. private int hours;
  17. private int overTime;
  18. private double payRate;
  19. private double regularPay;
  20. private double overTimePay;
  21. private double overTimeRate;
  22. private double grossPay;
  23. private double ssW;
  24. private double fedTax;
  25. private double netPay;
  26. private double margeHourlyRate;
  27. private double margeGrossPay;
  28.  
  29. /**
  30. * It all starts with the main method.
  31. *
  32. * @param args Command-line arguments.
  33. */
  34. public static void main(String[] args)
  35. {
  36. Scanner reader = new Scanner(System.in);
  37.  
  38. PayStub homer = new PayStub(reader);
  39. PayStub marge = new PayStub(reader);
  40. PayStub lisa = new PayStub(reader);
  41. }
  42.  
  43. /**
  44. * Constructor.
  45. *
  46. * @param keyboard Scanner object.
  47. */
  48. public PayStub(Scanner keyboard)
  49. {
  50. getInput(keyboard);
  51. keyboard.nextLine();
  52. calculate();
  53. printPayStub();
  54. }
  55.  
  56. /**
  57. * Accessor for overTime.
  58. */
  59. public int getoverTime()
  60. {
  61. return overTime;
  62. }
  63.  
  64. /**
  65. * Accessor for grossPay.
  66. */
  67. public double getgrossPay()
  68. {
  69. return grossPay;
  70. }
  71.  
  72. /**
  73. * Mutator for overTime.
  74. *
  75. * @param newValue Set the object's value to the supplied value.
  76. */
  77. public void setoverTime(int newValue)
  78. {
  79. if (newValue >= 0)
  80. {
  81. overTime = newValue;
  82. calculate();
  83. }
  84. }
  85.  
  86. /**
  87. * Mutator for payRate.
  88. *
  89. * @param newValue1 Set the object's value to the supplied value.
  90. */
  91. public void setpayRate(double newValue)
  92. {
  93. if (newValue >= 0)
  94. {
  95. payRate = newValue;
  96. calculate();
  97. }
  98. }
  99.  
  100. /**
  101. * Get input from the user.
  102. *
  103. * @param keyboard Scanner object.
  104. */
  105. private void getInput(Scanner keyboard)
  106. {
  107. //get employee's name
  108. System.out.print("Enter employee name: ");
  109. employeeName = keyboard.nextLine();
  110.  
  111. //employee social security number
  112. System.out.print("Enter employee SSN: ");
  113. ssN = keyboard.nextLine();
  114.  
  115. //employee's regular not overtime hours worked
  116. System.out.print("Enter number of regular hours: ");
  117. hours = keyboard.nextInt();
  118.  
  119. //overtime hours worked
  120. System.out.print("Enter number of overtime hours: ");
  121. overTime = keyboard.nextInt();
  122.  
  123. //hourly payRate
  124. System.out.print("Enter hourly pay rate: ");
  125. payRate = keyboard.nextDouble();
  126.  
  127. System.out.printf("New gross pay: $%-8.2f\n", getmargeGrossPay());
  128.  
  129. }
  130.  
  131. /**
  132. * This function separates the calculations from the interface.
  133. */
  134. private void calculate()
  135. {
  136. regularPay = hours * payRate;
  137.  
  138. overTimeRate = payRate * OVERTIME_FACTOR;
  139.  
  140. overTimePay = overTime * overTimeRate;
  141.  
  142. grossPay = regularPay + overTimePay;
  143.  
  144. ssW = SOCIAL_WITHHOLDING * grossPay;
  145.  
  146. fedTax = FEDERAL_TAX * (grossPay - ssW);
  147.  
  148. netPay = grossPay - (ssW + fedTax);
  149. }
  150.  
  151. /**
  152. * Print out the calculated pay stub.
  153. * This method should only be called after the calculate method.
  154. */
  155. private void printPayStub()
  156. {
  157. System.out.println("____________________________________"
  158. + "_________________________________________");
  159.  
  160. String format = "Name: %-37s SSN: %-11s\n";
  161. System.out.printf(format, employeeName, ssN);
  162.  
  163. String format1 = "Regular Hours: %-8d Reg Rate: $%-8.2f"
  164. + " Reg Pay: $%-8.2f\n";
  165. System.out.printf(format1, hours, payRate, regularPay);
  166.  
  167. String format2 = "Overtime Hours: %-8d"
  168. + "OT Rate: $%-9.2f OT Pay: $%-8.2f\n";
  169. System.out.printf(format2, overTime, overTimeRate, overTimePay);
  170.  
  171. String format3 = "Gross Pay: $%-8.2f\n";
  172. System.out.printf(format3, grossPay);
  173.  
  174. String format4 = "SS Withholding: $%-8.2f\n";
  175. System.out.printf(format4, ssW);
  176.  
  177. String format5 = "Federal Tax: $%-8.2f\n";
  178. System.out.printf(format5, fedTax);
  179.  
  180. String format6 = "Net Pay: $%-8.2f\n";
  181. System.out.printf(format6, netPay);
  182.  
  183.  
  184. System.out.print("____________________________________"
  185. + "_________________________________________\n");
  186.  
  187. }
  188.  
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement