Maintain the java.util.BitSet link in your myTeams class and create it with a number equal to the number of commands. By default, all values ββare not set (false) at the beginning.
As a team tries to play a match with another team in aoTeams , check the value in BitSet in the index of the opponent's array. If it is not installed, let it reproduce and set the value in this index. Do the same for the other team.
An example implementation might look like this:
class Team { String teamName; int wins; int losses; BitSet playRecord; public Team(String name, int size) { this.teamName = name; playRecord = new BitSet(size); } public boolean hasPlayed(int index) { return playRecord.get(index); } public void finishedPlaying(int index) { playRecord.set(index); } }
And here is how you use it:
public static void main(String[] args) { int size = 9; Team aoTeams[] = new Team[size]; aoTeams[0] = new Team("Utah", size); aoTeams[1] = new Team("USC", size); play(aoTeams, 0, 1); } private static void play(Team[] teams, int indexA, int indexB) { if (teams[indexA].hasPlayed(indexB)) {
source share