Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class Deck. A Deck has the following private attribute: An array of Cards. The Deck class also contains the following public methods: A

Write a class Deck.

A Deck has the following private attribute:

An array of Cards. The Deck class also contains the following public methods:

A constructor that takes nothing as input and initializes the attribute with a Card[] of size 52.

The constructor should also initialize such array with all 52 possible cards. To get full marks you must use at least 1 loop to accomplish this (that is, you cannot write 52 total statements to assign all possible values). Hint: Create a String array of size 4 with the suit values, and then use nested for loops to initialize the cards. shuffle() which takes no input and returns no value. This method should shuffle the array of Cards of this Deck. To do so, do the following: create an object of type Random (remember that to use Random you should add the appro- priate import statement at the beginning of your file). To make your program easier to debug (and grade), you must provide a seed for the Random object. Use a seed equal to 123. Then create a loop that iterates 1000 times. Inside the loop, generate 2 random integers between 0 and 51 (both included) and swap the values at those positions in the array. (b) Page 8 For example, suppose the array of Cards of this Deck is the following: [AH, 2H, 3H, 4H, 5H, 6H, 7H, 8H, 9H, 10H, JH, QH, KH, AS, 2S, 3S, 4S, 5S, 6S, 7S, 8S, 9S, 10S, JS, QS, KS, AC, 2C, 3C, 4C, 5C, 6C, 7C, 8C, 9C, 10C, JC, QC, KC, AD, 2D, 3D, 4D, 5D, 6D, 7D, 8D, 9D, 10D, JD, QD, KD] Where the first symbol denotes the value of the card and the second the suit (C stands for clubs, H for hearts, D for diamonds, and S for spades). Then, after the method shuffle() is appropriately called on such Deck, the array of Cards will look as follows: [AD, 6D, AS, QH, 7H, 5D, 5S, KS, 9D, AH, 4D, 6H, 4H, 2H, 9S, 10D, JH, JD, KD, 8H, 3C, 7S, 10C, 8S, JC, 10H, QS, 4C, 3H, 9H, 7D, 8C, KH, JS, 3S, 7C, 6C, 3D, 9C, 6S, QC, 10S, 5H, 5C, 4S, 2D, KC, 8D, 2S, 2C, QD, AC] dealHand() which takes as input two integers. The first one, call it n, indicates how many cards should be dealt, the second one indicates the players number. The idea is that the first player should be dealt the first n cards in this Deck, the second player the next n cards, and so on. The method should return an array of Cards representing the hand dealt to the player. If there are not enough cards to deal (for instance we cannot deal a hand of 12 cards to a fifth player, since the first four players already took 48 cards, and only 4 cards are left in the deck), then the method should throw an IllegalArgumentException explaining that there are not enough cards in the deck.

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

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions

Question

2. What are Seventh Generations four sustainability goals?

Answered: 1 week ago