Question
Submission should be: Card.java, Deck.java, Hand.java, Shuffling.java Part 1: Shuffling Assignment: In this assignment, you will create a program that shuffles cards and produces hands
Submission should be: Card.java, Deck.java, Hand.java, Shuffling.java
Part 1: Shuffling
Assignment: In this assignment, you will create a program that shuffles cards and produces hands given user specifications.
Requirements:
- Create a class to represent aCardobject. This class should include the following members:
a. private int rank; representing the rank of a card (face value A-K)
b. private int suit; representing the suit of a card (Clubs, hearts, spades, diamonds)
c. private String[] rankName; an array holding the face value of cards in order from lowest to highest ("A" for Ace to "K" for King)
d. private String[] suitName; an array holding the suit values of the cards ("C" for clubs, "H" for hearts, "S" for spades, "D" for diamonds)
e. public static final int constants: these variables will hold the integer value for the suits and ranks individually.
i. The ranges of values for the suits are from 0 (clubs) to 3 (diamonds), with the integer value corresponding to the suitName array declared previously.
ii. The ranges of values for the ranks are from 0 (Ace) to 12 (King), with the integer value corresponding to the rankName array declared previously.
iii. For example:
1.public static final int CLUBS=0; holds the integer value for the club suit
2.public static final int QUEEN=11; holds the integer value for the Queen rank
f. At least a 2-argument constructor that expects int rank and int suit as parameters
g. Getter methods for the first four private data fields (setter methods not required)
2. Create a class to represent a Deck of Cards. Be sure to include the following members:
a. private Card[] cards; an array of Card objects called cards -- what is the expected length of a deck of cards?
b. private int nextCard; a counter to keep track of cards as they are dealt
c. A no-argument constructor that initializes the cards array (where each element represents a separate Card object).
d. A method shuffle() that will randomly shuffle the cards in the deck.
i. Shuffle the cards by randomly choosing an index number (that is not zero) and swap the element at that index with the current element (starting at index 0). Swap however many times you like, but you should choose a minimum of 52 swaps to ensure a high probability that your deck is well-shuffled.
e. A method dealCard() that will return the next card in the deck
3. Create a class to represent the Hand of cards. Be sure to include the following:
a. private Card[] cards; an array of Card objects that represent the current hand
b. A 1-arg constructor that expects int size as a parameter. Within this method, declare the cards array to be of length size.
c. A method display()that will print out the individual cards in a hand
4. Create a class called Shuffling that will perform the following:
a. Create a 52-card deck and print it in order
b. Shuffle the deck and print the shuffled deck
c. Ask the user for a hand size, determine that hand and print it.
d. Continue to prompt the user for a hand size, until they choose to exit.
Note: The design of your main program (Shuffling.java) is totally up to you. But, be sure to include:
- Pre/post conditional comments.
- Methods if/when appropriate.
Sample output:
The deck in order: 2C 3C 4C 5C 6C 7C 8C 9C 10C JC QC KC AC 2H 3H 4H 5H 6H 7H 8H 9H 10H JH QH KH AH 2S 3S 4S 5S 6S 7S 8S 9S 10S JS QS KS AS 2D 3D 4D 5D 6D 7D 8D 9D 10D JD QD KD AD
The deck shuffled: 9S 3C 4H 5C 6C 7C 9H JS 2C 6S 8C 8D 9C 2H 3H KH 7H QS 4S 8H QC 10H JH AH 3D 7D 2S QH KC 6H 9D 7S 8S AC 10S JC 3S 4C AS 2D 10C 4D 5D 6D 5S KS 5H 10D JD QD KD AD
Please input a hand-size:
2.2
Incorrect type, please input a hand-size:
57
Too large of a hand, please input a hand-size:
5
Your hand: 10D JD QD KD AD
Please input a hand-size:
6
Your hand: 4D 5D 6D 5S KS 5H
Please input a hand-size:
Exit
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