Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I n JAVA Language: ADT Lists These applications should create random five card poker hands using the CardDeck class. You may find that sorting the

In JAVA Language: ADT Lists

These applications should create random five card poker hands using the CardDeck class. You may find that sorting the hand in various ways aids in the determination of the hand rank.

PokerValue should generate a single five-card poker hand and output the best rank associated with the handis it a three of a kind or a straight flush, and so forth? Hand ranks are listed from best to worst on page 370.

PokerOdds should generate 10 million five-card poker hands and output the relative percentage of times each of the card ranks listed on page 370 occurs. Each hand contributes only to the count of its highest possible rank. Do some research and compare your result to the known probabilities for poker hands.

Implement a graphical user interfacebased version of the In-Between game

//---------------------------------------------------------------------- // Card.java by Dale/Joyce/Weems Chapter 6 // // Supports playing card objects having a suit, a rank, and an image. // Only rank is used when comparing cards. Ace is "high". //---------------------------------------------------------------------- //package support.cards; //import java.util.CardDeck; import javax.swing.ImageIcon;

public class Card implements Comparable { public enum Rank {Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace}

public enum Suit {Club, Diamond, Heart, Spade}

protected final Rank rank; protected final Suit suit; protected ImageIcon image;

Card(Rank rank, Suit suit, ImageIcon image) { this.rank = rank; this.suit = suit; this.image = image; }

public Rank getRank() { return rank; } public Suit getSuit() { return suit; } public ImageIcon getImage() {return image;}

@Override public boolean equals(Object obj)

// Returns true if 'obj' is a Card with same rank // as this Card, otherwise returns false. { if (obj == this) return true; else if (obj == null || obj.getClass() != this.getClass()) return false; else { Card c = (Card) obj; return (this.rank == c.rank); } }

public int compareTo(Card other) // Compares this Card with 'other' for order. Returns a // negative integer, zero, or a positive integer as this object // is less than, equal to, or greater than 'other'. { return this.rank.compareTo(other.rank); }

@Override public String toString() { return suit + " " + rank; }

}

//----------------------------------------------------------------------

// CardDeck.java by Dale/Joyce/Weems Chapter 6

//

// Models a deck of cards. Includes shuffling and dealing.

//----------------------------------------------------------------------

//package support.cards;

import java.util.Random;

//import java.util.Card;

//import ch06.lists.ABList;

import javax.swing.ImageIcon;

public class CardDeck

{

public static final int NUMCARDS = 52;

protected ABList deck;

protected Iterator deal;

public CardDeck()

{

deck = new ABList(NUMCARDS);

ImageIcon image;

for (Card.Suit suit : Card.Suit.values())

for (Card.Rank rank : Card.Rank.values())

{

image = new ImageIcon("support/cards/" + suit + "_" + rank

+ "_RA.gif");

deck.add(new Card(rank, suit, image));

}

deal = deck.iterator();

}

public void shuffle()

// Randomizes the order of the cards in the deck.

// Resets the current deal.

{

Random rand = new Random(); // to generate random numbers

int randLoc; // random location in card deck

Card temp; // for swap of cards

for (int i = (NUMCARDS - 1); i > 0; i--)

{

randLoc = rand.nextInt(i); // random integer between 0 and i - 1

temp = deck.get(randLoc);

deck.set(randLoc, deck.get(i));

deck.set(i, temp);

}

deal = deck.iterator();

}

public boolean hasNextCard()

// Returns true if there are still cards left to be dealt;

// otherwise, returns false.

{

return (deal.hasNext());

}

public Card nextCard()

// Precondition: this.hasNextCard() == true

//

// Returns the next card for the current 'deal'.

{

return deal.next();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Multimedia Database Systems

Authors: V.S. Subrahmanian

1st Edition

1558604669, 978-1558604667

More Books

Students also viewed these Databases questions