Homework: Review III


Here are some review questions to give you extra practice with what you have learned so far and help you prepare for the second midterm exam.

  1. Implement the following two static methods. Note that, although the two methods compute the same function, the first one clears the given NaturalNumber while the second one restores it.
  2. Implement the static method declared as follows:
  3. Implement the static method declared as follows:
  4. For each of the following terms (in no particular order), provide a short definition.
    1. design-by-contract
    2. precondition
    3. postcondition
    4. testing
    5. debugging
    6. parameter mode
    7. clears
    8. replaces
    9. restores
    10. updates
    11. immutable type
    12. primitive type
    13. reference type
    14. object
    15. aliasing
    16. declared type/static type
    17. object type/dynamic type
    18. implements
    19. extends
    20. method overriding
    21. subinterface/derived interface/child interface
    22. superclass/base class/parent class
    23. polymorphism
    24. recursion
  5. Carefully trace over the following code. Draw a picture (of the kind used in Arrays and References, slide #5) of the value of the array after the initialization code completes.
    What is wrong with the code above and how would you fix it so that its behavior matches the comment?
  6. Argue from the definition of extends that NaturalNumber extends Standard as shown on slide 2 of Concepts of Object-Oriented Programming.
  7. Argue from the definitions of extends and implements that C4 implements I2 and that C3 implements I1 on slides 11-12 of Concepts of Object-Oriented Programming.

Additional Questions

  1. Implement the static method declared as follows:
  2. Modify your implementation of the static method toInt so that it is an instance method for NaturalNumber declared as follows: