Trying Implement Method Report Number Cards Deck Card Dealt Code Currently Cardsindeck Rea Q10085599

I am trying to implement a method to report the number of cardsin a deck after each card is dealt, here is my code. Currently thecardsInDeck is not being reached and I need to call the method inthe driver also. Any help is appreciated!! Thanks.

//DECK OF CARDS

import java.util.Random;

public class DeckOfCards
{

private Card[] deck; //Array to store Card class objects
private int currentCard; //Current card
private static final int NUMBER_OF_CARDS = 52; //Number of cards inthe decks
private int cardsInDeck = 52; //Number of cards in the deck at anygiven time
private static final Random randomNumbers = new Random();//Random

/** Creates a new instance of DeckOfCards */
public DeckOfCards()
{
deck = new Card[NUMBER_OF_CARDS];
currentCard = 0;

//fills deck with Card class objects
//which has suit and face enumerations
int count = 0;   
for(Card.Suit suit : Card.Suit.values())
{   
for(Card.Face face : Card.Face.values())
{
deck[count] = new Card(face,suit);
count++;
}
}
}

//Shuffles cards in the deck
public void shuffle()
{
currentCard = 0;
for(int first = 0; first < deck.length; first++)
{
int second = randomNumbers.nextInt(NUMBER_OF_CARDS);  
Card temp = deck[first];
deck[first] = deck[second];
deck[second] = temp;
}   
}

//Deal one card
public Card dealCard()
{
if(currentCard < deck.length)
{
return deck[currentCard++];
cardsInDeck–;
}   
else
return null;   
}
  
//Report the number of cards in the deck at any given time
public int numberOfCards()
{
System.out.println(cardsInDeck);
}
}

//CARD

public class Card
{
//Faces
public enum Face {Ace, Two, Three, Four, Five, Six, Seven, Eight,Nine, Ten, Jack, Queen, King};

//Suits
public enum Suit {Hearts, Diamonds, Clubs, Spades};

private Face face;
private Suit suit;

//Constructor
public Card(Face cardFace, Suit cardSuit){
face = cardFace;
suit = cardSuit;
}   

public String toString(){
return face + ” of ” + suit;
}   
}

//DRIVER

public class DeckOfCardsTest
{
public static void main(String []args)
{
//DeckOfCards object
DeckOfCards myDeckOfCards = new DeckOfCards();
myDeckOfCards.shuffle();

//Deal and display a card
for(int i = 1; i <= 52; i++)
{
System.out.printf(“%-20s”,myDeckOfCards.dealCard());

if( i % 4 == 0) //New line every 4 cards
{
System.out.println();
}
}
}
}

“We Offer Paper Writing Services on all Disciplines, Make an Order Now and we will be Glad to Help”

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published.