The Artima Developer Community
Sponsored Link

Java Answers Forum
don't understand the problem - using methods

1 reply on 1 page. Most recent reply: May 3, 2003 8:20 AM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Big Mama

Posts: 4
Nickname: violet
Registered: May, 2003

don't understand the problem - using methods Posted: May 2, 2003 5:14 PM
Reply to this message Reply
Advertisement
Here is a problem what I have. But I do not even understand it. Can anybody solve this problem? Please help me....^^

@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 he appropriate withholing 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.Write a main() method that tests all three overloaded methods.


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: don't understand the problem - using methods Posted: May 3, 2003 8:20 AM
Reply to this message Reply
/* 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;    
    }
    
}

Flat View: This topic has 1 reply on 1 page
Topic: question about button? Previous Topic   Next Topic Topic: Threads treading on one another's feet...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use