// Guide to Java
// Copyright 2014, by J.T. Streib and T. Soma


// a program to find the distribution of the grades

import java.util.*;

class ClassGrades {
 public static void main(String[] args) {

    // declaration and initialization of variables
    Grades class1;
    int score;
    char letter;
    Scanner scanner;
    class1 = new Grades();
    scanner = new Scanner(System.in);
      
    // priming read
    System.out.print("Enter a score or -1 to stop: ");
    score = scanner.nextInt();

    if(score == -1)
       System.out.println("No scores were entered.");
    else {
       // loop to enter scores
       while(score != -1) {
          class1.enterGrade(score);
          System.out.print("Enter a score or -1 to stop: ");
          score = scanner.nextInt();
       }
     
       // print distribution and percent
       System.out.println();
       System.out.println("Grade     Distribution     Percent(%)");
       for(letter='A'; letter<'E'; letter++) {
          System.out.printf("%3c       %6d           %7.1f",
             letter, class1.getNumStudents(letter),
             class1.getPercent(letter));
          System.out.println();
       }
       System.out.printf("%3c       %6d           %7.1f",
          'F',class1.getNumStudents('F'),class1.getPercent('F'));
       System.out.println();
    }
 }
}

// definition of Grades class

class Grades {
 // data members
 private int numA, numB, numC, numD, numF, count;

 // constructor
 public Grades() {
    numA = 0;
    numB = 0;
    numC = 0;
    numD = 0;
    numF = 0;
    count = 0;
 }
  
 // methods
 public void enterGrade(int score) {
    if(score >= 0 && score <= 100) {
       count++;
       if(score < 60)
          numF++;
       else
          if(score < 70)
             numD++;
          else
             if(score < 80)
                numC++;
             else
                if(score < 90)
                   numB++;
                else
                   numA++;
    }    
 }
 
 public int getNumStudents(char grade) {
    int numStudents;
    switch(grade) {
       case 'A': numStudents = numA;
                 break;
       case 'B': numStudents = numB;
                 break;
       case 'C': numStudents = numC;
                 break;
       case 'D': numStudents = numD;
                 break;
       case 'F': numStudents = numF;
                 break;
       default:  numStudents = -1;            
    }
    return numStudents;
 }
  
 public double getPercent(char grade) {
    double percent;
    switch(grade) {
       case 'A': percent = 100.0*numA/count;
                 break;
       case 'B': percent = 100.0*numB/count;
                 break;
       case 'C': percent = 100.0*numC/count;
                 break;
       case 'D': percent = 100.0*numD/count;
                 break;
       case 'F': percent = 100.0*numF/count;
                 break;
       default:  percent = -1;            
    }
    return percent;
 }
}