Question
Please fill in the 4 TODOs on CardDeck.java. Comment if you have any questions. Will rate! import java.util.Random; import java.util.Iterator; import javax.swing.ImageIcon; public class CardDeck
Please fill in the 4 TODOs on CardDeck.java. Comment if you have any questions. Will rate!
import java.util.Random;
import java.util.Iterator; 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("cards/" + suit + "_" + rank + "_RA.gif"); deck.add(new Card(rank, suit, image)); } deal = deck.iterator(); }
public void shuffle() { 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--) { // TODO generate a random integer between 0 and i - 1 and assign it to the randLoc variable (one statement is missing)
temp = deck.get(randLoc);
deck.set(randLoc, deck.get(i)); deck.set(i, temp); } // TODO re-assign the deal variable to be the iterator of the deck array (one statement is missing) } public boolean hasNextCard() // Returns true if there are still cards left to be dealt; // otherwise, returns false. { // TODO Returns the result of test if the card iterator variable deal still has cards left to be dealt (one statement is missing) } public Card nextCard(){ //TODO Returns the next card from the current card iterator variable deal. (one statement is missing) } }
//----------------------------------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started