Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*Must FIRST print un shuffled deck* then deal each card from a shuffled eck IN J

ID: 2247414 • Letter: #

Question

*Must FIRST print un shuffled deck* then deal each card from a shuffled eck

IN JAVA

Create a class called DeckOfCards that stores 52 objects of the Card class. Include methods to shuffle the deck, deal a card, and report the number of cards left in the deck. The shuffle methods should assume a full deck. Create a driver class with a main method that deals each card from a shuffled deck, printing each card as it is dealt.Hints: The constructor for DeckOfCards should have nested for loops for the face values (1 to 13) within the suit values (1 to 4).

Your main method should print the un-shuffled deck first to ensure you have a full deck, then the shuffled deck.

Explanation / Answer

DeckOfCards.java

class DeckOfCards {
public static final int NEWCARDS = 52;
private Card[] cardDeck;   
private int currCards;

public DeckOfCards( ) {
cardDeck = new Card[NEWCARDS];
int uu = 0;

for ( int suites = Card.DIAMOND; suites <= Card.SPADE; suites++ )
for ( int ranki = 1; ranki <= 13; ranki++ )
cardDeck[uu++] = new Card(suites, ranki);
currCards = 0;
}


public void shuff(int no) {
int uu, qq, io;
for ( io = 0; io < no; io++ ) {
uu = (int) ( NEWCARDS * Math.random() );
qq = (int) ( NEWCARDS * Math.random() );

Card tempo = cardDeck[uu];
cardDeck[uu] = cardDeck[qq];
cardDeck[qq] = tempo;
}
currCards = 0;   
}
}

Card.java

class Card {
public static final int SPADES = 4;
public static final int HEARTS = 3;
public static final int CLUBS = 2;
public static final int DIAMONDS = 1;

private int rnk;
private int suit;
private static final String[] SUite = {"Hearts", "Clubs", "Spades", "Diamonds"};
private static final String[] Rankings = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};   

private int crdSuit;
private int crdRnk;

public Card(int suit, int rnk) {
if (rnk == 1)
crdRnk = 14;   
else
crdRnk = (int) rnk;
crdSuit = (int) suit;
}

public int suit() {
return this.crdSuit;   
}

public String suitStrings() {
return(this.SUite[ this.crdSuit ]);
}

public int rnk() {
return this.crdRnk;
}

public String rankStrings() {
return ( Rankings[ crdRnk ] );
}


public String toString() {
return ( Rankings[ crdRnk ] + SUite[ crdSuit ] );
}
}

Rate an upvote........Thankyou

Hope this helps......