Question
Having trouble for class Deck and Hand, please help me complete this code 1.Write constructor Deck(), buildSuit(), isEmpty() and size(). Don't forget the javadoc comments
Having trouble for class Deck and Hand, please help me complete this code
1.Write constructor Deck(), buildSuit(), isEmpty() and size(). Don't forget the javadoc comments (@param, @return). The constructor must call private method buildSuit() four times (once for each suit). Each time buildSuit() is called, 13 new cards will be added to the deck. The constructor does not shuffle the deck of cards.
2.Write dealCard(). dealCard() should always remove and return the card at the front of the deck, i.e. the first card in the ArrayList. It should not randomly pick the card it will remove.Don't forget the javadoc comments (@param, @return).
3.Write shuffle(). The method should create one instance of java.util.Random() and repeatedly (at least 10,000 times) invoke nextInt(int n) to generate the positions of two cards in the deck to interchange. Don't forget the javadoc comments (@param, @return).
4.Open the incomplete implementation of Hand in the BlueJ editor and read the documentation for the constructor and methods. Complete the implementation of the class, including the javadoc comments. As you write each method, run the tests in HandTest to provide you with feedback. Notes: a. The class must not define any additional fields - the fields called cards is sufficient. Of course, your methods may need to define one or more local variables. b. Most of the methods in Hand will be very short; for the most part, they will simply call the appropriate method on the hand's ArrayList object. c. Notice that the String returned by toString() should have a single space between each number (card rank), and should have no leading or trailing spaces.
public class Card { /** The card's suit: "hearts", "diamonds", "clubs", "spades". */ private String suit; /** * The card's rank, between 1 and 13 (1 represents the ace, 11 represents * the jack, 12 represents the queen, and 13 represents the king.) */ private int rank;
/** * Constructs a new card with the specified suit and rank. */ public Card(String suit, int rank) { this.rank = rank; this.suit = suit; } /** * Returns this card's suit. */ public String suit() { return suit; } /** * Returns this card's rank. */ public int rank() { return rank; } /** * Determines if this card has the same rank as the specified card. */ public boolean hasSameRank(Card aCard) { return (this.rank() == aCard.rank()); } /** * Determines if this card is equal to the specified card. */ public boolean isEqualTo(Card aCard) { return (this.suit().equals(aCard.suit())); } }
import java.util.ArrayList; import java.util.Random;
public class Deck { /** * The cards are stored in a linked-list implementation of the * List collection. */ private ArrayList
/** * Constructs a new, unshuffled deck containing 52 playing cards. */ public Deck() { cards = new ArrayList
import java.util.ArrayList;
public class Hand { /** * The cards are stored in a linked-list implementation of the * List collection. */ private ArrayList
/** * Constructs a new, empty hand. */ public Hand() { } /** * Adds the specified card to this hand. */ public void addCard(Card aCard) { } /** * Removes a card from this hand. Cards are removed in the order in * which they were added to the hand. */ public Card playCard() { return null; }
/** * Returns the number of cards that are currently in this hand. */ public int size() { return -1; }
/** * Determines if this hand is empty. */ public boolean isEmpty() { return false; }
/** * Returns a String that lists the ranks (but not the suits) of all the * cards in this hand, starting with the first card and finishing with * the last card. For example, if the first card is the two of hearts, * the second card is the five of diamonds, and the last card is the * queen of clubs, the String returned by this method will be: "2 5 12". */ public String toString() { return ""; } }
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