Program specification you are to write methods that will


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 card's number is given by card % 9 + 1; the card's 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 element's 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

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

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Program specification you are to write methods that will
Reference No:- TGS02900756

Expected delivery within 24 Hours