import java.io.*;

// Program processes a student's record and decides the
// student's status in the following session.
class Grade {

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

      BufferedReader stdin = new BufferedReader
         (new InputStreamReader(System.in));

      // These variables should be commented!
      int maxCourses, mark;
      String currentSession, name, studentNumber, course, status;
      String courseSession;
      double total = 0.0, sessionTotal = 0.0;
      double countCourses = 0.0, countSession = 0.0;
      double average, sessionalAverage, weight, weightedMark;

      // read student info
      System.out.println ("Enter current session: ");
      currentSession = stdin.readLine();
      System.out.println ("Enter student name: ");
      name = stdin.readLine();
      System.out.println ("Enter student number: ");
      studentNumber = stdin.readLine();
      System.out.println ("Enter number of marks: ");
      maxCourses = Integer.parseInt(stdin.readLine());

      // process each course, reading in the course code, mark,
      // and session.  Keep track of sums to calculate average.
      for (int count = 1; count <= maxCourses; count++) {

         // read course info
         System.out.println ("Enter course code: ");
         course = stdin.readLine();
         System.out.println ("Enter mark: ");
         mark = Integer.parseInt(stdin.readLine());
         System.out.println ("Enter session: ");
         courseSession = stdin.readLine();

         // decide course weight
         if (MoreHelp.fullcourse(course)) {
            weight = 1;
            weightedMark = mark;
         } else {
            weight = 0.5;
            weightedMark = mark/2.0;
         }

         // accumulate totals
         if (currentSession.equals(courseSession)) {
            countSession+=weight;
            sessionTotal+=weightedMark;
         }
         countCourses+=weight;
         total+=weightedMark;
      }

      // Report error if no courses entered
      if (countCourses == 0) {
         System.out.println ("No courses were entered for this student.");
      }
      else {
         // calculate cumulative average
         average = total/countCourses;

         // calculate sessional average
         if (countSession == 0) {
            System.out.println ("Student has no marks for this session.");
         }
         else {
            sessionalAverage = sessionTotal/countSession;
         }

         // read current status
         System.out.println ("Enter current status: ");
         status = stdin.readLine();

         // output results
         System.out.println("Student: " + name);
         System.out.println("Student number: " + studentNumber);
         System.out.println("Their cumulative average is " +
                Helper.twoDecPlaceString(average));
         System.out.println("Their sessional average is " +
                Helper.twoDecPlaceString(sessionalAverage));
         System.out.println("Their new status is " +
                MoreHelp.newStatus(status,average,sessionalAverage));
      }
   }
}

