Advertisement
calcpage

C6X12_Dart.java

Jan 31st, 2012
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.48 KB | None | 0 0
  1. //Dart.java MrG 2012.0131
  2. import java.util.Random;
  3. public class Dart
  4. {
  5.     private int hits;
  6.     private int tries;
  7.     private Random gen;
  8.  
  9.     public Dart()
  10.     {
  11.         hits = 0;
  12.         tries = 0;
  13.         gen = new Random();
  14.     }
  15.  
  16.     public void toss()
  17.     {
  18.         double x = 2*gen.nextDouble()-1;
  19.         double y = 2*gen.nextDouble()-1;
  20.         if (x*x+y*y<1)
  21.         {
  22.             hits = hits + 1;
  23.         }
  24.         tries = tries + 1;
  25.     }
  26.  
  27.     public int getHits()
  28.     {
  29.         return hits;
  30.     }
  31.  
  32.     public int getThrows()
  33.     {
  34.         return tries;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement