オーケー週給を戻っていない間。私はこれでコードを再構築しましたが、empWeeklyPayを0に初期化せずに返却する方法を見つけることができません。それをゼロに初期化すれば、私の給料は常にゼロになりますか?誰も私ができることを考えることができますか?私のJavaのループが一部2ので、この上
public double getWeeklyPay()//Call the getWeeklyHours method of the Emp's timecard to get the total
//hours worked and then multiply the returned value by the emp's hourly rate and return the value.
{
TimeCard empTimeCard = timeCard;
double empWeeklyPay;
double totalOtHours;
double totalRegHours;
int i = 0;
while(i <= empTimeCard.NUMDAYS && empTimeCard.getHoursByDay(i) > 8)
{
double empHourlyRate = getHourlyRate();
double otHours = 0;
double regHours = 0;
double sumOtHours = 0;
int sumRegHours = 0;
//grabbing the overtime and reghours and storing them
otHours = empTimeCard.getHoursByDay(i) % 8;
regHours = empTimeCard.getHoursByDay(i) - otHours;
sumOtHours += otHours;
sumRegHours += regHours;
double tmpBasePay = (sumRegHours * empHourlyRate) + (sumOtHours * empHourlyRate * 1.5);
if(Integer.toString(getEmployeeId()).charAt(0) == '0' || Integer.toString(getEmployeeId()).charAt(0) == '2'
|| Integer.toString(getEmployeeId()).charAt(0) == '9')
//Java reads in 1010 so need to convert to a string to do a count on the value.
{
tmpBasePay += (tmpBasePay * .10);
i++;
}
else if(Integer.toString(getEmployeeId()).charAt(0) == '3')
{
tmpBasePay -= (tmpBasePay *.10);
i++;
}
else if(Integer.toString(getEmployeeId()).charAt(0) == '8')
{
tmpBasePay += (tmpBasePay * .20);
i++;
}
totalRegHours = regHours;
totalOtHours = sumOtHours;
if(totalRegHours > 34)
{
tmpBasePay -= (tmpBasePay * .06);
//empWeeklyPay = tmpBasePay;
empWeeklyPay = tmpBasePay;
}
else
{
empWeeklyPay = tmpBasePay;
}
}それは常にreturn
キーワードに遭遇したとしてのみ一回の反復を行いながら
return empWeeklyPay;// <---need to return back this value.
これは 'return'ステートメントの*ロット*です。アイデアが実際にループするのであれば、あなたは 'i'をインクリメントした後に' return'するので、ループを止めてしまいます。 –
書式を修正してください。コードはそのまま読めるわけではありません。 –
大丈夫ああ私は、リターンは私が私のことを警告するためにそのコードnow..thanksを編集した – SaintClaire33