# oo-p laboratory problem

• 07-22-2010, 02:26 AM
ryamz
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
• 07-22-2010, 02:30 AM
al_Marshy_1981
Can we see what you have attempted?
• 07-22-2010, 02:39 AM
ryamz
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;
}
}
• 07-22-2010, 02:52 AM
Norm
Quote:

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.
• 07-22-2010, 03:06 AM
ryamz
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.
• 07-22-2010, 03:08 AM
Norm
Quote:

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.
• 07-22-2010, 03:10 AM
ryamz
can u heLp me for that :(
• 07-22-2010, 03:16 AM
Norm
add this at end of the methods:

return THEVALUETOBERETURNED;

Replacing the uppercase word with the value to return.
• 07-22-2010, 03:27 AM
ryamz
Quote:

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

return valuetoreturn;
}
like this?
• 07-22-2010, 03:29 AM
Norm
What does the compiler say? Try your code BEFORE posting it.