Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is the main question followed by classes that must be filled out. In this a

ID: 3805831 • Letter: T

Question

This is the main question followed by classes that must be filled out.

In this assignment, you will implement a simulation of a popular casino game usually called video poker. The card deck contains 52 cards, 13 of each suit. At the beginning of the game, the deck is shuffled.

You need to devise a fair method for shuffling. (It does not have to be efficient.)

The player pays a token for each game.

Then the top five cards of the deck are presented to the player.

The player can reject none, some, or all the cards.

The rejected cards are replaced from the top of the deck.

Now the hand is scored. Your program should pronounce it to be one of the following:

• No pair—The lowest hand, containing five separate cards that do not match up to create any of the hands below.

• One pair—Two cards of the same value, for example two queens. Payout: 1

• Two pairs—Two pairs, for example two queens and two 5’s. Payout: 2

• Three of a kind—Three cards of the same value, for example three queens. Payout: 3

• Straight—Five cards with consecutive values, not necessarily of the same suit, such as 4, 5, 6, 7, and 8. The ace can either precede a 2 or follow a king. Payout: 4

• Flush—Five cards, not necessarily in order, of the same suit. Payout: 5

• Full House—Three of a kind and a pair, for example three queens and two 5’s. Payout: 6
• Four of a Kind—Four cards of the same value, such as four queens. Payout: 25

• Straight Flush—A straight and a flush: Five cards with consecutive values of the same suit. Payout: 50

• Royal Flush—The best possible hand in poker. A 10, jack, queen, king, and ace, all of the same suit. Payout: 250

card class

// add your own banner here

public class Card implements Comparable<Card>{

  

   private int suit; // use integers 1-4 to encode the suit

   private int rank; // use integers 1-13 to encode the rank

  

   public Card(int s, int r){

       //make a card with suit s and value v

   }

  

   public int compareTo(Card c){

       // use this method to compare cards so they

       // may be easily sorted

   }

  

   public String toString(){

       // use this method to easily print a Card object

   }

   // add some more methods here if needed

}

deck class

// add your own banner here

public class Deck {

  

   private Card[] cards;

   private int top; // the index of the top of the deck

   // add more instance variables if needed

  

   public Deck(){

       // make a 52 card deck here

   }

  

   public void shuffle(){

       // shuffle the deck here

   }

  

   public Card deal(){

       // deal the top card in the deck

   }

  

   // add more methods here if needed

}

game class

// add your own banner here

public class Game {

  

   private Player p;

   private Deck cards;

   // you'll probably need some more here

  

  

   public Game(String[] testHand){

       // This constructor is to help test your code

       // use the contents of testHand to

       // make a hand for the player

       // use the following encoding for cards

       // c = clubs

       // d = diamonds

       // h = hearts

       // s = spades

       // 1-13 correspond to ace - king

       // example: s1 = ace of spades

       // example: testhand = {s1, s13, s12, s11, s10} = royal flush

      

      

   }

  

   public Game(){

       // This no-argument constructor is to actually play a normal game

      

   }

  

   public void play(){

       // this method should play the game  

   }

  

   public String checkHand(ArrayList<Card> hand){

       // this method should take an ArrayList of cards

       // as input and then determine what evaluates to and

       // return that as a String

      

   }

  

  

   // you will likely want many more methods here

   // per discussion in class

}

player class

// add your own banner here

public class Player {

  

      

   private ArrayList<Card> hand; // the player's cards

   private double bankroll;

private double bet;

   // you may choose to use more instance variables

      

   public Player(){      

      // create a player here

   }

   public void addCard(Card c){

      // add the card c to the player's hand

   }

   public void removeCard(Card c){

      // remove the card c from the player's hand

}

      

public void bets(double amt){

// player makes a bet

}

public void winnings(double odds){

//   adjust bankroll if player wins

}

public double getBankroll(){

// return current balance of bankroll

}

// you may wish to use more methods here

}

Explanation / Answer

