Advertisement
virtualideaz

Pay.java

Mar 26th, 2015
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.94 KB | None | 0 0
  1. 1. create a class name Pay that includes five double variables that will hold :
  2.  
  3. hours worked
  4. rate of pay per hour
  5. withholding rate
  6. gross pay
  7. net pay
  8.  
  9. Create three methods overloaded computerNetPay() methods.
  10. When computeNetPay() receives values for hours, pay rate, and withholding rate, it computes the gross pay and reduces it by the appropriate withholding amount to produce the net pay.
  11. When computeNetPay() receives two arguments, they represent the hours and pay rates, and the withholding rate is assumed to 10%.
  12. When computeNetPay() receives one argument, it represents the number of hours worked, the withholding rate is assumed 10% and the hourly rate is assumed to be 5.65. Name the program Pay.java
  13.  
  14.  
  15. Source Code:
  16.  
  17. import java.util.Scanner;
  18. public class Pay {
  19.  
  20. static Scanner sc = new Scanner(System.in);
  21. public static void main(String [] args) {
  22.  
  23. double hours;
  24. double rate;
  25. doublewithholdRate;
  26.  
  27.         //method set 1
  28.     System.out.print("Enter hours worked : ");
  29.     hours = sc.nextDouble();
  30.             //input rate
  31.         System.out.print("Enter rate of pay/hour : ");
  32.         rate = sc.nextDouble();
  33.             //input withholding rate
  34.         System.out.print("Enter withholding rate : ");
  35.         withholdRate = sc.nextDouble();
  36.             //computation by calling a method
  37.         double gross = getGross(hours, rate);
  38.         double net = computeNetPay(gross, withholdRate);
  39.         System.out.println("The net pay is : " + net);
  40.  
  41.         //method set 2
  42.     System.out.print("Enter hours worked: ");
  43.     doublehoursWorked = sc.nextDouble();
  44.     System.out.print("Enter rate per hour: ");
  45.     doubleratePerHour = sc.nextDouble();
  46.        //withhold rate is defined
  47.         double withhold = 0.10;
  48.            //second computation with withhold rate is defined
  49.         doublegrossPay = computeGrossPay(hoursWorked, ratePerHour);
  50.         doublenetPay = computeNet(grossPay, withhold);
  51.         System.out.println("The Net Pay is : " + netPay);
  52.  
  53.         //method set 3
  54.     System.out.print("Enter hours worked: ");
  55.     doublehoursOnly = sc.nextDouble();
  56.             //rate pay is defined
  57.         doubleratePay = 5.65;
  58.             //third computation
  59.         doublegrossHoursPayment = getGrossHours(hoursOnly, ratePay);    
  60.         doublenetPayment = computeNetPayment(grossHoursPayment, withhold);
  61.  
  62.     System.out.println("The net pay is " + netPayment);
  63.     }
  64.     public static double getGross(double hours, double rate) {
  65.         return hours*rate;
  66.     }
  67.     public static double computeNetPay(double gross, double withholdRate){
  68.         return gross-withholdRate;
  69.     }
  70.     public static double computeGrossPay(double hoursWorked, double ratePerHour) {
  71.         returnhoursWorked*ratePerHour;
  72.     }
  73.     public static double computeNet(double grossPay, double withhold) {
  74.         returngrossPay-withhold;
  75.     }
  76.     public static double getGrossHours(double hoursOnly, double ratePay) {
  77.         returnhoursOnly*ratePay;
  78.     }
  79.     public static double computeNetPayment(double grossHoursPayment, double withhold) {
  80.         returngrossHoursPayment-withhold;
  81.     }
  82. }
  83.  
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement