Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Cards: a . Define a class named Card with two fields, rank and suit, both of which are Strings. Include public accessor methods for these

Cards:
a. Define a class named Card with two fields, rank and suit, both of which are Strings. Include public accessor methods for these fields. Also define a method named toString() which returns a String rep- resenting a Card. For example, if the rank is "Jack" and the suit is "hearts", this method would return "Jack of hearts".
b.1. Define a class named Deck with at least one field, a List of Cards. The constructor should initialize the field to the 52 different cards
in a deck of playing cards. The suits are "spades", "hearts", "diamonds", "clubs". The ranks are "Two", "Three", ... "King", "Ace".
b.2. Define a method named getCard with one parameter, an int representing the position of a card in the deck. This method should remove the card at the given position from this deck, and return the removed card. For example:
/** Remove the Card at position ndx from this Deck.
* @return the removed Card
* @param ndx is not negative, and less than the size of this Deck. */
public Card getCard(int ndx)
b.3. Define a method which returns the size of this Deck (i.e. the number of cards currently in this Deck).
c. Define a class named Deal with at least one field storing a Deck. This class should have a method named dealHand(int n) which will return a List of n cards from its deck. Those cards should also be removed from the deck, in case dealHand is called more than once.
/** Deal a card hand.
* @return n cards from the deck.
* These cards are removed from the deck. */
public List dealHand (int n)
You can either just deal the cards in order or for a challenge, randomly deal the cards from the deck.
Help (optional):
To deal cards randomly from the deck, use a random number generator from java.util, Random:
Random rand = new Random();
Each time you call the nextInt(int n) method, it will return a random int in the range [0..n-1].
Test your program. Have the main program deal 4 hands with 7 cards in each hand. Print the hands to the screen. These should be no duplicate cards.
image text in transcribed

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

More Books

Students also viewed these Databases questions

Question

How accurately can managers plan for future human resources needs?

Answered: 1 week ago