Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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!
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB 2008 Databases

Authors: Vidya Vrat Agarwal, James Huddleston

1st Edition

1590599470, 978-1590599471

More Books

Students also viewed these Databases questions