CSnathan

sb pool names

Feb 5th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.19 KB | None | 0 0
  1. package SuperBowlPool;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5. public class Names
  6. {
  7.     Random gen = new Random();
  8.     private String[] strOwner, joint;
  9.     private int number, slots, ownerCount = 0, repCount = 0;
  10.     private String teamOne, teamTwo;
  11.     private int peopleCount, slotPerCount, totalSlots;
  12.     private boolean[] taken, hasRepresent;
  13.     private int[] owner, represent;
  14.    
  15.    
  16.     public Names(int people, int slot, String[] array)
  17.     {
  18.         number = people;
  19.         joint = array;
  20.         slots = slot;
  21.         totalSlots = number * slots;
  22.        
  23.     }
  24.    
  25.     //Gets the team names
  26.     public void teamNames(String team1, String team2)
  27.     {
  28.         teamOne = team1;
  29.         teamTwo = team2;
  30.     }
  31.    
  32.     //Assigns a value to names
  33.     private int[] assign()
  34.     {
  35.         int rand = gen.nextInt(number);
  36.         boolean[] hasRepresent = new boolean[number+1];
  37.         int[] represent = new int[number + 1];
  38.         represent[number] = number;
  39.         int repCount = 0;
  40.         while (repCount <= number)
  41.         {
  42.             hasRepresent[repCount] = false;
  43.             repCount++;
  44.         }
  45.        
  46.         repCount = 0;
  47.         while (repCount < number)
  48.         {
  49.             if (hasRepresent[rand] == false)
  50.             {
  51.                 represent[rand] = repCount;
  52.                 hasRepresent[rand] = true;
  53.             }
  54.             else
  55.             {
  56.             while (hasRepresent[rand] == true)
  57.             {
  58.                 rand = gen.nextInt(number);
  59.             }
  60.             represent[rand] = repCount;
  61.             hasRepresent[rand] = true;
  62.             }
  63.             repCount++;
  64.         }
  65.         return represent;
  66.     }
  67.    
  68.     //Creates the ownership of the slots for the pool chart
  69.     public String[] nameChart()
  70.     {
  71.         boolean[] taken = new boolean[totalSlots];
  72.         int[] owner = new int[totalSlots];
  73.         int takenCount = 0;
  74.         while (takenCount < totalSlots)
  75.         {
  76.             taken[takenCount ] = false;
  77.             takenCount++;
  78.         }
  79.         peopleCount = 0;
  80.         while (peopleCount < number)
  81.         {
  82.             slotPerCount = 1;
  83.             while (slotPerCount < slots)
  84.             {
  85.                 int rand = gen.nextInt(totalSlots);
  86.                 if (taken[rand] == false)
  87.                 {
  88.                     owner[rand] = peopleCount;
  89.                     taken[rand] = true;
  90.                 }
  91.                 else
  92.                 {
  93.                     while (taken[rand] == true)
  94.                     {
  95.                         rand = gen.nextInt(totalSlots );
  96.                     }
  97.                     owner[rand] = peopleCount;
  98.                     taken[rand] = true;
  99.                 }
  100.                 slotPerCount++;
  101.             }
  102.             peopleCount++;
  103.         }
  104.        
  105.         int checkCount = 0;
  106.         while (checkCount < totalSlots - 1)
  107.         {
  108.             if (taken[checkCount ] == false)
  109.             {
  110.                 taken[checkCount] = true;
  111.                 owner[checkCount] = (number);
  112.             }
  113.             checkCount++;
  114.         }
  115.         represent = assign();
  116.         ownerCount = 0;
  117.         String[] strOwner = new String[totalSlots -1];
  118.         while (ownerCount < totalSlots)
  119.         {
  120.             while (repCount <= number)
  121.             {
  122.                 repCount = 0;
  123.                 if (owner[ownerCount] == repCount)
  124.                 {
  125.                     strOwner[ownerCount] = joint[repCount];
  126.                     repCount = repCount + number+1;
  127.                 }
  128.                 else
  129.                 {
  130.                     repCount++;
  131.                 }
  132.             }
  133.             ownerCount++;
  134.         }
  135.        
  136.         return strOwner;
  137.     }
  138.    
  139.    
  140.     //Print the pool array
  141.     public void getPool(int slots, int number)
  142.     {
  143.         int rowcolLimit = (int) (Math.ceil(Math.sqrt(slots * number)));
  144.         strOwner = nameChart();
  145.         int count = 0;
  146.         int ownerCount = 0;
  147.         while (count < rowcolLimit)
  148.         {
  149.             System.out.println();
  150.             int count2 = 0;
  151.             while (count2 < rowcolLimit)
  152.             {
  153.                 System.out.print(strOwner[ownerCount] + "\t");
  154.                 ownerCount++;
  155.                 count2++;
  156.             }
  157.             count++;
  158.         }
  159.     }
  160.  
  161. }
Add Comment
Please, Sign In to add comment