Homework assignment 3
CS 150
Spring, 2011
due: May 13 (not to be
handed in)
Do the following problems from chapter 9 of R&S (pp. 616-622):
3, 7, 9, 10, 13, 14, 25
(1st ed. ch 9: 3, 13, 6, 7, 13, --, --, 25)
X1. a. Rewrite the Deck and Hand classes of the Blackjack lab so
that they are subclasses of ArrayList<Card>; that is, both are
specialized versions of ArrayList<Card>. That means that
they inherit all of the methods of ArrayList, such as add, get, set,
remove, etc. It should be possible to do this without declaring
any instance variables in either class.
b. What are the pros and cons of using inheritance in this case?
chapter 10 (pp,. 674-675):
2, 3, 4, 5, 6, 7 (use a for each loop), 8, 9, 10, 16
(1st ed. ch 10: 2, 3, 4, 5, 6, 7, 8, 9, 10, 16)
chapter 12 (pp. 764-768):
2, 3, 4, 5, 8, 9, 14
(1st ed. ch 12: 2, 3, --, --, 6, 7, 11)
chapter 13 (pp. 816-818)
9, 13a, 14a
(1st ed. ch 13: 9, 13 (first bullet), 14 (first bullet))
X2. For the arrays given in problems 13 and 14, show the state of
the elements after five passes of the outermost loop of insertion sort
have occurred.
Answers: (13) 1 2 4 7 8 11
9 5 3 10
(14) -3 1 6 7 8 12 4
21 2 30 -1 9
X3. For the arrays given in problems 13 and 14, show the state of
the elements after five passes of the outermost loop of bubble sort
have occurred.
Answers: (13) 1 2 4 3 5
7 8 9 10 11
(14) -3 1 4 2 6 -1 7
8 9 12 21 30