Java Assignment : Poker hand implemented in java programming.


Study and review the Case Study: Deck of Cards on page 256 which was presented in the class.
Do not copy the code on page 257 you will be given a starting code that you can use. The first 
thing to do is you put your name and replace the string “YourNameHere”. A lot of declaration 
and initialization is done for you, then you add codes of your own to achieve the objective of 
the project. If you do not know the poker ranking study the ranking at the end of this 
assignment or go to https://www.cardplayer.com/rules-of-poker/hand-rankings . You do not shuffle 
the deck of card you are given the pre shuffle card sequence that you can copy from 
dataOf52NumbersH.txt. This is only an initial test data which does not include the royal flush 
and special straight flush. You must create others five cards sequence to test your program this 
is part of being a good programmer, to test all possible combination that you can think of.
Objective: Group the 52 cards into 10 groups of five cards to form a poker hand starting from 
index 0. (Hand # 1: 0, 1, 2, 3, 4 Hand #2: 5, 6, 7, 8, 9) Display their card value like 5 of hearts, K 
of spades etc. which is easy almost given by following the book case study “Deck of Cards”.
Then determine the poker hand ranking example Royal Flush, Two pair, Four of a kind, ….etc. 
see the sample report next page.


(Again you will NOT generate or shuffle the deck of card you are given the 52 numbers to 
represent the pre-shuffle deck of cards. You will read in the 52 numbers as you can see the first 
few lines of the given starter code.)

The given test data (52 numbers in dataOf52NumbersH.txt) was hand pick and include most of 
the ranking does not include Royal flush and the special straight flush. You must come up with 
your own test data to check all possible poker hand ranks.
I will use different set of 52 cards to grade you. 
Next page is the required result you must produce.

Submitted by : yourNameHere
enter your 52 number : 10 36 23 49 6 1 16 2 3 4 28 15 11 24 12 9 21 
34 8 5 7 20 33 14 27 40 0 17 29 41 44 43 45 46 47 37 25 22 35 19 26 30 
32 31 38 50 51 39 42 48 13 18
Hand # 1
Card number 10 : J of Spades 
Card number 36 : J of Clubs 
Card number 23 : J of Hearts 
Card number 49 : J of Diamonds 
Card number 6 : 7 of Spades 
******************************************** Four of a kind
Hand # 2
Card number 1 : 2 of Spades 
Card number 16 : 4 of Hearts 
Card number 2 : 3 of Spades 
Card number 3 : 4 of Spades 
Card number 4 : 5 of Spades 
******************************************** Pair
Hand # 3
Card number 28 : 3 of Clubs 
Card number 15 : 3 of Hearts 
Card number 11 : Q of Spades 
Card number 24 : Q of Hearts 
Card number 12 : K of Spades 
******************************************** Two pair
Hand # 4
Card number 9 : 10 of Spades 
Card number 21 : 9 of Hearts 
Card number 34 : 9 of Clubs 
Card number 8 : 9 of Spades 
Card number 5 : 6 of Spades 
******************************************** Three of a kind
Etc 
up to Hand # 10
*******************************************
Hand # 10
Card number 50 : Q of Diamonds 
Card number 51 : K of Diamonds 
Card number 39 : A of Diamonds 
Card number 42 : 4 of Diamonds 
Card number 48 : 10 of Diamonds 
******************************************** Flush

Program:

import java.util.Arrays;
import java.util.Scanner;

public class PokerHands {
    public static void main(String[] args) {
        String studentName = "Your Name";
        int[] ranking_deck = new int[52];
        String[] Shape = { "Spades", "Hearts", "Clubs", "Diamonds" };
        String[] ranking = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
        String[] pokerHands = {
                "Royal Flush", // 0
                "Straight flush", // 1
                "Four of a kind", // 2
                "Full House", // 3
                "Flush", // 4
                "Straight", // 5
                "Three of a kind", // 6
                "Two pair", // 7
                "Pair", // 8
                "High Card", // 9
                "next none yet"
        };

        System.out.println("Submitted by : " + studentName);
        Scanner input = new Scanner(System.in);
        System.out.print("\nEnter your 52 number: ");
        // 10 36 23 49 6 1 16 2 3 4 28 15 11 24 12 9 21 34 8 5 7 20 33 14 27 40 0 17 29 41 44 43 45 46 47 37 25 22 35 19 26 30 32 31 38 50 51 39 42 48 13 18

        // initialize cards
        for (int i = 0; i < ranking_deck.length; i++) {
            ranking_deck[i] = input.nextInt();
        }
        System.out.println(Arrays.toString(ranking_deck) + "\n\n");

        for (int i = 0; i < 52; i++) {
            if (i%5 == 0){
            System.out.println("*******************************************");
            }
            String rank = ranking[(ranking_deck[i] % 13)];
            String suit = Shape[ranking_deck[i] / 14];
            System.out.print("Card number " + ranking_deck[i] + " : " + rank + " of " + suit);
            System.out.println();
        }
    }
}

Output:

Enter your 52 number: 10 36 23 49 6 1 16 2 3 4 28 15 11 24 12 9 21 34 8 5 7 20 33 14 27 40 0 17 29 41 44 43 45 46 47 37 25 22 35 19 26 30 32 31 38 50 51 39 42 48 13 18
[10, 36, 23, 49, 6, 1, 16, 2, 3, 4, 28, 15, 11, 24, 12, 9, 21, 34, 8, 5, 7, 20, 33, 14, 27, 40, 0, 17, 29, 41, 44, 43, 45, 46, 47, 37, 25, 22, 35, 19, 26, 30, 32, 31, 38, 50, 51, 39, 42, 48, 13, 18]


Submitted by : Your Name
Enter your 52 number: 10 36 23 49 6 1 16 2 3 4 28 15 11 24 12 9 21 34 8 5 7 20 33 14 27 40 0 17 29 41 44 43 45 46 47 37 25 22 35 19 26 30 32 31 38 50 51 39 42 48 13 18
[10, 36, 23, 49, 6, 1, 16, 2, 3, 4, 28, 15, 11, 24, 12, 9, 21, 34, 8, 5, 7, 20, 33, 14, 27, 40, 0, 17, 29, 41, 44, 43, 45, 46, 47, 37, 25, 22, 35, 19, 26, 30, 32, 31, 38, 50, 51, 39, 42, 48, 13, 18]


*******************************************
Card number 10 : J of SpadesCard number 36 : J of Clubs
Card number 23 : J of Hearts
Card number 49 : J of Diamonds
Card number 6 : 7 of Spades
*******************************************
Card number 1 : 2 of Spades
Card number 16 : 4 of Hearts
Card number 2 : 3 of Spades
Card number 3 : 4 of Spades
Card number 4 : 5 of Spades
*******************************************
Card number 28 : 3 of Clubs
Card number 15 : 3 of Hearts
Card number 11 : Q of Spades
Card number 24 : Q of Hearts
Card number 12 : K of Spades
*******************************************
Card number 9 : 10 of Spades
Card number 21 : 9 of Hearts
Card number 34 : 9 of Clubs
Card number 8 : 9 of Spades
Card number 5 : 6 of Spades
*******************************************
Card number 7 : 8 of Spades
Card number 20 : 8 of Hearts
Card number 33 : 8 of Clubs
Card number 14 : 2 of Hearts
Card number 27 : 2 of Hearts
*******************************************
Card number 40 : 2 of Clubs
Card number 0 : A of Spades
Card number 17 : 5 of Hearts
Card number 29 : 4 of ClubsCard number 41 : 3 of Clubs
*******************************************
Card number 44 : 6 of Diamonds
Card number 43 : 5 of Diamonds
Card number 45 : 7 of Diamonds
Card number 46 : 8 of Diamonds
Card number 47 : 9 of Diamonds
*******************************************
Card number 37 : Q of Clubs
Card number 25 : K of Hearts
Card number 22 : 10 of Hearts
Card number 35 : 10 of Clubs
Card number 19 : 7 of Hearts
*******************************************
Card number 26 : A of Hearts
Card number 30 : 5 of Clubs
Card number 32 : 7 of Clubs
Card number 31 : 6 of Clubs
Card number 38 : K of Clubs
*******************************************
Card number 50 : Q of Diamonds
Card number 51 : K of Diamonds
Card number 39 : A of Clubs
Card number 42 : 4 of Diamonds
Card number 48 : 10 of Diamonds
*******************************************
Card number 13 : A of Spades
Card number 18 : 6 of Hearts

Comments

  1. Thanks for sharing this informative blog. this blog is really helpfully for game developer. if you want more information aboutpoker software developers Visit our website and call now - 6507276690

    ReplyDelete

Post a Comment