Introduction to Programming (CPSC 124)
—Hobart & William Smith Colleges, Fall 2014
Thursday Lab #9: class definitions
Home | Syllabus | Calendar | Class Notes | Labs and Projects | General Notes

Due by 2:59 pm on Friday, November 14

Bonus Lab Assignment

We are just beginning our study of class definitions, you have a project due Saturday and an exam on Monday. Hence, this lab assignment is optional. If you choose to complete it (by tomorrow's deadline), it can be used to replace your lowest lab assignment score for the semester.

Object-Oriented Program Design

Previous work in this class—Lab #6 (link) and Project #3 (link)—involved a representation of playing card data with the integers 1 ... 52. For one assignment, you wrote a program, printDeck, which read a sequence of integers (each between 1 and 52) and printed out a list of the corresponding names of the playing cards, in the order their numbers appear. In the richer version, cardShuffle, the program reads a list of card deck permutations ("shuffles") along with a list of applications of those permutations, applies them to a sorted deck of cards, and prints the result.

Here is a solution to the printDeck problem: http://pastie.org/private/9og4vs6hn9z7hivg5ffzrw

And here is my version of cardShuffle: http://pastie.org/private/cxdfkqrtshgvsvd5w8htyq

In both programs, we adopt a fairly simple representation of a playing card, as an integer between 1 (the 2 of Clubs) and 52 (Ace of Spades). With this simple representation, we are then able to perform various "playing card-related" tasks. In particular, both programs perform a change of representation by displaying to the user a String containing the card's proper name (e.g. "2 of Clubs" for card 1, "Ace of Spades" for card 52, and so on).

In class this week, we saw how to restructure both programs to use an object-based representation of a playing card, which encapsulates both the low-level representation elements of a card and the common tasks associated with playing card values. You job in this lab is to perform this restructuring yourself:

Even if you were perfectly happy with your own solutions to these assignments, please use the source files linked above for this lab. Your transformed source code should behave identically to the original, non-object-oriented versions.

Standards

Formatting Requirements

See the Style Guide, available from the General Notes section of our course web site. All elements of beautiful, clear code style described there will be expected.

In the header comments of both printDeck.java and cardShuffle.java, add the line:

Modified by:  YOUR NAME

General


Turn In


John H. E. Lasseter