Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am postin this for 3rd time I need 3 classes for this java code as given in pictures card class deck class deck test
I am postin this for 3rd time I need 3 classes for this java code as given in pictures
Part B: A Deck of Cards A standard deck of playing cards includes 52 cards - 13 each in clubs, diamonds, spades, and hearts. The 13 cards in each suit are the Ace, 2 through 10, Jack, Queen, and King. Write a Card class that represents a single playing card. This class has two instance variables: - face - An int value 0-12 (This works better with arrays than 1-13) 0 represents the Ace 1 represents 2 2 represents 3 10 represents the Jack 11 represents the Queen 12 represents the King - suit-An int value 0-3 - clubs, diamonds, spades, hearts in that order Include a standard constructor, as well as getFace() and getSuit() methods that return the int values held in the instance variables. The toString() method for the Card class works differently from how we normally define this method. Simply return a short representation of the card, for example: - "Ah" for the ace of hearts - " 3d " for the three of diamonds - "10c" for the 10 of clubs - "Qs" for the queen of spades As you can see, the String value returned from toString() is always 2 or 3 characters in length. Hint: This toString() method becomes super easy to write if you include two arrays in your Card class: - private static final String[] SUITLETTER = {"c,"d","s ", "h" }; - Plus a similar array called FACELETTER with 13 short strings. Do you remember what the word 'static' means in that context? It means that each individual Card object does not require its own copy of SUITLETTER. It's enough to have one copy of that array that is shared between any Card objects you happen to create. Also write a Deck class. The Deck class has two instance variables: - An array of 52 Card objects - currentCard - An int value. When this number is in the range 0-51, it represents the position of the next card to be dealt from the deck. Once all 52 cards have been dealt, this number becomes 52 , thereafter indicating that there are no more cards to deal (at least until the deck is shuffled again). The Deck constructor has no parameter. It loops to create all 52 Cards in a standard deck and inserts them into the array in the order of Ace-to-King, of clubs, diamonds, spades, hearts, in that order. Thus the order is Ac, 2c, 3c all the way to Qh,Kh. In terms of the (face, suit) values for the Cards, that's the same as (0,0),(1,0),(2,0) all the way to (11,3),(12,3). It's those face and suit int values you need to generate to create the Card objects, since that is what the Card constructor accepts as parameters. The Deck class includes the following methods: - shuffle () - reorders the cards within the Deck and resets currentCard to zero. Use the following algorithm for shuffling your deck: for each Card in the deck, swap this card with a card in a randomly selected position. This means you only have to loop through the cards once to shuffle the deck. - dealCard - If currentCard is less than the number of cards, return the Card object in the position indicated by currentCard, and increase currentCard by one. Otherwise return null. Note that "dealing" a card doesn't remove it from the Deck - the only change is to update currentCard to a new position. - toString() - Concatenates together the toString() results for every card in the deck. Insert two spaces between each card. Insert a newline character after the 13th,26th, an 39th card, so that printing the result shows up as four lines of thirteen cards. You can see a few examples in the sample output shown on the next page. Also write a DeckTest class to try out your Card and Deck classes. This test class should: 1. Create a Deck and display it (using toString) in its original, unshuffled state. 2. Shuffle the deck and display it again. 3. Show the cards retumed by dealing the first five cards from the deck. (You can visually compare with the shuffled deck display to ensure your dealCard() method is working properly.) 4. Loop to deal the rest of the cards in the deck, except for the very last card, but with no output. 5. Deal the last card and print it so you can confirm you are getting the last card in the shuffled deck. 6. Use an if-else statement to test one more call to dealCard(). Confirm whether or not you get back the appropriate result, and display an appropriate message either way 7. Shuffle the deck and display it again. 8. Deal 5 more cards and display them, which allows you to confirm that the shuffle reset the value of currentCard appropriately. See the next page for sample output from my version of DeckTest. The order of the cards in your output should differ, of course, since each shuffle is random. Your output from Decktest should resemble the following card class
deck class
deck test class
and the output is also given
thanks :)
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