// Asst 1: a solution for Assignment 1, CSC108S, spring 1998

import java.io.*;

// Class Asst1 contains a main method that is used to read in
// marks for a student and to summarize mark information.
public class Asst1 {

   // Main method to read in course marks and to print a summary.
   public static void main(java.lang.String[] args) throws IOException {

      DataInputStream stdin = new DataInputStream (System.in);
      final String LISTENDER = "XXX";  // flag to signal end of input
      final int PASSMARK = 50;         // Marks lower than this fail
      
      // Read the student's name and number.
      System.out.println ("Student name? ");
      String name = stdin.readLine();
      System.out.println ("Student number? ");
      String number = stdin.readLine();  // (could be int or String)
      
      int numMarks = 0;            // Count Number of Marks
      int numFailures = 0;         // Count Number of Failing Marks
      int sum = 0;                 // Sum of Marks

      // Loop to read grades until user enters sentinel number 
      while (true) {
         // Read in course name and check for sentinel number
         System.out.println ("Next course name?");
         String course = stdin.readLine();
         if (course.equals(LISTENDER))    // Exit if sentinel number read
            break;

         // Read in next mark and update counters
         System.out.println ("Mark for this course?");
         int mark = Integer.parseInt(stdin.readLine());
         numMarks = numMarks + 1; // or numMarks += 1; or numMarks++;
         sum = sum + mark;
         if (mark < PASSMARK)
            numFailures += 1;
      }   
      
      // Print the summary.
      System.out.println ("\nSummary of record for student " + name + 
                          " (student number " + number + ")");
      if (numMarks == 0)
         System.out.println ("\n    No marks read!");
      else {
         double average = (double) sum/numMarks;
         int intAverage = (int) (average + 0.5);
         System.out.println ("\n    Average = " + intAverage);
         System.out.println ("\n    Number of failures: " + numFailures);
      }   
   }
}
