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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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. 

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
Transcribed Image Text: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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education