CIS 1068 - Homework 7

Handed out: 03/02/10
Due: by 10pm on 03/15/10

For this assignment, you will need three files: Your program will deal two random 5-card poker hands for two players, and print each hand and what type of hand it is (e.g., quads, flush, trips, high card). It will then determine which hand is better and print out which player wins the round. It will then prompt the user asking if s/he wants to play again and, if the answer is yes, go thru another round. Sample output from the program is below.

The program begins by dealing five cards each to two players. The next part of the program prints out each player's hand, representing each card in the hand as a 2-character String with rank (AKQJT98765432) and suit (hdcs), and its evaluation. Note that PokerHandAssessor.java contains an assess() method that will print out a hand evaluation. Finally, the program determines which player has the better hand and prints out the result. If both players have quads, or both players have ushes, or both players have trips, the program should print out that they tied (in contrast to traditional poker, where the rank of the quads, flush, or trips matters). Remember that quads beat flushes, flushes beat trips, and trips beat high card hands. If both players have only high card hands, you should determine the winner by determining whose high card is higher. If the high cards have the same rank, then the round is a tie (the suit does not matter).

Your program should match the execution log shown below, except for those parts that were determined at random (the playing cards, the type of hands, the winner).

In the PokerHand class, you should implement a constructor that takes 5 Strings as parameters, representing the five cards in the hand. You should also implement two instance methods:

Note that the methods getQuadsRank, getFlushSuit, getTripsRank, getHighCardRank, and numericValue in PokerHandAssessor may be useful here. As before, you are only required to check for four of the nine possible combinations: Four of a Kind, Flush, Three of a Kind, and High Card.

In the Dealer class, you should fill out the skeleton code in order to implement the main method, the dealOneCard method, the dealOneHand method, and the playOneRound method. To repeat: do not modify PokerHandAssessor.java for this assignment. You will find it very useful to use, but do not change it, and do not hand it in. You should not refer to PokerHandAssessor anywhere in the Dealer class. Only the PokerHand class may use it. Thus the PokerHandAssessor class is decoupled from the Dealer class.

In this assignment you do not have to make sure that the cards in a hand are all different (for example, that the Ace of Hearts does not appear twice) or that the cards in the hands of the two players are all different (for example, that both hands in a round contain the Ace of Hearts). Of course you are free to do extra work and make sure that all cards are different.

Sample Output

This program deals 5-card hands to two poker players, and determines whose hand
is better.

Round 1:
Player 1:
	Ks
	As
	Ts
	8h
	6h
	A high
Player 2:
	2s
	8h
	8d
	Jh
	Js
J high

Player 1 wins.

Do you want to play another round? yes

Round 2:
Player 1:
	As
	9c
	5d
	Jh
	Ac
	A high
Player 2:
	As
	4c
	5h
	Ks
	9s
	A high

It's a tie!

Do you want to play another round? no

Good Bye