Wednesday, April 13, 2011

Division of the class for the final

The final exam takes place on Friday, April 15, from 9 AM to 12 noon.

There is a written part and a labtest part. Both parts have time limits of 80 minutes, with a 20 minute break in between.  The written part takes place in CSE lecture hall C (in the basement), and the labtest part takes place in the Prism lab.
  • If your last name starts with the letter A-L: You will be doing the labtest part first.  Go to the lab at 9 AM.
  • If your last name starts with the letter M-Z: You will be doing the written part first.  Go to CSE C at 9 AM.
  • Exception: Everyone with arrangements through the Alternate Exam Centre will do the labtest part first.
For the first part of the test, you will not be permitted to leave until 80 minutes have elapsed. For the second part, you can leave at any time.

5 comments:

  1. Professor,

    I have noticed that during the Lab exams, preconditions for methods are not given.

    For example, in last lab test, there was a method called avgWeeklyPay(Employee[] list).

    There was no precondition specified on the method, i.e. it wasn't mentioned if list could be null, or an array of null with employees. list = [null, Employee, null] etc.

    Since preconditions are not provided, should we ensure that we take care of all the possible cases and not throw exceptions, or should we not be concerned about that at all.

    So, for above example, do we check if (list == null) return 0?. and also if list[i] i.e. each element is null, to ensure no exceptions are thrown?.

    So, should we just ignore that and run a loop on the list, and so if a client passes a null as list, we would allow it to throw a NullPointerException.


    Please clarify.


    Regards,

    ReplyDelete
  2. If a method doesn't contain any preconditions or throws, you should assume nothing and expect everything.

    As in your example. If the API only lists that the method takes a List of some type and nothing else; then you should check for list size, nulls, etc.

    ReplyDelete
  3. @April 13, 2011 8:14 PM

    Perhaps I misunderstood something, but I thought that we're only responsible for what's given in the API. Aren't we supposed to trust that the API creator knew what they were doing? So if a method says nothing about any special cases, why should I bother and waste time handling those cases? Even if the method ends up not working so great, I still did what I was told. It's the API creator's fault for not specifying how I should handle special cases.

    Thank you

    ReplyDelete
  4. @ April 14, 2011 8:34 PM

    Sorry, I didn't see you were talking about avgWeeklyPay last time (was half asleep when I replied). In that example, if there was no preconditions, you would of just returned 0 as the average weekly pay if passed a NULL list. A list of employees set to null is equivalent to no employees, and the average weekly pay of 0 employees is 0 dollars.

    The precondition basically tells you which special cases you can ignore. They're not going to tell you how to handle the preconditions because they're there for the end user not you. They tell the end user that unless they follow the preconditions, then the final output can't be guaranteed to be correct or even run without crashing.

    You do need to follow the API exactly. If there's no preconditions then anything java will allow to be passed to the method needs to be accounted for. You should be able to determine how to handle each case from the API's description of the method.

    ReplyDelete