GradingProgram.java.html

  1  import java.util.Scanner;
  2  
  3  /**
  4     This program demonstrates the use of mock objects
  5     for testing.
  6  */
  7  public class GradingProgram
  8  {
  9     public static void main(String[] args)
 10     {
 11        IGradeBook gradeBook = new MockGradeBook();
 12        Scanner in = new Scanner(System.in);
 13        boolean done = false;
 14        while (!done) 
 15        {
 16           System.out.print("L)oad A)dd aV)erage S)ave Q)uit: ");
 17           String command = in.next().toUpperCase();
 18           if (command.equals("L")) 
 19           {
 20              System.out.print("Filename: ");
 21              String filename = in.next();
 22              gradeBook.load(filename);
 23           }
 24           else if (command.equals("S")) 
 25           {
 26              System.out.print("Filename: ");
 27              String filename = in.next();
 28              gradeBook.save(filename);
 29           }
 30           else if (command.equals("A")) 
 31           {
 32              System.out.print("ID: ");
 33              int id = in.nextInt();
 34              System.out.print("Score: ");
 35              double score = in.nextDouble();
 36              gradeBook.addScore(id, score);
 37           }
 38           else if (command.equals("V")) 
 39           {
 40              System.out.print("ID: ");
 41              int id = in.nextInt();
 42              System.out.println("Average for " + id + ": " 
 43                 + gradeBook.getAverageScore(id));
 44           }
 45           else if (command.equals("Q")) 
 46           {
 47              done = true;
 48           }         
 49        }
 50     }
 51  }