Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Specification: You are to write methods that will allow you to emulate a deck of cards to be used to play games of chance

Program Specification: You are to write methods that will allow you to emulate a deck of cards to be used to play games of chance

There is a deck of 36 cards:

Each card has value - a number in the range of [1, 9] printed on it - 9 possible values.

Each card has a suit - [Club, Spade, Heart, Diamond] printed on it - 4 possible suits.

Thus we will use the numbers from 0 to 35 (inclusive) to represent the cards.

Given a card ([0, 35]): the cards number is given by card % 9 + 1; the cards suit is given by card / 9, where 0 = Club, 1 = Spade, 2 = Heart, and 3 = Diamond.

The deck is cut by picking a random point to divide the deck, and then swapping the stack of cards below the cut point with the stack at and above the cut point.

The deck is shuffled by doing the following repeatedly: cut the deck, then divide the deck exactly in half

- creating two stacks, and finally recombining the two stacks back into one by selecting the top card from each stack (in alteration).

You must represent the deck of cards using an int Array of of size 36.

For each of the following headings / descriptions, write and use a method that adheres to it:

public static int cardValue(int card) Return the integer value ( [1, 9] ) of card

public static String cardSuit(int card) Return the suit ( [Club, Spade, Heart, Diamond] ) of card

public static void displayCard(int card) Prints card in some reasonable report format.

public static void initDeck(int[] deck) Assign the elements of deck, such that each elements value is the same as its index.

public static void cutDeck(int[] deck)

1. Generate a random number ( cut ) in the range 6 to 24 inclusive.

2. Create two new int arrays ( top, bottom ): the size of top being cut; the size of bottom being 36 - cut.

3. Copy the values of deck (from index 0 to index cut - 1) into top and the values of deck (from index cut to index 35) into bottom.

4. Copy the values from top and bottom back into deck, such that the the values of bottom (in the same order they were in) occupy the indicies from 0 to 36 - cut - 1, and the values of top (in the same order they were in) occupy the remaining indicies.

public static void shuffleDeck(int[] deck, int n) The following is performed exactly n times:

1. Cut the deck

2. Create two new int arrays ( top, bottom ), the size of each being 18

. 3. Copy the first half of deck into top and the second half of deck into bottom.

4. Copy the values from top and bottom back into deck such that: the even indecies of deck hold the values of top (in the same order they were in); the odd indecies of deck hold the values of bottom (in the same order they were in).

public static void displayDeck(int[] deck) Prints the cards in deck in some reasonable report format.

Write a main method to test your methods for correctness.

Notes and Hint

1. You will need to be creative when writing your main method to make sure that you have tested all of your methods adequate

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

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions

Question

2.3 Describe the requirements for reasonable accommodation.

Answered: 1 week ago

Question

4 How the market system adjusts to change and promotes progress.

Answered: 1 week ago