Quiz 2

One-page version suitable for printing.

Statistics:

mean     24.583 (295.000/12)
stddev   4.804
median   23.000
midrange 21.500-29.000

1   7.16 / 10
2   4.08 / 5
3   3.50 / 5
4   5.83 / 10
 + 4-point bonus

Question 2-1

Explain why generics make more sense as a feature in statically typed languages than in dynamically typed languages.

Solution

Question 2-2

Fully parenthesize the following expression to illustrate the order in which Smalltalk will evaluate it.

   2     +     3     factorial     *     4     gcd:     12     -     4

Solution

Question 2-3

Give Smalltalk code for defining a new instance method deductPenalty in our Account class, which should deduct 10 from the balance if the current balance is below 500. Your code should use the withdraw: method already defined for the Account class.

Solution

Question 2-4

Give and describe an example of how the Composite pattern shows up in the AWT or Swing user interface libraries of Java.

Solution