Question: Card.java public class Card { private char suit, kind; private boolean faceUp; // value will be taken from the index position in KINDS (plus 2)

 Card.java public class Card { private char suit, kind; private boolean

Card.java

public class Card { private char suit, kind; private boolean faceUp; // value will be taken from the index position in KINDS (plus 2) public static final char [] SUITS={'C','D','H','S'}; public static final String [] SUIT_NAMES={"clubs","diamonds","hearts","spades"}; public static final char [] KINDS={'2','3','4','5','6','7','8','9','T','J','Q','K','A'}; public static final String [] KIND_NAMES={"two","three","four","five","six","seven","eight","nine","ten","jack","queen","king","ace"}; public Card( ) { suit=SUITS[SUITS.length-1]; kind=KINDS[KINDS.length-1]; faceUp=false; } // no mutator methods needed, so data validation in non-default constructor only public Card( char s, char k ) { faceUp=false; int i=0; while (i

Deck.java

import java.util.Arrays; import java.util.Random; public class Deck { // instance attributes // array of Card Card[] deck; // count of cards private static int count =0; private Random randomNumbers; // default constructor // create (instantiate) 52 Card objects in the array of Card // iterate over Card.Suits array // nested iterate over Card.Kinds array // initial count of cards public Deck(){ deck = new Card[52]; for(int s=0; s

}

Question 1 - Deck class (12 points) Write a class to represent a standard deck of 52 cards. You are already provided with a Card class. See Card.java - A card is initially face down. You can only see the suit and kind of the card if it is face up. Comparisons between cards (both suit and kind) are provided. The values are 2-10 for face cards, Jack beats a 10, Queen beats a Jack, King beats a Queen, Ace beats a King. The classes using the Card class may need to know the range of valid suits and kinds. Note the public class constants in Card that should help you create a standard Deck, one of each suit and kind paring. Deck - Initially the standard 52 cards (facedown). These methods are required: - public Deck ( ) - default constructor makes a standard deck of 52 cards - public int getCount () - returns how many cards are currently in the deck - public void shuffle ( ) - randomly shuffle the cards in the deck - public Card deal () - remove the last card from the deck and return it (if exist), else return null - public String toString() - return a String with the number of cards currently in the deck, i.e. "deck with 37 cards" You should test each method using TestDeck.java. Because of randomness in the shuffle, we cannot automate testing of all methods. Sample output (cards drawn should be different every time): [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, falsel [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true] null deck with 52 cards card queen of diamonds deck with 51 cards

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!