Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 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. * Accessor for margeHourlyRate.
  73. */
  74. public double margeHourlyRate()
  75. {
  76. margeHourlyRate = 20.0;
  77. return margeHourlyRate;
  78. }
  79. public void setmargeHourlyRate(double hours)
  80. {
  81. margeHourlyRate = hours;
  82. }
  83. public double getmargeGrossPay()
  84. {
  85. grossPay = payRate * margeHourlyRate;
  86. return margeGrossPay;
  87. }
  88. /**
  89. * Mutator for overTime.
  90. *
  91. * @param newValue Set the object's value to the supplied value.
  92. */
  93. public void setoverTime(int newValue)
  94. {
  95. if (newValue >= 0)
  96. {
  97. overTime = newValue;
  98. calculate();
  99. }
  100. }
  101.  
  102. /**
  103. * Mutator for payRate.
  104. *
  105. * @param newValue1 Set the object's value to the supplied value.
  106. */
  107. public void setpayRate(double newValue)
  108. {
  109. if (newValue >= 0)
  110. {
  111. payRate = newValue;
  112. calculate();
  113. }
  114. }
  115.  
  116. /**
  117. * Get input from the user.
  118. *
  119. * @param keyboard Scanner object.
  120. */
  121. private void getInput(Scanner keyboard)
  122. {
  123. //get employee's name
  124. System.out.print("Enter employee name: ");
  125. employeeName = keyboard.nextLine();
  126.  
  127. //employee social security number
  128. System.out.print("Enter employee SSN: ");
  129. ssN = keyboard.nextLine();
  130.  
  131. //employee's regular not overtime hours worked
  132. System.out.print("Enter number of regular hours: ");
  133. hours = keyboard.nextInt();
  134.  
  135. //overtime hours worked
  136. System.out.print("Enter number of overtime hours: ");
  137. overTime = keyboard.nextInt();
  138.  
  139. //hourly payRate
  140. System.out.print("Enter hourly pay rate: ");
  141. payRate = keyboard.nextDouble();
  142. System.out.printf("New gross pay: $%-8.2f\n", getmargeGrossPay());
  143.  
  144. }
  145.  
  146. /**
  147. * This function separates the calculations from the interface.
  148. */
  149. private void calculate()
  150. {
  151. regularPay = hours * payRate;
  152.  
  153. overTimeRate = payRate * OVERTIME_FACTOR;
  154.  
  155. overTimePay = overTime * overTimeRate;
  156.  
  157. grossPay = regularPay + overTimePay;
  158.  
  159. ssW = SOCIAL_WITHHOLDING * grossPay;
  160.  
  161. fedTax = FEDERAL_TAX * (grossPay - ssW);
  162.  
  163. netPay = grossPay - (ssW + fedTax);
  164. }
  165.  
  166. /**
  167. * Print out the calculated pay stub.
  168. * This method should only be called after the calculate method.
  169. */
  170. private void printPayStub()
  171. {
  172. System.out.println("____________________________________"
  173. + "_________________________________________");
  174.  
  175. String format = "Name: %-37s SSN: %-11s\n";
  176. System.out.printf(format, employeeName, ssN);
  177.  
  178. String format1 = "Regular Hours: %-8d Reg Rate: $%-8.2f"
  179. + " Reg Pay: $%-8.2f\n";
  180. System.out.printf(format1, hours, payRate, regularPay);
  181.  
  182. String format2 = "Overtime Hours: %-8d"
  183. + "OT Rate: $%-9.2f OT Pay: $%-8.2f\n";
  184. System.out.printf(format2, overTime, overTimeRate, overTimePay);
  185.  
  186. String format3 = "Gross Pay: $%-8.2f\n";
  187. System.out.printf(format3, grossPay);
  188.  
  189. String format4 = "SS Withholding: $%-8.2f\n";
  190. System.out.printf(format4, ssW);
  191.  
  192. String format5 = "Federal Tax: $%-8.2f\n";
  193. System.out.printf(format5, fedTax);
  194.  
  195. String format6 = "Net Pay: $%-8.2f\n";
  196. System.out.printf(format6, netPay);
  197.  
  198.  
  199. System.out.print("____________________________________"
  200. + "_________________________________________\n");
  201.  
  202. }
  203.  
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement