Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 cards; /** Lowest ranking card (the ace). */ private static final int ACE = 1; /** Highest ranking card (the king). */ private static final int KING = 13; /** * Total number cards in the deck (4 suits, each with 13 cards of * different ranks). */ private static final int TOTAL_CARDS = 52; /** * Some constants that define the Strings for the various suits. */ private static final String HEARTS = "hearts"; private static final String DIAMONDS = "diamonds"; private static final String CLUBS = "clubs"; private static final String SPADES = "spades";

/** * Constructs a new, unshuffled deck containing 52 playing cards. */ public Deck() { cards = new ArrayList (); } /** * Creates the 13 cards for the specified suit, and adds them * to this deck. */ private void buildSuit(String suit) { } /** * Shuffles this deck of cards. */ public void shuffle() { } /** * Removes a card from this deck. */ public Card dealCard() { return null; } /** * Determines if this deck is empty. */ public boolean isEmpty() { return false; } /** * Returns the number of cards that are currently in the deck. */ public int size() { return -1; } }

import java.util.ArrayList;

public class Hand { /** * The cards are stored in a linked-list implementation of the * List collection. */ private ArrayList cards;

/** * 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

Develop successful mentoring programs. page 400

Answered: 1 week ago