Question: (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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!