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
Write a HTML program as shown in the output.​
Vitek1552 [10]

Explanation:

<html>

<title>first term 9/<title>

<head>SUNGHAVA SHIKSHA NIKETANA</head>

<body>

<h1>maths formula</h1>

<h6>a2-b2=(a+b)(A-B)</h6>

<h1>list of exams<\h1>

<h6>1.computer,2.english,3science</h6>

</body>

</html>

3 0
3 years ago
You have just installed a SOHO router in a customer’s home and the owner has called you saying his son is complaining that Inter
emmainna [20.7K]

Answer: A. Verify the wireless connection is using the fastest wireless standard the router supports.

D. Enable QoS for the gaming applications on the router and on the son's computer.

Explanation: Verifying the wireless connection is using the fastest wireless standard the router supports will improve line of connectivity and reduce network latency hence gaming consoles communicate faster.

QoS enables the prioritizing of the volume of internet traffic on the console for high quality gaming. QoS will also enable more internet bandwidth to be channeled to the gaming console.

6 0
3 years ago
Help with this quiz question thank you!
Svetlanka [38]
Hey wsg tbh this is an educated guess and I think it’s A. If it’s wrong then it’s my bad
4 0
3 years ago
Read 2 more answers
15 Points ASAP
DaniilM [7]
18 Point is the smallest font size on a slide
7 0
4 years ago
Read 2 more answers
help the grading period ends on Thursday and I need to get everything turned in by tomorrow (many more of these coming)
coldgirl [10]

Answer:

1. Fair use

2. Stacey uses parts of an older song in her new album that she wants to sell online.

3. Braxton makes a movie about his favorite superhero, using clips from various movies, and charges his friends to see it.

Explanation:

1. Fair use is a doctrine in the law of the United States that permits limited use of copyrighted material without having to first acquire permission from the copyright holder.

2. Stacey is not allowed to sell someone else's work as her own without getting permission from the original owner.

3. Braxton is not allowed to charge his friends to see his "movie", which is someone else work compiled into one video, without getting permission from the owner of the movies.

5 0
3 years ago
Other questions:
  • Susan is creating a spreadsheet, and she needs to enter the months of the year in column A. Susan should _____.
    15·2 answers
  • Which of the following is the 1's complement of 10?
    10·2 answers
  • Your ___ can provide hardware firewall protection for your home network where it connects to the ISP's network, just as ISP netw
    12·1 answer
  • Explain why the effect of stimulant and depressants do not necessarily counteract<br>each other​
    5·1 answer
  • in a typical e-mail address, the "host" is A. an account designated by a user name B. CPU processor 2500 C. the receiver of an e
    12·2 answers
  • A school’s administration stores the following data for each student in an online system: name, class, and five electives. Selec
    12·1 answer
  • Please help i will give you brainiest and 5 stars answer the question!!!!!!!!!!!!!!!!!!!!!!!!!
    7·1 answer
  • Which 2 processes are operational processes
    10·1 answer
  • Reflect on your semester in this class analysis and Design from an overall "experience" perspective
    9·1 answer
  • web browsers save website information in their _________, which helps the site load faster on future visits.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!