The task is to create a program that will randomly select four cards from a deck of 52 cards. All the cards can be represented using an array named deck, filled with initial values 0 to 51, as follows:Card numbers 0–12, 13–25, 26–38, and 39–51 represent 13 Spades, 13 Hearts, 13 Diamonds, and 13 Clubs, respectively, as shown in Figure 1. cardNumber / 13 determines the suit of the card, and cardNumber % 13 determines the rank of the card, as shown in Figure 2. After shuffling the array deck, pick the first four cards from deck. The program displays the cards from these four card numbers. Implement the following code in Eclipse, and ensure it runs without errors. Think about the following questions and write down your answers in a few sentences. 1) Describe how the above program shuffles the cards. 2) Describe how deck[i] / 13 and deck[i] % 13 work to display the suit and rank of cards.
The task is to create a
All the cards can be represented using an array named deck, filled with initial values 0 to 51, as
follows:Card numbers 0–12, 13–25, 26–38, and 39–51 represent 13 Spades, 13 Hearts, 13 Diamonds, and
13 Clubs, respectively, as shown in Figure 1. cardNumber / 13 determines the suit of the card,
and cardNumber % 13 determines the rank of the card, as shown in Figure 2. After shuffling the
array deck, pick the first four cards from deck. The program displays the cards from these four
card numbers.
Implement the following code in Eclipse, and ensure it runs without errors.
Think about the following questions and write down your answers in a few sentences.
1) Describe how the above program shuffles the cards.
2) Describe how deck[i] / 13 and deck[i] % 13 work to display the suit and rank of cards.
![Learning X
A-Z Data X
← → C
CPS 2231 Lab3.pdf
44°F
Mostly cloudy
JSTOR H XE Science X PQ Represer X
kean.instructure.com/courses/12224/assignments/56685
231°02 > Assignments
}
public class DeckOfCards {
public static void main(String[] args) {
int [52];
int[] deck = new
String[] suits =
▬▬▬
}
E Result Li X
String[] ranks = {"Ace", "2", "3",
"10", "Jack", "Queen", "King"};
{"Spades", "Hearts",
{"Spades", "Hearts",
}
Connect X
// Initialize cards
for (int i = 0; i < deck.length; i++)
deck[i] = i;
// Shuffle the cards
for (int i = 0; i < deck.length; i++) {
// Generate an index randomly
"Diamonds", "Clubs"};
{"Ace", "2", "3", "4", "5", "6","7", "8", "9",
}
// Display the first four cards
for (int i = 0;
i < 4; i++) {
O Search
int index = (int) (Math.random() * deck.length);
int temp
deck[i];
deck[i] = deck[index];
deck[index] = temp;
Lab 3: 1- X b Home | x
a
Page <
String suit = suits [deck[i] / 13];
String rank = ranks [deck[i] % 13];
System.out.println("Card number + deck[i] + ": "
+ rank + of "suit);
#
3 > of 6
New Tab x +
Download
R=J
i Info
ZOOM
+
J
X Close
4x O
11:57 PM
2/8/2023
X](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2ae76079-938b-4b5d-8ceb-1dfbc10f88ce%2F4c2be8d7-a1ac-4d7e-b382-4910d07ebbad%2Ftz0y357_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images









