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
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
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Program on Numbers
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
  • SEE MORE 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