Description
This program is the first in a three-part series that will result in a GUI-based simple poker game.
In Program 3A, you will create a Card class to represent a standard playing card. You will also create a Deck class that contains several Card objects. When a game starts, Card objects will be taken from a Deck object and dealt to the players. You will also create a Hand class that contains several Card objects that a player currently holds.
A standard playing card has a suit and a face value. The suits are
Spades,
Clubs, Diamonds, and Hearts. The face values are 2-10, Jack, Queen,
King, and
Ace. The 52 cards in a standard deck are the result of having one face
value
in each suit (13 faces * 4 suits = 52 cards).
Besides the face and suit, a card is also associated with a number
that specifies the order of a card in an unshuffled deck. We
will use the following convention in our program: the cards 2, 3, 4
5, 6, 7, 8, 9, 10, Jack, Queen, King, and Ace of hearts have the card
number 1-13. The cards of clubs, diamonds, and spades will have the
number
14-26, 27-39, and 40-52.
NOTE: Parts of this
assignment require some knowledge of Arrays, which we will learn about
in class next Monday. The assignment is being made available early so
you can read up on the background (if you need) and prepare for it.
A simple variant of poker
There are several variants of poker. We will implement a very simple variant of poker in which a player plays against a dealer. In our variant of poker, five cards are dealt to the player and the dealer when they start a game. After that, the program will determine whether the player wins, ties or loses the game. To further simplify matters, there is no betting although the program does keep counts of wins, ties, and losses for the player.
The standard rules of poker are applied to determine whether the player wins, ties, or loses the game. In poker, a hand has five cards and falls into different categories (or ranks) based on the combination of the cards. A hand of a certain category beats any hand of lower categories. If two hands are in the same category, the rank of individual cards decides which hand is better. The ranking of the individual cards, from high to low, is ace, king, queen, jack, 10, 9, 8, 7, 6, 5, 4, 3, 2. The ranking of hands, from high to low, is royal flush, straight flush, four of a kind, full house, flush, straight, three of a kind, two pairs, pair, and high card. The rules of poker are described here and here. You can also find additional information about poker on the Internet. Note that I provide these links only for informational purposes so that you can understand and implement the rules of poker. I do not endorse or encourage you to gamble on the Internet or anywhere else.
Program 3A Tasks
You are given an outline of the files needed to complete this assignment (see "What to Do").
Modify the given class called Card that represents a standard playing card. You must include two constructor methods that initialize the values of the member variables (since a card number can map unambiguously to a suit and a face value and vice versa, we will have two constructor methods for the Card class). One constructor method takes the card number as its parameter. The other constructor method takes the suit and face value of the card as its parameters. You must also implement a toString method that returns a String representing the Card object, and getFace, getSuit, getCardNo methods that allow each of the member variables to be accessed.
Modify the given class Hand that represents a hand of a player. An object of class Hand starts out empty and has a method TakeCard that accepts a new card. You must implement a method getNumCards that returns the number of cards contained in an object of class Hand. You must implement a method getCard that takes a position in a hand as a parameter and returns an object of class Card at that position. You must implement a method resetHand that allows to reset the hand and throws away all the cards in that hand. You must also implement a method SortHand that sorts all cards in a hand from low to high based on the face values of the cards. The Hand class should also have a method isSorted that indicates whether an object of class Hand is sorted. You must also implement a method toString that returns a String representing the objects of class Card currently in an object of class Hand. You can find the code used for sorting here (this sorting algorithm is called "selection sort").
Modify the given class Deck that represents a deck of card. The class Deck contains 52 objects of the class Card when a game starts. You must implement a method Shuffle that shuffles the cards for a specified number of times. You must implement a method Deal that deals a card from the top of the Deck. You must implement a method cardsLeft that returns the number of cards left in the deck. You must implement a method toString that returns a String representing the objects of class Card currently in a Deck. You must implement a method swap that swaps two cards in the deck. The constructor of class Deck must include the method Shuffle.
The test program PokerHand.java that I provide to you will generate an object of class Deck and an object of class Hand representing the player's hand. The test program deals 5 cards to the player and uses the method toString to print out the cards of the hand (unsorted and sorted).
Sample Output
Here is sample output generated by the test program PokerHand.java. I will grade your program based on multiple runs of the test program. Hence, you should test your program many times to see whether your program works correctly.
Player's hand (unsorted):
Jack of hearts
Ace of spades
8 of clubs
5 of clubs
5 of diamonds
Player's hand (sorted):
5 of clubs
5 of diamonds
8 of clubs
Jack of hearts
Ace of spades
What to Turn in
What to Do
Requirements
When I run/examine your program, it must satisfy the following requirements. The maximum point value for each is shown in brackets.