Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The Assignment This assignment is about using arrays. You will define two classes one to represent a playing card with a rank and a suit,
The Assignment
This assignment is about using arrays. You will define two classes one to
represent a playing card with a rank and a suit, and one to represent a deck
of cards these are the model classes Then you will repeatedly shuffle and
deal hands, and create a histogram of the results. The view class for this
assignment uses a main method and Standard Input and Output.
The Deck of Cards model
A Card object has a rank and a suit, both of which are positive, nonzero integers. The rank and suit are
specified when a Card is created and cannot be changed. A Card can report its rank and suit, and its
value. The value of a card is its rank multiplied by its suit. It has a toString method that reports its
rank and suit. Thats all it can do
A DeckOfCards object holds a set of Card objects in an array. The size of the deck is determined by
two integers passed to the constructor when it is created. The first integer specifies the maximum rank,
and the second specifies the number of suits. The deck then contains one card of each ranksuit
combination. So if there are suits and the maximum rank is there will be cards in the deck x
This constructor creates the Card objects and stores them in the array. A DeckOfCards can shuffle
itself which it does by randomly swapping pairs of cards in the array can report its size, the minimum
and maximum card value in the deck, and can deal the top n cards by placing them in an array and
returning them. It has a toString method that that reports the size of the deck, the minimum and
maximum values, and the top card. It also has a histogram method, described below. Thats all it can do
The Histogram Method
The histogram method of DeckOfCards accepts a
parameter that specifies the number of cards in a
hand. Then it shuffles and deals the cards
times by calling its own shuffle and deal methods.
For each deal, it adds up the total value of all the
cards in the hand and uses an array of counters to
record the number of times each total comes up For
example, if the sum of the values of the cards dealt is
you should add to array element Then it
returns the histogram array.
See HistogramExample.java in this weeks examples for some code that might help.
Design and Implementation
The exact details of the implementation and interface of these two classes is up to you, but you must
respect the specifications given above, and you must create and hand in a UML class diagram to
represent Card, DeckOfCards and the association relationship between the two classes. This UML
diagram can be hand drawn, or it you can use UMLet or draw.io If you have another piece of software
you would like to use, check with your instructor.
The Main Method View
The main method should start by asking the user to enter the number of suits and maximum rank. Then
it should create the deck of cards and print it to the screen. Then it should present a menu in a loop that
allows them to shuffle once, deal one hand, or shuffle and deal hands. They choose the size of
the hands dealt.
If they choose to deal a single hand, show the result by printing the cards they got. If choose
hands, call the histogram method described above, and print the nonzero elements of the array, as
shown in the example outpu
Example Output
Below is an example output of the program. User input is boldfaced and red. You are free to make your
interface look however you like.
How many suits?
How many ranks?
Deck of cards: low high top Card SR
shuffle, deal hand, deal times, quit:
Deck of cards: low high top Card SR
shuffle, deal hand, deal times, quit:
How many cards?
Card SR Card SR Card SR
Deck of cards: low high top Card SR
shuffle, deal hand, deal times, quit:
How many cards?
:
:
:
:
:
:
:
:
:
Deck of cards: low high top Card SR
shuffle, deal hand, deal times, quit:
BYE!
Optional Extra: Heres a nicer way to display the histogram, courtesy of Mark
Yendt. Scale the numbers down and print asterisks to represent the quantities.
:
:
:
:
:
:
:
: eck of cards: low high top Card SR
shuffle, deal hand, deal times, quit:
BY
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