Answered step by step
Verified Expert Solution
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 Define a class named Deck with at least one field, a List of Cards. The constructor should initialize the field to the different cards
in a deck of playing cards. The suits are "spades", "hearts", "diamonds", "clubs". The ranks are "Two", "Three", "King", "Ace".
b 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 getCardint ndx
b Define a method which returns the size of this Deck ie 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 dealHandint 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 nextIntint n method, it will return a random int in the range n
Test your program. Have the main program deal hands with cards in each hand. Print the hands to the screen. These should be no duplicate cards.
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