CSE Homework 4.docx - Michael Mendiola.67 CSE 2221(11:30...

This preview shows page 1 - 2 out of 2 pages.

Michael Mendiola.67CSE 2221 (11:30)Instructor: S. Joshi01/23/17Homework 041.public static boolean pointIsInCircle(double xCoord, double yCoord){boolean inCircle = false;if (Math.sqrt(Math.pow(xCoord - 1, 2) + Math.pow(yCoord - 1, 2)) <= 1){inCircle = true;}return inCircle;}2.public static int numberOfPointsInCircle(int n){int totalPoints = 0;int pointsIn = 0;Random rnd = new Random();while (totalPoints < n){double x = rnd.nextDouble() * 2; double y = rnd.nextDouble() * 2;if (pointIsInCircle(x, y) == true)pointsIn++;totalPoints++;}return pointsIn;}3.import components.random.Random;import components.random.Random1L;import components.simplereader.SimpleReader;import components.simplereader.SimpleReader1L;import components.simplewriter.SimpleWriter;import components.simplewriter.SimpleWriter1L;public final class MonteCarlo {private MonteCarlo() {}public static void main(String[] args) {/** Open input and output streams*/SimpleReaderinput = newSimpleReader1L();SimpleWriteroutput = newSimpleWriter1L();/** Ask user for number of points to generate*/output.print("Number of points: ");int n = input.nextInteger();/*1
* Declare counters and initialize them

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture