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 total number of time zones that can be configured to show by default in a calendar in Outlook 2016?
olganol [36]

Answer:

I think its 2, but correct me if i'm wrong. :>

Explanation:

6 0
2 years ago
Guys Do you know about e-waste recycling well ?
TEA [102]
<span>E-waste is a popular name for elecronics at the end of their "useful life".. computers, tv, steros, copiers, and fax mations are some common products. many of them can be reused, refurbished, or recycled. 
</span>
4 0
2 years ago
Read 2 more answers
Need answer ASAP
kaheart [24]

Answer:

D. To ensure that the software adheres to technical standards

Explanation:

The responsibility of the software architect is to ensure that all parts of the software system are able to meet the requirements set forth by the project or specifications, in this case, the technical standards.  This is an important piece of the software system because without it, the software system may not perform the necessary functions that it was written to do.

Cheers.

5 0
2 years ago
What is the most appropriate data type for each of these items?
Tom [10]
I may be wrong, BUT here is what i think



b) line graph


d) pie graph
7 0
2 years ago
Type which type of interference we will install after installing operating system​
pentagon [3]

Answer:

There are different kinds of operating systems: such as Windows, Linux and Mac OS

There are also different versions of these operating systems, e.g. Windows 7, 8 and 10

Operating systems can be used with different user interfaces (UI): text user interfaces (TUI) and graphical user interfaces (GUI) as examples

Graphical user interfaces have many similarities in different operating systems: such as the start menu, desktop etc.

When you can recognize the typical parts of each operating system’s user interface, you will mostly be able to use both Windows and Linux as well as e.g. Mac OS.

THE ROLE OF OPERATING SYSTEM IN THE COMPUTER

An operating system (OS) is a set of programs which ensures the interoperability of the hardware and software in your computer. The operating system enables, among other things,

the identification and activation of devices connected to the computer,

the installation and use of programs, and

the handling of files.

8 0
2 years ago
Other questions:
  • why is wrong timing, poor technology, bad implementation and politics in business affected the OSI model as a standard
    5·1 answer
  • You asked your colleague to provide feedback on a blog post you recently wrote. When they sent you their feedback, they made edi
    10·1 answer
  • The following slide was created as part of a presentation that trains new employees how to use the scheduling and calendar softw
    14·2 answers
  • Write a function called printEvens that prints all the even numbers between 2 and 20, inclusive. It will take no arguments and r
    6·1 answer
  • As an improvement of the ATX form factor over AT, shorter wires made it easier to shield them and made them capable of handling
    6·1 answer
  • Which software is primarily used to create
    15·2 answers
  • Create detailed pseudocode for a program that calculates how many days are left until Christmas, when given as an input how many
    15·1 answer
  • Which of these statements regarding​ time-cost tradeoffs in CPM networks is​ true?
    6·1 answer
  • How to connect two routers wirelessly to extend range.
    15·1 answer
  • Which unit of binary storage has a size that is processor dependent?.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!