Question: Main.java import java.util. * ; public class Main { private static String formatHandTypeName ( HandType type ) { return type.name ( ) . replaceAll (
Main.java
import java.util.;
public class Main
private static String formatHandTypeNameHandType type
return type.name
replaceAllazAZ$ $
replaceAllAZAZaz$ $
replaceOf Aof a;
public static void mainString args
Scanner scanner new ScannerSystemin;
System.out.printEnter the seed value : ;
int seed scanner.nextInt;
Deck deck new Deckseed;
System.out.println;
for int i ; i ; i
deck.shuffle; Updated to match the new shuffle signature
Hand hand deck.deal;
System.out.println hand;
System.out.printEnter the number of hands : ;
int numHands scanner.nextInt;
if numHands
System.out.println;
for HandType type : HandType.values
System.out.printfs fdn formatHandTypeNametype;
else
Map handTypeCounts new EnumMapHandTypeclass;
for HandType type : HandType.values
handTypeCounts.puttype;
for int i ; i numHands; i
deck.shuffle; Updated to match the new shuffle signature
Hand hand deck.deal;
HandType type hand.getHandType;
handTypeCounts.puttype handTypeCounts.gettype;
System.out.println;
for HandType type : HandType.values
int count handTypeCounts.gettype;
double percentage count numHands;
System.out.printfs fdn formatHandTypeNametype percentage, count;
scanner.close;
Card.java
public class Card implements Comparable
private final int rank;
private final int suit;
Constructor to initialize card with a value between and
public Cardint value
this.rank value ; A J Q K
this.suit value ; Spades Hearts Diamonds Clubs
Getter for suit
public int getSuit
return suit;
Getter for rank
public int getRank
return rank;
Override compareTo for sorting cards
@Override
public int compareToCard other
return this.rank other.rank this.rank other.rank : this.suit other.suit;
Convert card to string representation egAS for Ace of Spades
@Override
public String toString
String suits SHDC; Spades, Hearts, Diamonds, Clubs
String ranks AJQK;
return ranksrank suitssuit;
Deck.java
import java.util.Random;
import java.util.Arrays;
public class Deck
private Card cards;
private Random random;
private int currentIndex; Tracks the current position in the deck
public Deckint seed
this.random new Randomseed; Seeded random instance
initializeDeck;
private void initializeDeck
this.cards new Card;
for int i ; i ; i
cardsi new Cardi;
this.currentIndex ; Reset the index
public void shuffle
for int i cards.length ; i ; i
int j random.nextInti ; Deterministic random number
Card temp cardsi;
cardsi cardsj;
cardsj temp;
this.currentIndex ; Reset after shuffle
public void shuffleint numSwaps
for int i ; i numSwaps; i
int pos random.nextInt; Deterministic random indices
int pos random.nextInt;
Card temp cardspos;
cardspos cardspos;
cardspos temp;
this.currentIndex ; Reset after shuffle
public Hand deal
Reset and shuffle the deck if there aren't enough cards to deal
if currentIndex cards.length
initializeDeck;
shuffle;
Card dealtCards Arrays.copyOfRangecards currentIndex, currentIndex ;
currentIndex ; Move the index forward by
return new HanddealtCards;
import java.util.;
import java.util.stream.Collectors;
public class Hand
private final Card cards;
public HandCard cards
this.cards Arrays.copyOfcards cards.length;
Arrays.sortthiscards;
public Card getCards
return Arrays.copyOfcards cards.length;
public HandType getHandType
boolean isFlush Arrays.streamcardsmapCard::getSuitdistinctcount;
boolean isStraight Arrays.streamcardsmapCard::getRankdistinctcount&&
cardsgetRank cardsgetRank;
if isFlush && isStraight return HandType.StraightFlush;
if isFlu
public enum HandType
StraightFlush,
FourOfAKind,
FullHouse,
Flush,
Straight,
ThreeOfAKind,
TwoPair,
OnePair,
HighCard,
l
Output differs. See highlights below.
Expected output :Compare output
Output differs. See highlights below.
Expected output
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
