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
What is the purpose of the Format Painter?
Oduvanchick [21]

Answer:

changes the formatting to be exact from what is copied to what should be

Explanation:

It happens to be the feature of the MS word that is applied to a style from one section of the document to another section. We first highlight the text with the thought of style like size, font, etc., and then click the format painter. The text that is highlighted next, gets transformed into the thought of style. And hence, the above option is correct.

5 0
3 years ago
Fuel-pressure regulators on fuel-return-type fuel-injection systems are installed
Natalija [7]
1) The correct answer is <span>B. at the end of the fuel rail.
2) The one who is correct is the Technician A.</span>
5 0
3 years ago
Read 2 more answers
.9 What is Artificial Intelligence?
Serhud [2]
C because bread is not happy with you
8 0
3 years ago
An EAP is an:
Oksana_A [137]

i believe the answer would be B

8 0
3 years ago
Read 2 more answers
Here it is crews my profile pic
Murrr4er [49]
It looks niceee
Also can you mark me brainlyest for extra points
7 0
3 years ago
Read 2 more answers
Other questions:
  • Why must an rodc be able to connect to at least one windows server 2008 or higher domain controller?
    5·1 answer
  • For an alternative to the String class, and so that you can change a String's contents, you can use_________ .
    12·1 answer
  • You learned that properly edited resumes are necessary for making a good impression on a university or a potential employer. Dis
    13·1 answer
  • Which of the following is the code of acceptable behaviors users should follow while on the Internet; that is, it is the conduct
    15·1 answer
  • How can you create an illusion of spatial depth in a two-dimensional design?
    15·1 answer
  • Chapter 15 Problem 6 PREVENTIVE CONTROLS Listed here are five scenarios. For each scenario, discuss the possible damages that ca
    11·1 answer
  • _____ is the practice of using the internet to provide healthcare without going to a doctor’s office or hospital.
    15·2 answers
  • Who's hype for Halo Infinite?
    11·2 answers
  • Please answer me <br> in Assignment - Algorithms
    10·1 answer
  • List out any four hardware and software components required for multimedia​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!