Terminally Incoherent

Utterly random, incoherent and disjointed rants and ramblings...

Sunday, April 16, 2006

WTF Code moments...

One of my Graduate Assistant responsibilities this semester is grading homeworks for an introductory Java class. As you can imagine, I see alot of bad code. But every once in a while, I run into something really "special".

The assignment was to write a payroll class, and one of the methods should calculate employees sick days. Every employee gets 1 sick day per 75 hours worked. This is how one of the students tackled the problem:

int totalHoursWorkedTemp = totalHoursWorked;
while(totalHoursWorkedTemp > 75)
{
   totalHoursWorkedTemp = totalHoursWorkedTemp - 75;
   sickDays++;
}

return sickDays;

I was about to mark it wrong, but then I realized that this will actually do the job. Ackward, but valid solution.

I don't know... What's wrong with sickDays = totalHoursWorked/75 (integer division)? But then again, maybe I'm being a minimalist here. I should be glad that they figured out how a loop works, eh?

0 Comments:

Post a Comment

<< Home