
/* This program
 *  1. reads in a list of students and grades
 *  2. computes the average grade
 *  3. prints the difference from the average for each student
 */

/* It illustrates arrays, for loops,
 * the StringTokenizer class, and the StringBuffer class.
 */

import java.io.*;
import java.util.*;



public class Grades {

   public static void main (String args[]) throws IOException {

      // set of the input reader
      BufferedReader stdin = new BufferedReader
	 (new InputStreamReader (System.in));

      // set up the arrays
      final int MAX = 500;
      String[] names = new String[MAX];
      float[] grades = new float[MAX];


      // read in the grades
      // names and grades come in on the same line.  This uses a
      // StringTokenizer to break up the line.
      System.out.println ("Enter the students and grades: <name grade>");
      int count = 0;
      String line = stdin.readLine();
            
      while ( ! line.equals("quit") ) {
	 StringTokenizer tokens = new StringTokenizer (line);
	 names[count] = tokens.nextToken();
	 grades[count] = Float.valueOf(tokens.nextToken()).floatValue();
	 count++;
	 line = stdin.readLine();
      }

      // now compute the average
      int sum = 0;
   
      // sums up the grades in 'sum' 
      for (int i=0; i < count; i++ ) {
	 sum += grades[i];
      }
      float avg = (float) sum / (float) count;

      // Now print students and differences from average
      // builds up an output line in a StringBuffer
      for (int i=0; i < count; i++ ) {
	 StringBuffer line_out = new StringBuffer();
	 line_out.append (names[i]);
	 for (int j=names[i].length(); j < 20; j++)
	    line_out.append (" ");
	 line_out.append (grades[i]-avg);
	 System.out.println (line_out.toString());
      }
      
   } //main
}

	 
	 
	 

