Charles Bell
Posts: 519
Nickname: charles
Registered: Feb, 2002
|
|
Re: don't understand the problem - using methods
|
Posted: May 3, 2003 8:20 AM
|
|
/* Pay.java
* May 3, 2003
*/
/** Create a class name Pay hat includes five double
* variables that hold hours worked, rate of pay per
* hour, withholding rate, gross pay,and net pay.
* Create three overloaded computeNetPay() methods.
* Gross pay is computed as hours worked,multiplied
* by pay per hour.
* When computeNetPay receives values for hours, pay
* rate,and withholding rate,it computes he gross
* pay and reduces it by the appropriate withholding
* amount to produce the net pay.
* When computeNetPay() receives two arguments, the
* withholing
* rate is assumed to be 15 percent.
* When computeNetPay() receives one argument,
* the withholding rate is assumed to be 15 percent,
* and the hourly rate is assumed to be 4.65.
*/
public class Pay{
/** Number of hours worked inpay period. */
private double hoursWorked;
/** Rate of pay per hour. */
private double payRate;
/** Rate of withholding in per cent. */
private double withholdingRate;
/** hoursWorked * payRate .*/
private double grossPay;
/** grossPay - withholding .*/
private double netPay;
/** The main() method tests all
* three overloaded methods.
*/
public static void main(String[] args){
Pay pay = new Pay();
double pay1 = pay.computeNetPay(40.00d,5.50d,10.0d);
System.out.println("NetPay (Method 1) = " + String.valueOf(pay1));
double pay2 = pay.computeNetPay(40.00d,10.0d);
System.out.println("NetPay (Method 2) = " + String.valueOf(pay2));
double pay3 = pay.computeNetPay(40.00d);
System.out.println("NetPay (Method 3) = " + String.valueOf(pay3));
}
/** Computes net pay from three inputs hoursWorked,
* payRate, and withholdingRate.
*/
public double computeNetPay(
double hoursWorked,
double payRate,
double withholdingRate){
this.hoursWorked = hoursWorked;
this.payRate = payRate;
this.withholdingRate = withholdingRate;
grossPay = hoursWorked * payRate;
double withholding = grossPay * withholdingRate / 100;
netPay = grossPay - withholding;
return netPay;
}
/** Computes net pay from two inputs hoursWorked,
* and payRate. withholdingRate = 15%.
*/
public double computeNetPay(
double hoursWorked,
double payRate){
this.hoursWorked = hoursWorked;
this.payRate = payRate;
withholdingRate = 15;
grossPay = hoursWorked * payRate;
double withholding = grossPay * withholdingRate /100;
netPay = grossPay - withholding;
return netPay;
}
/** Computes net pay from one inputs hoursWorked,
* payRate = 4.65, and withholdingRate = 15%.
*/
public double computeNetPay(double hoursWorked){
this.hoursWorked = hoursWorked;
payRate = 4.65;
this.withholdingRate = 15;
grossPay = hoursWorked * payRate;
double withholding = grossPay * withholdingRate /100;
netPay = grossPay - withholding;
return netPay;
}
}
|
|