Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. public class Monopoly
  2. {
  3.  
  4.     String[] spaces = {"Mediterranean Avenue", "Community Chest(1)", "Baltic Avenue", "Income Tax", "Reading Railroad",
  5.     "Oriental Avenue", "Chance(1)", "Vermont Avenue", "Connecticut Avenue", "In Jail/Just Visiting", "St. Charles Place",
  6.     "Electric Company", "States Avenue", "Virginia Avenue", "Pennsylvania Railroad", "St. James Place", "Community Chest(2)",
  7.     "Tennessee Avenue", "New York Avenue", "Free Parking", "Kentucky Avenue", "Chance(2)", "Indiana Avenue", "Illinois Avenue",
  8.     "B&O Railroad", "Atlantic Avenue", "Ventnor Avenue", "Water Works", "Marvin Gardens", "Go to Jail", "Pacific Avenue",
  9.     "North Carolina Avenue", "Community Chest(3)", "Pennsylvania Avenue", "Short Line", "Chance(3)", "Park Place", "Luxury Tax",
  10.     "Boardwalk", "Go"};
  11.    
  12.     final int players = 1;
  13.     final int goAroundTimes = 25;
  14.     float[] percentages = new float[40];
  15.        
  16.    
  17.     public float[] analyze()
  18.     {
  19.    
  20.         int[] visitCount = new int[40];
  21.        
  22.         for(int i = 0; i < players; i++)
  23.         {
  24.            
  25.             String position;
  26.            
  27.            
  28.             int timesAround = 1;
  29.             Dice dice = new Dice();
  30.            
  31.             do
  32.             {
  33.                 int move = dice.roll2Dice();
  34.                 position = spaces[move];
  35.                
  36.                 for(int j = 0; j < 40; j++)
  37.                 {
  38.                     position = spaces[j];
  39.                     visitCount[j] += 1;
  40.                 }
  41.                
  42.                
  43.                 if( position == "Go" )
  44.                 {
  45.                     timesAround += 1;
  46.                     position = spaces[1];
  47.                 }
  48.                
  49.                 else if( position == "In Jail/Just Visiting" )
  50.                 {
  51.                     timesAround += 1;
  52.                     position = spaces[10];
  53.                     visitCount[10] -= 1;
  54.                 }
  55.                
  56.                
  57.             }while(timesAround < goAroundTimes);
  58.            
  59.         }
  60.        
  61.        
  62.         for(int i = 0; i < 40; i++)
  63.         {
  64.             int visitTotal = 0;
  65.             visitTotal += visitCount[i];
  66.            
  67.             percentages[i] = (visitCount[i] / visitTotal) * 100;
  68.         }
  69.        
  70.         return percentages;    
  71.     }
  72.        
  73.         public void listResults(float[] results)
  74.         {
  75.             for(int i = 0; i < 40; i++)
  76.             {
  77.                 System.out.printf("%5d/t5.2f \n", percentages[i] );
  78.             }
  79.         }
  80.        
  81.        
  82. }
  83.  
  84.  
  85.  
  86. And then
  87.  
  88.  
  89. public class TestGame
  90. {
  91.     public static void main(String[] args)
  92.     {
  93.         Monopoly game = new Monopoly();
  94.         float[] results = game.analyze();
  95.         game.listResults(results);
  96.     }
  97. }
  98.  
  99.  
  100. Dice thingy
  101.  
  102. import java.util.*;
  103.  
  104. public class Dice
  105. {
  106.     Random rand = new Random();
  107.    
  108.     public int roll1Die()
  109.     {
  110.         return rand.nextInt(6) + 1;
  111.     }
  112.    
  113.     public int roll2Dice()
  114.     {
  115.         int die1 = roll1Die();
  116.         int die2 = roll1Die();
  117.        
  118.         return die1 + die2;
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement