title: Monte Carlo Simulation
body: <p>I'm a student in a Java Programming class. My problem deals with an interpretation of the Monte Carlo Simulation. I'm supposed to find the probability that three quarters or three pennies will be picked out of a purse that has 3 quarters and 3 pennies. Once a coin is picked it is not replaced. The probability should be 0.1XXXXXXX. I keep getting 0 or 1 for my answer. This is what i have so far.</p>
  
  <pre><code>public class CoinPurse {
      public static void main(String[] args) {
          System.out.print("Probability of Drawing 3 coins of the Same Type - ");
          System.out.println(coinPurseSimulation(100));
      }
  
      /**
       Runs numTrials trials of a Monte Carlo simulation of drawing 
       3 coins out of a purse containing 3 pennies and 3 quarters. 
       Coins are not replaced once drawn.
       @param numTrials - the number of times the method will attempt to draw 3 coins
       @returns a double - the fraction of times 3 coins of the same type were drawn.
       */
  
      public static double coinPurseSimulation(int numTrials) {
          final int P = 1;
          final int Q = 2;
          int [] purse = {Q, Q, Q, P, P, P};
          int [] drawCoins = new int[3];
          for (int draw = 0; draw &lt; 3; draw ++) {
              int index = (int)(Math.random() * purse.length);
              drawCoins[draw] = purse[index];
              int [] newPurse = new int[purse.length-1];
              int j = 0;
              for (int i =0; i &lt; purse.length; i++) {
                  if (i == index) {
                      continue;
                  }
                  newPurse[j] = purse[i];
                  j++;
              }
              purse = newPurse;
          }
          double number = 0.0;
          double result = 0.0;
          for (int i = 0; i &lt; numTrials; i++) {
              result++;
              for (int j = 0; j &lt; numTrials;j++) {
                  if(drawCoins[0] == drawCoins [1] &amp;&amp; drawCoins[1] == drawCoins[2]) {
                      number++;
                  }
              }
          }
          return number/result;
      }
  }
  </code></pre>