1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
AleksandrR [38]
3 years ago
14

Coupon collector is a classic statistic problem with many practical applications. The problem is to pick objects from a set of o

bjects repeatedly and determine how many picks are needed for all the objects to be picked at least once. A variation of the problem is to pick cards from a shuffled deck of 52 cards repeatedly and find out how many picks are needed before you see one of each suit. Assume a picked card is placed back in the deck before picking another. Write a program to simulate the number of picks needed to get total of four cards from each different suit and display the four cards picked (it is possible that a card may be picked twice). Here is a sample run of the program:
4 of Diamonds
8 of Spades
Queen of Clubs
8 of Hearts
Number of picks: 9

Computers and Technology
1 answer:
ahrayia [7]3 years ago
8 0

Answer:

Here is the JAVA program:

public class Main {  //class name

public static void main(String[] args) {   //start of main method

//sets all boolean type variables spades, hearts diamonds and clubs to false initially

   boolean spades = false;  

   boolean hearts = false;

   boolean diamonds = false;

   boolean clubs = false;  

   String[] deck = new String[4];  //to store card sequence

   int index = 0;  //to store index position

   int NoOfPicks = 0;  //to store number of picks (picks count)

   while (!spades || !hearts || !diamonds || !clubs) {   //loop starts

       String card = printCard(getRandomCard());  //calls printCard method by passing getRandomCard method as argument to it to get the card

       NoOfPicks++;   //adds 1 to pick count

       if (card.contains("Spades") && !spades) {  //if that random card is a card of Spades and spades is not false

           deck[index++] = card;  //add that card to the index position of deck

           spades = true;  //sets spades to true

       } else if (card.contains("Hearts") && !hearts) {  //if that random card is a card of Hearts and hearts is not false

           deck[index++] = card;  

           hearts = true;   //sets hearts to true

       } else if (card.contains("Diamond") && !diamonds) {  //if that random card is a card of Diamond and diamonds is not false

           deck[index++] = card;

           diamonds = true;  //sets diamonds to true

       } else if (card.contains("Clubs") && !clubs) {  if that random card is a card of Clubs and clubs is not false

           deck[index++] = card;

           clubs = true;         }     }   //sets clubs to true

   for (int i = 0; i < deck.length; i++) {  //iterates through the deck i.e. card sequence array

       System.out.println(deck[i]);     }  //prints the card number in deck

   System.out.println("Number of picks: " + NoOfPicks);  }   //prints number of picks

public static int getRandomCard() {  //gets random card

   return (int) (Math.random() * 52); }   //generates random numbers of 52 range

public static String printCard(int cardNo) {   //displays rank number and suit

   String[] suits = { "Spades", "Hearts", "Diamonds", "Clubs", };  //array of suits

   String[] rankCards = { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10",

           "Jack", "Queen", "King" };   //array of rank

  int suitNo = cardNo / 13;  //divides card number by 13 and stores to suitNo

 int rankNo = cardNo % 13;   //takes modulo of card number and 13 and store it to rankNo

   return rankCards[rankNo] + " of " + suits[suitNo];  }}  //returns rankCard at rankNo index and suits at suitNo index

Explanation:

The program is explained in the comments attached with each line of code. The screenshot of the program along with its output is attached.

You might be interested in
If a system's instruction set consists of an 8-bit opcode, what is the maximum number of output signal lines required for the co
otez555 [7]

Answer:

D. 256

Explanation:

Given

Instructions = 8\ bit

Required

Determine the maximum number of output

To get the required value, we make use of the following:

Maximum = 2^n

Where n is the bits of the opcode.

i.e.

n = 8

Substitute 8 for n in Maximum = 2^n

Maximum = 2^8

Maximum = 256

<em>Hence, option D answers the question</em>

6 0
3 years ago
When performing actions between your computer and one that is infected with a virus, which of the following offers No risk of yo
daser333 [38]

Answer:

d

Explanation:

7 0
3 years ago
To copy and paste the image in MS Word the dash option is used​
Stells [14]

<em>ur</em><em> </em><em>answer</em><em> </em><em>hope</em><em> </em><em>this</em><em> </em><em>will</em><em> </em><em>helps</em><em> </em><em>u</em><em /><em /><em /><em /><em />

5 0
2 years ago
A photograph is taken by letting light fall on a light-sensitive medium, which then records the image onto that medium.
Andru [333]
True. At least that's how it is for camera's that print photos. Not digital cameras
4 0
3 years ago
Read 2 more answers
Benefits of etherchannel
Mariana [72]
An ether channel can give you high speed interface if it is successfully engineered. Combining 2 or more ethernet lets you create a logical ethernet link providing high speed links between switches. Also having etherchannel gives you a higher band width than what you costumed for.
5 0
3 years ago
Other questions:
  • What office application has animations on the home ribbon?
    7·2 answers
  • What type of document would you use the landscape page orientation
    7·1 answer
  • Computing devices translate digital to analog information in order to process the information
    8·1 answer
  • What is the maximum transmission speed for bluetooth v3 and v4 devices?
    12·1 answer
  • Write a program with a function that accepts a string as an argument and returns a copy of the string with the first character o
    11·1 answer
  • ANSWER THIS CORRECTLY FOR BRAINLIEST
    13·2 answers
  • Case 2-2 Jack has a computer at home that he uses to access the Internet, store and edit personal photos, and create and edit do
    9·1 answer
  • How did the use of ARPANET change computing?
    14·1 answer
  • PLZ HELP What will be the output? class num: def init (self.a): self. number = a mul* __(self. b) return self. number + b. numbe
    7·1 answer
  • Need answer ASAP
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!