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
Because HTML was designed as a cross-platform language, it is the preferred method of communicating with back-end databases. Tru
zubka84 [21]

Answer:

False

Explanation:

HTML which stands for Hypertext Markup Language is a front-end formatting language, that is why it is referred to as a markup language. It handles everything you want to be displayed on the webpage such as images, videos, text including their arrangements.

It should be noted that HTML is not a programming language. The back-end contains all that is developed on the server side. Usually programming languages like PHP, NodeJS, Ruby, C# and many more.

These programming languages communicate with back-end databases while HTML formats the result to be displayed on the web page.

6 0
4 years ago
Where can i check on an acer chromebook to see what version of java is installed.
lana66690 [7]

Based on the current situation, to check on an Acer Chromebook to see what version of java is installed, you must "<u>input</u><u> specific commands on the terminal window and press Enter key</u>."

<h3>Java Installation on Chromebook.</h3>

Currently, Góogle or Chromebook do not allow Java installation on its operating system. This is due to the security threats that are associated with Java.

However, there are ways to bypass this situation and eventually install Java on your Chromebook if you so desire.

Nevertheless, if eventually, you installed Java successfully on your Chromebook, to check the version, you must "<u>input specific commands on the terminal window and press Enter key."</u>

Learn more about Java Program here: brainly.com/question/19485769

5 0
2 years ago
What is does the word multimedia mean?
Natasha_Volkova [10]
Your answer would be B. Media that combines text, images, animation, and sound.
You're welcome:)
3 0
3 years ago
Read 2 more answers
A brown outline around a frame is an indication of which tool?​
zimovet [89]

Answer:

Direct Selection Tool

Explanation:

The Direct Selection tool is a tool that allows the selection of a single object or a single path such that an object already grouped with other objects can be directly and moved to a desired location

The Direct Selection tool can be used to select a container's content including graphics which are imported and specific points or paths of a figure or text to allow for drawing, text editing or to edit paths.

6 0
3 years ago
A moldboard was a feature and technological development of what device
wlad13 [49]
The moldboard is a curved iron wedge formed by the curved part of a steel plow blade that turns the furrow <span>used to lift and turn the soil.</span><span>
A moldboard was a feature and technological development of the device plow.
</span>It was used in farming for initial cultivation of soil, for preparation for sowing seed or planting to loosen or turn the soil. 
5 0
3 years ago
Other questions:
  • While working on a group project, you notice something does not look right in the presentation. You call a meeting with your tea
    14·2 answers
  • Who is the publisher of the book Vertebrates?
    7·1 answer
  • Andrew will use the _____ picture option to add a new image. ??
    15·2 answers
  • MULTIPLE CHOICE!!!
    5·2 answers
  • Match the following.
    8·1 answer
  • Computer father known as​
    5·1 answer
  • What is the role of a design tWhat is the role of a design tool in a Robotic Process Automation (RPA) solution?
    9·1 answer
  • Use a for loop to output the numbers from 50 to 65
    6·1 answer
  • 8. Software ____ are individual programs that can be purchased, installed, and run separately, but extract data from the common
    12·1 answer
  • Hello can someone help with the output of this please?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!