Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Maintain a <a href="http://docs.oracle.com/javase/7/docs/api/java/util/BitSet.html" rel="nofollow"><strong><code>java.util.BitSet</code></strong></a> reference in your class <code>myTeams</code> and instantiate it with a number equaling the number of teams. By default all values are <em>unset</em> (false) in the beginning.</p> <p>As a team tries to play a match with another team in the <code>aoTeams</code> check the value in the <code>BitSet</code> at the array index of the opponent. If it's not set let it play and <em>set</em> the value at that index. Do the same for the other team as well.</p> <p>An example implementation might look like:</p> <pre><code>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); } } </code></pre> <p>And this is how you use it:</p> <pre><code>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)) { // Teams have already played together } else { // Teams playing for the first time teams[indexA].finishedPlaying(indexB); teams[indexB].finishedPlaying(indexA); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload