Menu

T Figure Code Wont Compile Work Public Class Deckofcards Private Card Deckofcards Represen Q43815020

I can’t figure out why this code wont compile and work

public class DeckOfCards {
private Card[] deckOfCards; // Represents the deck
//Variable Declaration
private int dealtCards;
private int remainingCards;

// No-arg/Default constructor
public DeckOfCards() {
deckOfCards = new Card[52]; // 52 card deck
dealtCards = 0;
remainingCards = 42;
int count =0;
int i,j;
// Nested for loops
for (i=1;i<=4;i++) {
for (j=1;j<=13;j++) {
deckOfCards[count++] = new Card(i,j);
}
}
}
public void shuffle() {
Random randNum = new Random();
deckOfCards = new Card[52];
int count =0;
while (count<=51) {
int suit = randNum.nextInt(4)+1; // 1 to 4
int face = randNum.nextInt(13)+1; // 1 to 13
boolean result = false;
for (int i =0; i<count; i++) {
if (suit== deckOfCards[i].getFace()) {
result = true;
}
}
if (result== false) {
deckOfCards[count] = new Card(suit,face);
count++;
}
}
}
public void outputDeck() {
for (int i =0; i< deckOfCards.length;i++) {
System.out.println(“Card “+(i+1)+” Suit =”+deckOfCards[i].getSuit()+ “Face = “+deckOfCards[i].getFace());

}
}
// Method below for dealing cards
public Card receiveCard() {
dealtCards++;
remainingCards–;
return (deckOfCards[0]);
}
// Cards that have been dealt with
public int getCardsDealt() {
return dealtCards;
}
// Cards that are remaining
public int getCardsLeft() {
return remainingCards;
}
}

Created a Card class that represents a standard playingcard. Use this to design and implement a class called DeckOfCardsthat stores 52 objects of the Card class. Include methods toshuffle the deck, deal a card, and report the number of cards leftin the deck, and a toString to show the contents of the deck. Theshuffle methods should assume a full deck. Document your designwith a UML Class diagram. Create a separate driver class that firstoutputs the populated deck to prove it is complete, shuffles thedeck, and then deals each card from a shuffled deck, displayingeach card as it is dealt.

Hint: The constructor for DeckOfCards should have nestedfor loops for the face values (1 to 13) within the suit values (1to 4). The shuffle method does not have to simulate how a deck isphysically shuffled; you can achieve the same effect by repeatedlyswapping pairs of cards chosen at random.

Testing: Include two complete runs to demonstrate therandom effect of shuffling.

That is the requirements for functionality andtesting

Expert Answer


Answer to I can’t figure out why this code wont compile and work public class DeckOfCards { private Card[] deckOfCards; // Represe…

OR