package randomcolors; import java.io.Console; import java.util.Random; import java.util.Scanner; /** * A class is broken into twelve teams. A question is posed to each team. Teams * receive points for the correct answer and lose points for wrong answers. This * program is used by the instructor so that teams are chosen at random and points * totaled automatically. * * This program collects the number of points earned by each team as they compete. * The twelve teams (each represented by a color) are called on at random * (with replacement). When the competition is over, the user enters "!". At this * point, the totals points earned by each team are displayed. * * Modify this program so that it works without replacement. That is, after a team * is chosen and the team's points are collected, that team will not be called on * again until all remaining teams have been selected. When all twelve teams have * been given a score, the program places all twelve teams back in play. The program * only stops when the "!" has been entered. * */ public class RandomColors { /** * @param args the command line arguments */ public static void main(String[] args) { final int numColor = 12; String a[] = {"Red","Brown","Gray","Green","Orange","Pink","Teal","Yellow","Black","Blue","White","Purple"}; int totalPoints[] = { 0,0,0,0,0,0,0,0,0,0,0,0}; Scanner sc = new Scanner(System.in); Random rnd = new Random(); while(true) { int i = rnd.nextInt(numColor); System.out.println("Enter points for the " + a[i] + " team or ! to quit."); String val = sc.nextLine(); if(val.equals("!")) { // sort the arrays byt points sort(a,totalPoints,numColor); // display points and exit System.exit(0); for(int k = numColor-1; k >= 0; k--) { System.out.println("Team " + a[k] + " point total " + totalPoints[k]); } System.exit(0); } try { int points = new Integer(val).intValue(); totalPoints[i] += points; } catch(Exception e) { System.out.println("Exception thrown " + e); } } } public static void sort(String color[], int points[],int size){ for(int i=1; i0 && points[j]