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?
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
Related questions
Question
100%
please answer the question for below questions (see the code):
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?
![11 public class Task_1and2 {
120 public static void main(String[] args) {
13
int[] deck = new int [52];
14
String[] suits = { "Spades", "Hearts", "Diamonds", "Clubs"};
15
String[] ranks = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
// Initialize cards
16
17
for (int i = 0; i < deck.length; i++)
18
deck[i] = i;
for (int i = 0; i < deck.length; i++) {
// Generate an index randomly
int index = (int) (Math.random()* deck.length);
int temp = deck[i];
deck[i] = deck[index];
deck[index] temp;
19
20
21
22
23
24
25
26
27
28
29
30
31
}
// 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);
4
}
32
33
34 /*
35 * 1) Describe how the above program shuffles the cards?
36
*
37 *2) Describe how deck[i] / 13 and deck[i] % 13 work to display the suit and rank of cards?
38 *
39 */
}
}
@Javadoc Declaration Console X Coverage
<terminated > Task_1and2 [Java Application] C:\Users\Jenif\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.1.v20211116-1657\jre\bin\javaw.exe (Oct 9, 2022, 11:48:48 AM
Card number 36 Jack of Diamonds
Card number 38: King of Diamonds
Card number 49: Jack of Clubs
Card number 25: King of Hearts](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe4e72d86-d216-4977-8ee6-fe536869a207%2Fb5c62add-c9e4-4fce-ae5e-ca9e042af6bb%2F2rkw5fr_processed.jpeg&w=3840&q=75)
Transcribed Image Text:11 public class Task_1and2 {
120 public static void main(String[] args) {
13
int[] deck = new int [52];
14
String[] suits = { "Spades", "Hearts", "Diamonds", "Clubs"};
15
String[] ranks = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
// Initialize cards
16
17
for (int i = 0; i < deck.length; i++)
18
deck[i] = i;
for (int i = 0; i < deck.length; i++) {
// Generate an index randomly
int index = (int) (Math.random()* deck.length);
int temp = deck[i];
deck[i] = deck[index];
deck[index] temp;
19
20
21
22
23
24
25
26
27
28
29
30
31
}
// 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);
4
}
32
33
34 /*
35 * 1) Describe how the above program shuffles the cards?
36
*
37 *2) Describe how deck[i] / 13 and deck[i] % 13 work to display the suit and rank of cards?
38 *
39 */
}
}
@Javadoc Declaration Console X Coverage
<terminated > Task_1and2 [Java Application] C:\Users\Jenif\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.1.v20211116-1657\jre\bin\javaw.exe (Oct 9, 2022, 11:48:48 AM
Card number 36 Jack of Diamonds
Card number 38: King of Diamonds
Card number 49: Jack of Clubs
Card number 25: King of Hearts
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps

Knowledge Booster
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.Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education