Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Java Programming): Which game: card(1D array) Card: complete Cards.java Template: /* String lab: write a program that will pick four cards randomly from a deck

(Java Programming):

Which game: card(1D array) Card: complete Cards.java

Template:

/* String lab: write a program that will pick four cards randomly from a deck of 52 cards.

=========sample output=============

Card number 6: 7 of Spades

Card number 48: 10 of Clubs

Card number 16: Queen of Spades

Card number 24: Jack of Hearts

*/

public class Cards {

public static void main(String args[] ){

// use arrays to create array deck

int [] deck = new int[52];

// use arrays to create two string arrays with initial values

String[] suits ....

String[] ranks ....

//initialize the cards: use a for loop and deck.length

for ( ) {....}

//shuffle the cards: use a for loop, randomize the index and swap the values. why?

for ( ) {....}

// display the first four cards

for (int i=0; i<4; 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_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago