Results 1 to 10 of 10
  1. #1
    ryamz is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Post oo-p laboratory problem

    Hi guys, my name is rhaii and im from the philippines.

    Our teacher Gave us these problems in our java class for our Lab activity.:eek:

    Im really new with Java and im having a hard time solving them.


    Create a class named Pay that 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. 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 represents the hours and pay rate, and the withholding rate is assumed to be 10%. When computeNetPay ( ) receives one argument, it represents the number of hours worked, the withholding rate is assumed to be 10%, and the hourly rate is assumed to be 5.65. Name the program as Pay.java.


    Guys i really really tried hard to sovle these problems. But to no avail
    This is my last resort. I need my grades Its really bothering me. :mad:

    -help me pls

    rhaii

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Can we see what you have attempted?

  3. #3
    ryamz is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Default

    i tried this code:
    but there something wrong in "{}"


    class Pay {
    private static final double DEFAULT_WITHHOLDING_RATE = 15;
    private static final double DEFAULT_PAY_RATE = 6.50;

    private int hoursWorked; // or float??
    private double rateOfPayPerHour;
    private double withholdingRate;
    private double grossPay;
    private double netPay;

    public double computeNetPay(int hoursWorked, double payRate, double withholdingRate) {
    grossPay = hoursWorked*payRate;
    netPay = grossPay - withholdingRate;
    }

    public double computeNetPay(int hours, double payRate) {
    grossPay = hoursWorked*payRate;
    netPay = grossPay - grossPay*DEFAULT_WITHHOLDING_RATE/100;
    }

    public double computeNetPay(int hours) {
    grossPay = hoursWorked*DEFAULT_PAY_RATE;
    netPay = grossPay - grossPay*DEFAULT_WITHHOLDING_RATE/100;
    }
    }

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    there something wrong
    Do you get an error from the compiler?

    Please copy and paste the full text of the error message.
    Also show the lines of code in your program that the error message refers to.

  5. #5
    ryamz is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Default

    public class pay {
    private static final double DEFAULT_WITHHOLDING_RATE = 10;
    private static final double DEFAULT_PAY_RATE = 5.65;

    private int hoursWorked; // or float??
    private double rateOfPayPerHour;
    private double withholdingRate;
    private double grosspay;
    private double netpay;

    public double computeNetPay(int hoursWorked, double payRate, double withholdingRate) {
    grosspay = hoursWorked*payRate;
    netpay = grosspay - withholdingRate;
    }

    public double computeNetPay(int hours, double payRate) {
    grosspay = hoursWorked*payRate;
    netpay = grosspay - grosspay*DEFAULT_WITHHOLDING_RATE/10;
    }

    public double computeNetpay(int hours) {
    grosspay = hoursWorked*DEFAULT_PAY_RATE;
    netpay = grosspay - grosspay*DEFAULT_WITHHOLDING_RATE/10;
    }
    }



    and this is it says:
    C:\Documents and Settings\blah\My Documents\pay.java:14: missing return statement
    }
    ^
    C:\Documents and Settings\blah\My Documents\pay.java:19: missing return statement
    }
    ^
    C:\Documents and Settings\blah\My Documents\pay.java:24: missing return statement
    }
    ^
    3 errors

    Process completed.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    missing return statement
    Can you read and understand the message OK? It seems pretty clear.

    You have several methods that say they are going to return a double value but the compiler can not see where that is done. You need to add return statements to all those methods or change them to void.

  7. #7
    ryamz is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Default

    can u heLp me for that :(

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    add this at end of the methods:

    return THEVALUETOBERETURNED;

    Replacing the uppercase word with the value to return.

  9. #9
    ryamz is offline Member
    Join Date
    Jul 2010
    Posts
    16
    Rep Power
    0

    Default

    public double computeNetpay(int hours) {
    grosspay = hoursWorked*DEFAULT_PAY_RATE;
    netpay = grosspay - grosspay*DEFAULT_WITHHOLDING_RATE/10;
    }

    return valuetoreturn;
    }
    like this?

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    What does the compiler say? Try your code BEFORE posting it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •