Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93094770

Have any Question?


Related Questions in Computer Engineering

Relational algebrawrite a relational algebra expression

[Relational Algebra] Write a relational algebra expression that will output first name and last name of computer science major male students who have borrowed books from "University of Iowa Main Library". Relational Sche ...

Question suppose that an attack would do 200000 in damage

Question : Suppose that an attack would do $200,000 in damage and has a 25% annual probability of success. Spending $15,000 per year on Countermeasure A would reduce the damage of a successful attack by 50%. a) Do a risk ...

What is the purpose of exclusive gates such as the xor and

What is the purpose of exclusive gates such as the XOR and XNOR? What function do these gates perform?

Cullumber corp issued a four-year bond one year ago with a

Cullumber Corp. issued a four-year bond one year ago with a coupon rate of 6.0 percent. The bond pays interest semiannually. If the yield to maturity on this bond is 9 percent, what is the price of the bond? (Round answe ...

Question what would be the impact of predictive modeling on

Question: What would be the impact of predictive modeling on healthcare and medicine? Can predictive modeling replace managerial or medical personnel? 500 word The response must be typed, single spaced, must be in times ...

Stack - java plz use simple java language netbeans 81 or

STACK - java, plz use simple java language, netbeans 8.1 or 8.2 1. Create a Stack class based on MyLinkedList class. Use this class in the following: 2. Create a new Java Application that has the following methods: 1. A ...

Question state the dilemma the score as he puts it harnish

Question : State the dilemma ("the score", as he puts it) Harnish finds between the Humean view and the Frege-Russell view of representation. Do you think a computational theory of mind is a viable alternative to these v ...

Sutures sutures are strands or fibers used to sew living

Sutures: Sutures are strands or fibers used to sew living tissue together after an injury or an operation. Packages of sutures must be sealed carefully before they are shipped to hospitals to prevent contamination. The p ...

When a developer creates an app should they make it

When a developer creates an app, should they make it backwards compatible, so that the app can be handled by older versions of the operating system? Why or why not?

Question in ruby as in java 8 or scala an interface mix-in

Question : In Ruby, as in Java 8 or Scala, an interface (mix-in) can provide method code as well as signatures. (It can't provide data members; that would be multiple inheritance.) Explain why dynamic typing makes this f ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As