好吧,所以第二部分就這一點。我重構了代碼,但現在我無法找到一種方法來返回empWeeklyPay,而無需將其初始化爲零。如果我將它初始化爲零,那麼我的工資總是零?任何人都可以想到我能做的任何事情嗎?我的java while循環沒有返回每週薪酬
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 empWeeklyPay;// <---need to return back this value.
這是* return *語句。如果這個想法實際上是循環的,那麼你沒有這樣做,因爲你在遞增'i'之後'返回',從而停止循環。 – 2012-03-01 19:58:08
請修復您的格式。代碼不可能按原樣讀取。 – 2012-03-01 19:58:31
啊好吧我認爲回報是搞砸了..ok讓我改變.. – SaintClaire33 2012-03-01 20:00:37