Menu

[Solved]Java Really Need Help Implementing Checkplayerhand Playgame Methods Videopoker Class Publi Q37192384

Java.
I really need help implementing thecheckPlayerHand() and playGame()methods in the VideoPoker class!

import java.util.*; Ref: Short Description and Poker rules Video poker is also known as draw poker. The dealer uses a 52-card

public class VideoPoker {

// default constant values
private static final int defaultBalance=100;
private static final int numberCards=5;

// default constant payout value and playerHand types
private static final int[]winningMultipliers={1,2,5,10,15,20,25,50,250};
private static final String[] winningHands={
   “Royal Pair” , “Two Pairs” , “Three of a Kind”,”Straight”, “Flush   “,
   “Full House”, “Four of a Kind”, “Straight Flush”,”Royal Flush” };

// use one deck of cards
private Decks thisDeck;

// holding current player 5-card hand, balance, bet
private List<Card> playerHand;
privateintplayerBalance;
privateintplayerBet;

/** default constructor, set balance = defaultBalance */
publicVideoPoker()
{
   this(defaultBalance);
}

/** constructor, set given balance */
publicVideoPoker(int balance)
{
   this.playerBalance= balance;
   try {
thisDeck = new Decks(1);
   } catch (Exception e) {
   System.out.println(e.getMessage());
   }
}

/** This display the payout table based on winningMultipliersand
* winningHands arrays */
private void showPayoutTable()
{
   System.out.println(“nn”);
   System.out.println(“Payout Table   Multiplier “);
  System.out.println(“=======================================”);
   int size = winningMultipliers.length;
   for (inti=size-1; i >= 0; i–) {
      System.out.println(winningHands[i]+”t|t”+winningMultipliers[i]);
   }
   System.out.println(“nn”);
}

/** Check current playerHand using winningMultipliers andwinningHands arrays
* Must print yourHandType (default is “Sorry, you lost”) at the endof function.
* This can be checked by testCheckHands() and main() method.
*/
private voidcheckPlayerHand()
{
   // implement this method
}

/*************************************************
* add new private methods here ….
*
*************************************************/

public voidplayGame()
{
/** The main algorithm for single player poker game
*
* Steps:
*        showPayoutTable()
*
*        ++  
*        show balance, get bet
*       verify bet value, updatebalance
*       reset deck, shuffle deck,
*       deal cards and display cards
*       ask for positions of cards tokeep
* get positions in one input line
*       update cards
*       check hands, display propermessages
*       update balance if there is apayout
*       if balance = O:
*           end ofprogram
*       else
*           ask if theplayer wants to play a new game
*           if the answeris “no” : end of program
*           else:showPayoutTable() if user wants to see it
*           goto ++
*/
   // implement this method

}

// Here is the Card class:

class Card {
  
/* constant suits and ranks */
static final String[] Suit = {“”,”Clubs”, “Diamonds”, “Hearts”,”Spades” };
static final String[] Rank ={“”,”A”,”2″,”3″,”4″,”5″,”6″,”7″,”8″,”9″,”10″,”J”,”Q”,”K”};

/* Data field of a card: rank and suit */
privateintcardRank; /* values: 1-13 (see Rank[] above) */
privateintcardSuit; /* values: 1-4 (see Suit[] above) */

/* Constructor to create a card */
/* throw PlayingCardException if rank or suit is invalid */
public Card(int suit, int rank) throws PlayingCardException {
   if ((rank < 1) || (rank > 13))
       throw newPlayingCardException(“Invalid rank:”+rank);
   else
   cardRank = rank;
   if ((suit < 1) || (suit > 4))
       throw newPlayingCardException(“Invalid suit:”+suit);
   else
   cardSuit = suit;
}

/* Accessor and toString */
publicint getRank() { return cardRank; }
public int getSuit() { return cardSuit; }
public String toString() { return Rank[cardRank] + ” ” +Suit[cardSuit]; }

// Here is the Decks class:

public class Decks {

private List<Card> constructedDeck;   

private List<Card> gameDeck;

  
public Decks(int n) throws PlayingCardException
{
  
if (n<1) {
throw new PlayingCardException(“n < 1”);
}
  
constructedDeck = new ArrayList<Card>();
gameDeck = new ArrayList<Card>();
  
for (inti=1; i<=n; i=i+1) {
  
for (int suit=1; suit<=4; suit=suit+1) {
  
for (int rank=1; rank<=13; rank=rank+1) {
Card c = new Card(suit,rank);
constructedDeck.add(c);
}
}
}

gameDeck.addAll(constructedDeck);
}

  
public void shuffle()
{
  
Collections.shuffle(gameDeck);
}

public List<Card> deal(intnumberCards) throwsPlayingCardException
{

if (numberCards>this.remainSize()) {
throw new PlayingCardException(“number of cards is greater thanremaining cards”);
}
  
List<Card> dealCards = new ArrayList<Card>();
  
for (inti=0; i<numberCards; i=i+1) {
  
Card c = gameDeck.remove(i);
  
dealCards.add(c);
}
  
returndealCards;
}

  
public void reset()
{
gameDeck.clear();
  
gameDeck.addAll(constructedDeck);

}

  
publicintremainSize()
{
   returngameDeck.size();
}

  
public String toString()
{
   return “”+gameDeck;
}

/*************************************************
* do not modify testCheckPlayerHand() below
* it is used for testing checkPlayerHand().
*
*************************************************/

public void testCheckPlayerHand()
{
   try {
       playerHand = newArrayList<Card>();

       // set Royal Flush
       playerHand.add(newCard(4,1));
       playerHand.add(newCard(4,10));
       playerHand.add(newCard(4,12));
       playerHand.add(newCard(4,11));
       playerHand.add(newCard(4,13));
      System.out.println(playerHand);
       checkPlayerHand();
      System.out.println(“———————————–“);

       // set Straight Flush
       playerHand.set(0,newCard(4,9));
      System.out.println(playerHand);
       checkPlayerHand();
      System.out.println(“———————————–“);

       // set Straight
       playerHand.set(4, newCard(2,8));
      System.out.println(playerHand);
       checkPlayerHand();
      System.out.println(“———————————–“);

       // set Flush
       playerHand.set(4, newCard(4,5));
      System.out.println(playerHand);
       checkPlayerHand();
      System.out.println(“———————————–“);

       // “Royal Pair” , “Two Pairs” ,”Three of a Kind”, “Straight”, “Flush   “,
      // “Full House”, “Four of a Kind”,”Straight Flush”, “Royal Flush” };

       // set Four of a Kind
       playerHand.clear();
       playerHand.add(newCard(4,8));
       playerHand.add(newCard(1,8));
       playerHand.add(newCard(4,12));
       playerHand.add(newCard(2,8));
       playerHand.add(newCard(3,8));
      System.out.println(playerHand);
       checkPlayerHand();
      System.out.println(“———————————–“);

       // set Three of a Kind
       playerHand.set(4, newCard(4,11));
      System.out.println(playerHand);
       checkPlayerHand();
      System.out.println(“———————————–“);

       // set Full House
       playerHand.set(2, newCard(2,11));
      System.out.println(playerHand);
       checkPlayerHand();
      System.out.println(“———————————–“);

       // set Two Pairs
       playerHand.set(1, newCard(2,9));
      System.out.println(playerHand);
       checkPlayerHand();
      System.out.println(“———————————–“);

       // set Royal Pair
       playerHand.set(0, newCard(2,3));
      System.out.println(playerHand);
       checkPlayerHand();
      System.out.println(“———————————–“);

       // non Royal Pair
       playerHand.set(2, newCard(4,3));
      System.out.println(playerHand);
       checkPlayerHand();
      System.out.println(“———————————–“);
   }
   catch (Exception e)
   {
      System.out.println(e.getMessage());
   }
}
}

import java.util.*; Ref: Short Description and Poker rules Video poker is also known as draw poker. The dealer uses a 52-card deck, which is played fresh after each playerHand. The player is dealt one five-card poker playerHand After the first draw, which is automatic, you may hold any of the cards and draw k again to replace the cards that you haven ‘t chosen to hold k Your cards are compared to a table of winning combinations k The object is to get the best possible combination so that you earn the highest k payout on the bet you placed. k Winning Combination:s 1. Jacks or Better: a pair pays out only if the cards in the pair are Jacks Queens, Kings, or Aces. Lower pairs do not pay out. k 2. Two Pair: two sets of pairs of the same card denomination. k 3. Three of a Kind: three cards of the same denomination. 4. Straight: five consecutive denomination cards of different suit k 5. Flush: five non-consecutive denomination cards of the same suit. 6. Full House: a set of three cards of the same denomination plus a set of two cards of the same denomination 7. Four of a kind: four cards of the same denomination 8. Straight Flush: five consecutive denomination cards of the same suit 9. Royal Flush: five consecutive denomination cards of the same suit, starting from 10 and ending with an ace /* This is the video poker game class It uses Decks and Card objects to implement video poker game Do not modify any data fields or defined methods You may add new data fields and methods Note: You must implement defined methods Show transcribed image text import java.util.*; Ref: Short Description and Poker rules Video poker is also known as draw poker. The dealer uses a 52-card deck, which is played fresh after each playerHand. The player is dealt one five-card poker playerHand After the first draw, which is automatic, you may hold any of the cards and draw k again to replace the cards that you haven ‘t chosen to hold k Your cards are compared to a table of winning combinations k The object is to get the best possible combination so that you earn the highest k payout on the bet you placed. k Winning Combination:s 1. Jacks or Better: a pair pays out only if the cards in the pair are Jacks Queens, Kings, or Aces. Lower pairs do not pay out. k 2. Two Pair: two sets of pairs of the same card denomination. k 3. Three of a Kind: three cards of the same denomination. 4. Straight: five consecutive denomination cards of different suit k 5. Flush: five non-consecutive denomination cards of the same suit. 6. Full House: a set of three cards of the same denomination plus a set of two cards of the same denomination 7. Four of a kind: four cards of the same denomination 8. Straight Flush: five consecutive denomination cards of the same suit 9. Royal Flush: five consecutive denomination cards of the same suit, starting from 10 and ending with an ace /* This is the video poker game class It uses Decks and Card objects to implement video poker game Do not modify any data fields or defined methods You may add new data fields and methods Note: You must implement defined methods

Expert Answer


Answer to Java. I really need help implementing the checkPlayerHand() and playGame() methods in the VideoPoker class! public class… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *