ITEC 120 Back to Assignment index page
   
Assignment 4 - What a deal
Submit your program to the RU09 folder in your directory on neelix.

Description:  You'll write a program to deal a hand of cards.

The Card class:
Write a class to represent a Playing card. A card will have 2 pieces of instance data, one to represent the suit (clubs, diamonds, hearts, or spades), and one to represent the rank (2-10, J, Q, K, A). When a playing card is created, the suit and rank are randomly assigned.

The methods:

The program4.java driver:

Assume you are working with a single deck of cards. So, you will never have 2 of the same card in a hand. When you deal the cards (create them and put them in the array) you must check to see that the card has not already been dealt. You'll use the .equals method to check all the previously dealt cards to make sure your new card does not match one of them. (If it does, you need to create another one.)

To sort the array, implement the Comparable class and use the insertionSort method in this Sorts.java class.

The order of the cards are this:

So, for example the 2 of Spades is greater than the 9 of clubs.
The Ace of Diamonds is greater than the King of Diamonds.

The 2 of Hearts is greater than the Ace of Diamonds.

Here's a sample run:

Program outputs: How many cards would you like?
User inputs: 5
Program outputs:

6C AC 10H 6S 8S

Would you like to deal another hand? (y or n)

User inputs: y
Program outputs: How many cards would you like?

User inputs: 56
Program outputs:

You must choose a number between 1 and 52.

User inputs: 7
Program outputs:

4C 6C 6D 9D KD JS AS

Would you like to deal another hand? (y or n)

User inputs: n

TURNING IN YOUR PROGRAM: You will turn in two files. You'll have the driver program, named program4.java, and the Card class, named Card.java. Submit both files to neelix in the appropriate folder.