next up previous
Next: Merge Up: Assignment 12: Objects of Previous: Assignment 12: Objects of

Deck objects

This assignment builds on top of the Card class from Homework 11. If you are not satisfied with your solution to that assignment, feel free to use my version from the class web page.

http://rocky.colby.edu/cs151/solutions/hw11/cs151.java

In that program, a deck is implemented as an array of Cards. For example, when we pass a ``deck'' as a parameter, the actual type of the parameter is Card[].

In Chapter 12 of the excellent textbook, ``How to think like a computer scientist,'' I present an alternative representation for a deck, an object type named Deck that contains an array of cards as an instance variable.

You should read Chapter 12 and understand the difference between these two representations before proceeding.

1.
Add a second class definition, Deck, to the program. Like the Card class, the new class cannot be a public class like cs151, which contains main.

2.
Type in the constructors for the Deck class as shown in the book.

3.
Of the methods currently in the Card class, decide which ones would be more appropriate as members of the new Deck class. Move them there and make any changes necessary to get the program to compile and run again.

4.
Look over the program and identify every place where an array of Cards is being used to represent a deck. Modify the program throughout so that it uses a Deck object instead. You can use printDeck in the text as an example.

It is probably a good idea to make this transformation one method at a time, and test the program after each change. On the other hand, if you are confident you know what you are doing, you can make most of the changes with search-and-replace commands.


next up previous
Next: Merge Up: Assignment 12: Objects of Previous: Assignment 12: Objects of
Allen Downey
1999-11-29