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
________ is the process the compiler uses to divide your source code into meaningful portions; the message means that the compil
Nesterboy [21]

Answer:

Parsing is the process uses to divide your source code into meaningful portions; the message means that the compiler was in the process of analyzing the code when the end of the file was encountered prematurely

Explanation:

In parsing process  the parser in compiler breaks code and data into smaller elements coming from lexical analysis phase.

6 0
3 years ago
Write a brief description of what the local authorities are recommending in the news people should do to protect themselves from
lana [24]
The brief description of the local author asbestos is Hope and that's what it would too with a heart and another heart which equals 100 which equals yes
3 0
3 years ago
You are researching RAM for a computer you are building for a friend who will be using the system as a home office server for he
pashok25 [27]

Answer:

ECC RAM

Explanation:

ECC RAM is the most popular Random Access Memory out there that is used by most business servers. Dealing with big data for most huge businesses is crucial. The need to prevent loss of data requires that they purchase ECC RAM. ECC RAM automatically protects the systems from potential errors that occur in memory. Any abrupt changes in temporary data stored in ECC RAM are automatically corrected. This is achieved by an additional memory chip that acts as error detection for the other eight RAM chips.

8 0
3 years ago
Which word processing tool can help you find synonyms to improve your word choice?
deff fn [24]
Grammarly is the answer
6 0
3 years ago
Read 2 more answers
Give an example of a file suffix for the files created by each of the following: 1) a word processing program 2) a spread sheet
gayaneshka [121]
1) .docx
2) .xlsx
3) .pptx
4) .zip
7 0
3 years ago
Other questions:
  • Which of the following option is correct about HCatalog?
    14·1 answer
  • For what show did the actor, whose star is located at 6667 Hollywood Boulevard, earn an Emmy Award for Outstanding Supporting Ac
    10·2 answers
  • High capacity circuits are limited by the least capable network link, which is typically the user connection. As such, it is imp
    11·1 answer
  • Match each career with the education required for each job
    12·1 answer
  • To generate a report with exact results based on specific criteria it is best to base the report on a(n) ____________________ cr
    6·1 answer
  • Identify which statement explains why a programmer would break a logic problem into steps.
    13·2 answers
  • Peripeteia is also referred to as __________.
    5·2 answers
  • Corey set up his presentation for delivery to his team.
    8·1 answer
  • how risk can impact each of the seven domains of a typical IT infrastructure: User, Workstation, Local Area Network (LAN), Local
    7·1 answer
  • ACTIVITY NI MATCHING TYPE Directions: Match Column A with Column B. Write the letter of the correct answer on the space provided
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!