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

Due by the start of class on Friday, 04/17/2015

In this assignment, you will gain some practice with class definitions. You will begin with an example program that includes a convention for representing playing cards and several methods that operate on this representation. Your job is to transform this into a version that uses objects from a Card class, which you will complete from a skeleton distribution. For the most part, that involves moving method definitions around (there is very little in the way of hard algorithmic problem solving).

Supporting Code

Your Job

The printDeck source code is a complete program that reads input data representing the number of playing cards in a set, followed by a series of numbers between 1 and 52, representing those cards. The number convention for the cards is to group all cards of a suit together, then order by poker rank: 1 through 13 represent the Clubs suit (from 2 through 9, then jack, queen, king, and ace), 14 - 26 represent the Diamonds suit (same ranking within), 27 - 39 represent the Hearts, and 40 - 52 the Spades.

The program first prints out the cards (with rank and suit names) according to the order they were given, then sorts then (in poker ordering), and prints them again, in sorted order. There is no prompt for input, so only the input need be given.

For example, the input

7 3 13 27 52 50 39 40

represents seven cards, which will result in the output

7 cards.
4 of Clubs
Ace of Clubs
2 of Hearts
Ace of Spades
Queen of Spades
Ace of Hearts
2 of Spades

In poker order:  
2 of Hearts
2 of Spades
4 of Clubs
Queen of Spades
Ace of Clubs
Ace of Hearts
Ace of Spades

Your Job

Your job is not to write this program, as it already exists (see "Supporting Code", above). Rather, you are to refactor this code in order to complete the definition of a Card class, and modify the printDeck source code to use this class appropriately. Here's how:

You now have a Card class that is fully functional and ready for use. Now you'll need to modify printDeck to use it:

You'll know you got everything right if, after making these changes, the program printDeck behaves the same way as the original version.

Turn In

The source code for your completed source code files, printDeck.java and Card.java, in a subfolder of your turn-in directory called "lab9". Please also provide a paper copy of your work.

Standards (READ ME)

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.

General


John H. E. Lasseter