Question: //Using java language programming 5. Suppose a dart board is a square with dimensions 1 X 1, on which we draw a quarter circle with
5. Suppose a dart board is a square with dimensions 1 X 1, on which we draw a quarter circle with radius 1 and with the origin located at the lower left corner of the dart board. The area on the dart board that is inside the quarter circle is the "hit" area. The area on the dart board outside the quarter circle is the "miss" area. If we throw ran- domly at the dart board, the ratio of hits to throws will be roughly equal to the ratio of the hit area (r2/4 = 12/4 /4) to the total area (1 1 = 1), write a program that simulates randomly throwing a dart one million times at this dart board. Esti- mate a value for from the hits-to-throws ratio. (Hint: To "throw" a dart, generate two random double values, each between 0.0 and 1.0. Treat these values as the (x, y) coordinates of the point on the dart board on which the dart lands. To determine if a throw is a hit, check if the distance of the hit from the origin is less than or equal to 1. If it is, then the throw is a hit; otherwise, it is a miss. This problem is particularly in- teresting because we are using a random process to determine the universal constant To generate random numbers, use the predefined Random class. Place the following statement at the beginning of your program: import java.util.Random; To create a Random object, use Random r = new Random(); To generate a random double value between 0.0 and 1.0 and assign it to x, use x = r.nextDouble(); miss hit (0, 0)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
