Question: Problem Description: Write a method named coinToss that simulates the tossing of a coin using the following method header: public static String coinToss ( )

Problem Description:
Write a method named coinToss that simulates the tossing of a coin using the
following method header:
public static String coinToss()
When the method is called, it should generate a random number in the range
of 1 through 2. If the random number is 1, the method returns a string "heads". If
the random number is 2, it returns "tails".
You can use the random method of the Math class to generate a random
number between 1 and 2 like this:
(int)(Math.random ()**2)+1;
Write a test program (in the main method) that asks the user how many times
the coin should be tossed and then simulates the tossing of the coin that number
of time using the method coinToss. It then displays a report as in the sample runs.
The program must then ask if the user wants to continue with another round of
coin tosses. If the user enters "y", the program will start a new round. Otherwise, it'll
stop.
Sample run: (red indicates user's inputs)
How many times do you want to toss the coin? 20y
How many times do you want to toss the coin? 7
Good bye!
 Problem Description: Write a method named coinToss that simulates the tossing

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!