Results 1 to 10 of 10
Thread: oo-p laboratory problem
- 07-22-2010, 01:26 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 16
- Rep Power
- 0
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, 01:30 AM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Can we see what you have attempted?
- 07-22-2010, 01:39 AM #3
Member
- Join Date
- Jul 2010
- Posts
- 16
- Rep Power
- 0
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, 01:52 AM #4
Do you get an error from the compiler?there something wrong
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, 02:06 AM #5
Member
- Join Date
- Jul 2010
- Posts
- 16
- Rep Power
- 0
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, 02:08 AM #6
Can you read and understand the message OK? It seems pretty clear.missing return statement
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, 02:10 AM #7
Member
- Join Date
- Jul 2010
- Posts
- 16
- Rep Power
- 0
can u heLp me for that :(
- 07-22-2010, 02:16 AM #8
add this at end of the methods:
return THEVALUETOBERETURNED;
Replacing the uppercase word with the value to return.
- 07-22-2010, 02:27 AM #9
Member
- Join Date
- Jul 2010
- Posts
- 16
- Rep Power
- 0
like this?public double computeNetpay(int hours) {
grosspay = hoursWorked*DEFAULT_PAY_RATE;
netpay = grosspay - grosspay*DEFAULT_WITHHOLDING_RATE/10;
}
return valuetoreturn;
}
- 07-22-2010, 02:29 AM #10


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks