1. Engineering
  2. Computer Science
  3. in java you must provide test cases for each problem...

Question: in java you must provide test cases for each problem...

Question details
  • In Java

  • You must provide test cases for each problem to justify that your program works. Sometimes you may want to test more than one case.Question 6 (20 points) Write a program to approximate the area under a circle with radius r. Note that you should forget the existence of the well known formula area Tr2 2 2 2 dx Method: The equation of a circles with radius r, centered at origin is y22. Divide the area under the top of half (above x axis) in to small rectangles of width of your choice - smaller the better and you should pass this as a parameter to your method- and add these areas of all these rectangles to approximate the area of the upper half of the circle. Multiplying that value by 2 give the approximate area of the circle. You must test your results with known radius values (Say, if you set your radius to I. T hen you should see the π as the answer for the area) You dont need any Calculus knowledge to solve this problemQuestion 7 (20 points) Monte Carlo methods are a broad class of computational algorithms that rely on repeated random sampling to obtain numerical results. One of the basic examples of getting started with the Monte Carlo algorithm is the estimation of Pi Basic Idea: The idea is to simulate random (x, y) points in a 2-D plane with domain as a square of side 1 unit. Imagine a circle inside the same domain with same diameter and inscribed into the square. We then calculate the ratio of number points that lied inside the circle and total number of generated points. Refer to the image below Scatter Plot 1.00 0.95 0.90 0.85 0.80 0.75 0.70 0.65 0.60 0.55 050 0.45 0.35 0.30 0.25 0.20 0.15 0.05 00 01 02 0.304 050008 09 10 (first data) We know that area of the square is 1 unit sq while that of circle is π * ( )- . Now for a very large number of generated points Number of points generated inside cicle otal number of points generated The beauty of this algorithm is that we dont need any graphics or simulation to display the generated points. In randomized and simulation algorithms like Monte Carlo, the more the number of iterations, the more accurate the result is. Thus, it is estimating the value of T and not Calculating the value of T. Implement this algorithm in Java and estimate the value of π.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution