Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package SuperBowlPool;
- import java.util.ArrayList;
- import java.util.Random;
- public class Names
- {
- Random gen = new Random();
- private String[] strOwner, joint;
- private int number, slots, ownerCount = 0, repCount = 0;
- private String teamOne, teamTwo;
- private int peopleCount, slotPerCount, totalSlots;
- private boolean[] taken, hasRepresent;
- private int[] owner, represent;
- public Names(int people, int slot, String[] array)
- {
- number = people;
- joint = array;
- slots = slot;
- totalSlots = number * slots;
- }
- //Gets the team names
- public void teamNames(String team1, String team2)
- {
- teamOne = team1;
- teamTwo = team2;
- }
- //Assigns a value to names
- private int[] assign()
- {
- int rand = gen.nextInt(number);
- boolean[] hasRepresent = new boolean[number+1];
- int[] represent = new int[number + 1];
- represent[number] = number;
- int repCount = 0;
- while (repCount <= number)
- {
- hasRepresent[repCount] = false;
- repCount++;
- }
- repCount = 0;
- while (repCount < number)
- {
- if (hasRepresent[rand] == false)
- {
- represent[rand] = repCount;
- hasRepresent[rand] = true;
- }
- else
- {
- while (hasRepresent[rand] == true)
- {
- rand = gen.nextInt(number);
- }
- represent[rand] = repCount;
- hasRepresent[rand] = true;
- }
- repCount++;
- }
- return represent;
- }
- //Creates the ownership of the slots for the pool chart
- public String[] nameChart()
- {
- boolean[] taken = new boolean[totalSlots];
- int[] owner = new int[totalSlots];
- int takenCount = 0;
- while (takenCount < totalSlots)
- {
- taken[takenCount ] = false;
- takenCount++;
- }
- peopleCount = 0;
- while (peopleCount < number)
- {
- slotPerCount = 1;
- while (slotPerCount < slots)
- {
- int rand = gen.nextInt(totalSlots);
- if (taken[rand] == false)
- {
- owner[rand] = peopleCount;
- taken[rand] = true;
- }
- else
- {
- while (taken[rand] == true)
- {
- rand = gen.nextInt(totalSlots );
- }
- owner[rand] = peopleCount;
- taken[rand] = true;
- }
- slotPerCount++;
- }
- peopleCount++;
- }
- int checkCount = 0;
- while (checkCount < totalSlots - 1)
- {
- if (taken[checkCount ] == false)
- {
- taken[checkCount] = true;
- owner[checkCount] = (number);
- }
- checkCount++;
- }
- represent = assign();
- ownerCount = 0;
- String[] strOwner = new String[totalSlots -1];
- while (ownerCount < totalSlots)
- {
- while (repCount <= number)
- {
- repCount = 0;
- if (owner[ownerCount] == repCount)
- {
- strOwner[ownerCount] = joint[repCount];
- repCount = repCount + number+1;
- }
- else
- {
- repCount++;
- }
- }
- ownerCount++;
- }
- return strOwner;
- }
- //Print the pool array
- public void getPool(int slots, int number)
- {
- int rowcolLimit = (int) (Math.ceil(Math.sqrt(slots * number)));
- strOwner = nameChart();
- int count = 0;
- int ownerCount = 0;
- while (count < rowcolLimit)
- {
- System.out.println();
- int count2 = 0;
- while (count2 < rowcolLimit)
- {
- System.out.print(strOwner[ownerCount] + "\t");
- ownerCount++;
- count2++;
- }
- count++;
- }
- }
- }
Add Comment
Please, Sign In to add comment