Develop a program that plays "Five Card Stud". The user plays against the computer. The program will "deal" five cards to the user and itself. Whoever has the highest hand wins. Inform the user who has won that hand, and ask if the user wants to play again. Interaction is as follows:
Your hand is:
2 of hearts
3 of diamonds
4 of clubs
2 of clubs
3 of hearts
My hand is:
Ace of clubs
Ace of hearts
Ace of diamonds
King of clubs
King of hearts
I win, sorry…
Play again (y,n)? n
Thanks for playing.
You need to develop 4 classes for this program. They are the Card, Deck, and Hand classes and the class containing your main method.
The Card class must contain (at least) the following methods:
Card() – constructor that initialized the value and suit of the Card
getValue() – returns the current value of the Card
getSuit() – returns the current suit of the Card
equals() – returns true when the passed Card is equal to the current Card
compareTo() – compares two Cards (passed and current) returning -1, 0 or 1
toString() – returns the string representation of the current Card, i.e. "King of hearts"
The Deck class must contain (at least) the following methods:
Deck() – constructor that initializes the Deck of Cards
shuffle() – shuffles the Deck
deal() – returns the Card on the top of the Deck
Implement the Deck as an array of Cards.
The Hand class must contain (at least) the following methods:
equals() – returns true when the passed Hand is equal to the current Hand
compareTo() – compares two Hands (passed and current) returning -1, 0 or 1
toString() – returns the string representation of the current Hand, i.e. "King of hearts\n2 of clubs\n etc…"
Implement the Hand as an array of five Cards.
For determining the winner of the deal, use the compareTo() method of the Hand class. It is not necessary to include all the rules of the game (like a pair, or 3 of a kind.) to determine the order of two Hands, simply calculate the sum of the face values of each card in the hand. You may ignore the suit; they are all equal. This should greatly simply the compareTo() method of your Hand class.
The fourth class is your main method class. It is implemented procedurally.
Last edited by Richard19Perez77
on Fri Mar 11, 2011 3:19 am, edited 1 time in total.