Suppose we add the method mystery below to the Coins class I

Suppose we add the method mystery (below) to the Coins class. In your own words, say what mystery does. ( 5 pts.) public int mystery(int big){ int howMany = 0; int total = 0; for(int j = 0; total < big; j++ ){ if (tossCoin() == HEADS) total++; howMany++; } return howMany; }

Solution

Answer:

public int mystery(int big){
       int howMany = 0;
       int total = 0;
       for(int j = 0; total < big; j++ ){
           if (tossCoin() == HEADS)
               total++;
           howMany++;
           }
       return howMany;
       }

In mystery method, we are tossing the coin number of times until we get HEADS that is equals to big value.

So we are using this method to get HEADS count that is equals to big variable value. and also we are counting after how many tosses we reach that HEADS count that is equals to big value. After that we are return howany attenps we made for reach HEADS equals to big.

Suppose we add the method mystery (below) to the Coins class. In your own words, say what mystery does. ( 5 pts.) public int mystery(int big){ int howMany = 0;

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site