public class Card
{
private short rank, suit;

private static String[] suits = { "hearts", "spades", "diamonds", "clubs" };
private static String[] ranks = { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };

public static String rankAsString( int __rank ) {
return ranks[__rank];
}

Card(short suit, short rank)
{
this.rank=rank;
this.suit=suit;
}

public @Override String toString()
{
return ranks[rank] + " of " + suits[suit];
}

public short getRank() {
return rank;
}

public short getSuit() {
return suit;
}

public boolean sameSuit(Card card) {
// TODO Auto-generated method stub
return false;
}
}


Here is my Deck class: package javapoker;
import java.util.ArrayList;
import java.util.Random;
public class Deck {
private ArrayList<Card> cards;

Deck()
{
cards = new ArrayList<Card>();
int index_1, index_2;
Random generator = new Random();
Card temp;

for (short a=0; a<=3; a++)
{
for (short b=0; b<=12; b++)
{
cards.add( new Card(a,b) );
}
}

int size = cards.size() -1;

for (short i=0; i<100; i++)
{
index_1 = generator.nextInt( size );
index_2 = generator.nextInt( size );

temp = (Card) cards.get( index_2 );
cards.set( index_2 , cards.get( index_1 ) );
cards.set( index_1, temp );
}
}

public Card drawFromDeck()
{
return cards.remove( cards.size()-1 );
}

public int getTotalCards()
{
return cards.size();
//we could use this method when making
//a complete poker game to see if we needed a new deck
}
}

Here is my Player class (it is very flawed, feel free to trash it and start over): package javapoker;
import java.util.Random;
public class Player
{
private static final int random = 0;
public static void main(String[] args)
{
Card [] hand = new Card [5];
hand[0] = new //I know variables go here but I'm trying and
//failing to match them to the random card suits and ranks
hand[1] = new
hand[2] = new
hand[3] = new
hand[4] = new

System.out.println("The hand dealt is: ");
for (int i = 0; i < hand.length; i++)
System.out.println(hand[i]);


if (flush(hand))
System.out.print("Your hand is a flush");
else if (threeKind(hand) && twoKind(hand))
System.out.print("Your hand is a full house");
else if (fourKind(hand))
System.out.print("Your hand is a four of a kind");
else if (threeKind(hand))
System.out.print("Your hand is a three of a kind");
else if (twoKind(hand))
System.out.print("Your hand is a two of a kind");
else if (straight(hand))
System.out.println("You've got a straight hand");
else if (straightFlush(hand))
System.out.println("You've got a straight flush");
else
System.out.print("Trade them all in");

System.out.println();
System.out.print("Thanks for playing");
}
public static boolean flush(Card [] hand)
{
boolean isFlush = true;
Card firstOne = new Card(hand[0].getSuit(), hand[0].face());
//I think I need to define method-Face for the Card class to get rid of these errors
for (int i = 1; isFlush && i < hand.length; i++)
if (!firstOne.sameSuit(hand[i]))
isFlush = false;

return isFlush;
}
public static boolean fullHouse(Card [] hand)
{
System.out.println("in full house");
return (threeKind(hand) && twoKind(hand));
}
public static boolean fourKind(Card [] hand)
{
int count = 0;

for (int i = 0; count < 3 && i < hand.length; i++)
{
count = 0;

for (int j = i + 1; j < hand.length; j++)
if (hand[i].sameFace(hand[j]))
count++;
}
return (count == 3);
}
public static boolean threeKind(Card [] hand)
{
int count = 0;

for (int i = 0; count < 2 && i < hand.length; i++)
{
count = 0;

for (int j = i + 1; j < hand.length; j++)
if (hand[i].sameFace(hand[j]))
count++;
}
return (count == 2);
}
public static boolean twoKind(Card [] hand)
{
int count = 0;

for (int i = 0; count < 1 && i < hand.length; i++)
{
count = 0;

for (int j = i +1; j < hand.length; j++)
if (hand[i].sameFace(hand[j]))
count ++;
}
return (count == 1);
}
public static boolean straight(Card [] hand)
{
boolean isStraight = true;
Card firstOne = new Card(hand[0].getSuit(), hand[0].face());

for (int i = 1; isStraight && i < hand.length; i++)
if (!firstOne.sameFace(hand[i]))
isStraight = false;

return isStraight;
}
public static boolean straightFlush(Card [] hand)
{
System.out.println("in straight flush");
return (straight(hand) && flush(hand));
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote