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. Awkward, 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?

This entry was posted in Uncategorized. Bookmark the permalink.



One Response to WTF Code moments…

  1. Dave Mozilla Firefox Windows says:

    it looks perfect for someone who cant grasp division and modulus. hehe

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *