Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. create a class name Pay that includes five double variables that will hold :
- hours worked
- rate of pay per hour
- withholding rate
- gross pay
- net pay
- Create three methods overloaded computerNetPay() methods.
- 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.
- When computeNetPay() receives two arguments, they represent the hours and pay rates, and the withholding rate is assumed to 10%.
- 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
- Source Code:
- import java.util.Scanner;
- public class Pay {
- static Scanner sc = new Scanner(System.in);
- public static void main(String [] args) {
- double hours;
- double rate;
- doublewithholdRate;
- //method set 1
- System.out.print("Enter hours worked : ");
- hours = sc.nextDouble();
- //input rate
- System.out.print("Enter rate of pay/hour : ");
- rate = sc.nextDouble();
- //input withholding rate
- System.out.print("Enter withholding rate : ");
- withholdRate = sc.nextDouble();
- //computation by calling a method
- double gross = getGross(hours, rate);
- double net = computeNetPay(gross, withholdRate);
- System.out.println("The net pay is : " + net);
- //method set 2
- System.out.print("Enter hours worked: ");
- doublehoursWorked = sc.nextDouble();
- System.out.print("Enter rate per hour: ");
- doubleratePerHour = sc.nextDouble();
- //withhold rate is defined
- double withhold = 0.10;
- //second computation with withhold rate is defined
- doublegrossPay = computeGrossPay(hoursWorked, ratePerHour);
- doublenetPay = computeNet(grossPay, withhold);
- System.out.println("The Net Pay is : " + netPay);
- //method set 3
- System.out.print("Enter hours worked: ");
- doublehoursOnly = sc.nextDouble();
- //rate pay is defined
- doubleratePay = 5.65;
- //third computation
- doublegrossHoursPayment = getGrossHours(hoursOnly, ratePay);
- doublenetPayment = computeNetPayment(grossHoursPayment, withhold);
- System.out.println("The net pay is " + netPayment);
- }
- public static double getGross(double hours, double rate) {
- return hours*rate;
- }
- public static double computeNetPay(double gross, double withholdRate){
- return gross-withholdRate;
- }
- public static double computeGrossPay(double hoursWorked, double ratePerHour) {
- returnhoursWorked*ratePerHour;
- }
- public static double computeNet(double grossPay, double withhold) {
- returngrossPay-withhold;
- }
- public static double getGrossHours(double hoursOnly, double ratePay) {
- returnhoursOnly*ratePay;
- }
- public static double computeNetPayment(double grossHoursPayment, double withhold) {
- returngrossHoursPayment-withhold;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement