import java.lang.Math;
import SimpleInput;
import SimpleOutput;


public class approxPi {
    // class provides a framework for checking whether the parentheses
    // in a line of input match

    public static void main (String args []) {

        // declare needed objects
        SimpleInput in = new SimpleInput();
        SimpleOutput out = new SimpleOutput();

        double x, y; // coordinates for a randomly-generated point

        // Other declarations
        int N;         // Number of points to be selected
        int count = 0; // Count of points in circle
        int i;         // loop index
        boolean errorFound = false; // state of checking so far

        // read line from keyboard
        out.println ("Please enter the number of points to be selected");
        N = in.readInt();

        for (i = 0; i < N; i = i + 1) {
            // pick a random x and y value
            x = Math.random(); 
            y = Math.random();
            // check if point is in circle of radius 1.0
            if (x*x + y*y <= 1.0)
                count = count + 1;
        }
        
        out.println ("In selecting " + N + " points in the unit square");
        out.println ("in the first quadrant, " + count + " points ");
        out.println ("were also in the unit circle.");
        out.println ("This gives " + 4.0*count/N 
                     + " as an approximation to Pi.");
    }
}

