Monte carlo simulation in java
<p>I have a task of performing a distributed solution for monte carlo in which the master must performs socket connection communication duties and send a number to one or more worker, be able to receive a point count that it can summate with any other counts it receives. I am stuck.it just keeps waiting for connection This is my code</p>

<pre><code>    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.io.PrintWriter;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.util.Random;
    import java.util.Scanner;

public class PICalcDistributedMaster {

    PrintWriter pWriter;

    // x coordinate of circle centre also equal to x coordinate of square centre

    private double xPoint;

    // y coordinate of circle centre also equal to y coordinate of square centre

    private double yPoint;

    // Half the width of the square, also equal to circle radius.

    private double radius;

 public PICalcDistributedMaster(double radius) {
           this.xPoint = radius;
           this.yPoint = radius;
           this.radius = radius;
  }

 public void setRadius(double radius) {

       this.radius = radius;

  }

 public double getRadius() {

       return radius;
  }

    /**
    *
    * @param x The x coordinate of a point,p
    * @param y The y coordinate of a point,p
    * @return true if p lies within a circle inscribed within the square,
    * such that circle diameter = square diameter.
    * To do this, this method finds the distance between the point
    * and the centre of the circle and if the distance is greater than
    *
    */

    public boolean isInside( double x , double y){

    double dx = this.xPoint-x;
    double dy = this.yPoint-y;
    double dist = Math.sqrt(dx*dx+dy*dy);

    return dist &lt;= this.radius;

    }//end method.

    /**
    * Assumes a square whose centre is at point r,r
    * where r = square's radius. and its edges are at 0,0, 2r,0, 0,2r and 2r,2r.
    */
    public void go(){

      calculate();
      send();
      connect();
    }
    public void send(){

          try{                                
               Socket s = new Socket();
               ServerSocket ss = new ServerSocket(1234, 50);
               System.out.println("Waiting for connection");

               s = ss.accept();  // accepts network connection
               PrintWriter pWriter = new PrintWriter(s.getOutputStream());
               pWriter.println("Sending number to Slave Machine");
               System.out.println("Waiting for connection");
               System.out.println("Connection received from "+s.getInetAddress());     

               ObjectOutputStream ostream = new ObjectOutputStream(s.getOutputStream());
               ostream.flush();

               ObjectInputStream istream = new ObjectInputStream(s.getInputStream());
               System.out.println("IO streams found");
               istream.read(); //reads the input stream

               String message = "connection successful";
               ostream.writeObject(message);
               ostream.flush();
               System.out.println(message);                
               }

          catch (IOException ioe){

             ioe.printStackTrace();
            }         
          }

         public void connect(){

         String message = "connection successful";
         }

         void calculate(){

         PICalcDistributedMaster pim = new PICalcDistributedMaster(10);
         Scanner input = new Scanner(System.in);
         System.out.print("Please enter number of throws: "); 

         double numThrows = input.nextDouble();
         double PI = pim.computePI(numThrows);
         double difference = PI - Math.PI;

          System.out.println(" THE CALCULATED VALUE OF PI FOR "+numThrows+"THROWS="+PI);
          System.out.println(" THE ACTUAL VALUE OF PI  = "+Math.PI);
          System.out.println(" THE DIFFERENCE IN DEVIATION FROM CALCULATED VALUE TO    ACTUAL VALUE IS  = "+difference);

    }

    public double computePI (double numThrows){

          Random randomGen = new Random ();
          double hits = 0;
          double PI = 0;            

            double width = radius * 2;
            //radius * 2 is the width of the square so we are stretching the random number generated
            //to apply across width, since by default it only generates between  0 and 1.
       for (int i = 0; i &lt;= numThrows; i++){

                   double xPos = (randomGen.nextDouble()) * width;
         double yPos = (randomGen.nextDouble()) * width;
           if (isInside(xPos, yPos)){
            hits++;         
                       }

                       PI = (4 * (hits/numThrows));                       
                   }

                   System.out.println("Throws = "+numThrows);
                   System.out.println("Hits = "+hits);


           return PI;
       }


      public static void main(String [] args){

          PICalcDistributedMaster pim = new PICalcDistributedMaster(10);
          pim.go();

      }
</code></pre>

<p>}</p>
