Question: I need some help finishing this java code. import java.util.Random; public class Deck { private final int DECK_SIZE = 52; private Card[] deck; // Top
I need some help finishing this java code.
import java.util.Random;
public class Deck
{
private final int DECK_SIZE = 52;
private Card[] deck;
// Top of the deck is index 0; bottom is index 51.
private int currentTop;
//
// Allocates a default deck of 52 cards with four suits.
//
public Deck()
{
deck = new Card[DECK_SIZE];
currentTop = 0;
int index = 0;
for (Card.SuitT suit : Card.SuitT.values())
{
for (Card.FaceT face : Card.FaceT.values())
{
deck[index++] = new Card(suit, face);
}
}
}
//
// May assume a full deck.
//
// Shuffles by switching two random cards in the deck many times.
//
public void shuffle()
{
Random rng = new Random();
final int ITERATIONS = 1000;
for (int count = 0; count < ITERATIONS; count++)
{
// TODO
}
}
//
// Computes the number of cards that remain in the deck:
// deck count minus the current top index
//
public int cardsRemaining()
{
// TODO
return DECK_SIZE;
}
//
// Returns the top card from the deck.
//
public Card deal() throws DeckException
{
// TODO
return null;
}
//
// Returns the top card from the deck.
//
public Card[] deal(int numCards) throws DeckException
{
// TODO
return deck;
}
//
// Builds and returns a meaningful representation of the cards that
// remain in the deck.
//
public String toString()
{
String retStr = "";
// TODO
return retStr;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
