Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to add a shuffle() constructor which randomizes the deck, and returns no value. I also need to add a dealOneCard() constructor - which

I need to add a shuffle() constructor which randomizes the deck, and returns no value.

I also need to add a dealOneCard() constructor - which returns one card from the deck to the user(returns one card at a time). Specifically, a call to shuffle() followed by 52 calls to dealOneCard() should result in the user being provided all 52 cards of the deck in a random order. If the caller then makes a 53rd call dealOneCard(), no card is dealt.

Probaly needs to be another class as well.

public class Cards {

public static void main(String[] args)

{

int[] deck = new int[52];

String[] suits = { "Spades", "Hearts", "Diamonds", "Clubs" };

String[] ranks = { "2", "3", "4", "5", "6", "7", "8", "9", "10","Ace", "Jack", "Queen", "King" };

for (int i = 0; i < deck.length; i++)

deck[i] = i;

for (int i = 0; i < deck.length; i++)

{

int shuffle = (int) (Math.random() * deck.length);

int temp = deck[i];

deck[i] = deck[shuffle];

deck[shuffle] = temp;

}

for (int i = 0; i < 52; i++)

{

String suit = suits[deck[i] / 13];

String rank = ranks[deck[i] % 13];

System.out.println("card number " + deck[i]+": "+rank + " of " + suit);

}

}

}

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

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

Students also viewed these Databases questions

Question

What are the different types of short sales?

Answered: 1 week ago