/*Student problem from the quiz
  Same as Student1.java, plus 
  added illustration of static fields and static methods
  added illustration (brief) of final

  Note: the usage of className and getClassName() is standard,
        and you should be able to understand it.

        the usage of numStudents (and getNumStudents()) is a bit more
        advanced, but you might try to figure out why this might be useful

  Note 2: This assumes you "know" the Student details, so I have removed
          the "make sure you know" notes that were in Student1

*/

public class Student2 {

  //static fields

  //this class is always called "Student" so we use the final keyword
  private static final String className = "Student"; 

  //this variable will record how many Student objects there
  private static int numStudents = 0;    


  //instance fields 
  private int numQuizzes;
  private int totalScore;
  private String name;

  //constructors
  public Student2(String name) {
    this.name = name;
    totalScore = 0;
    numQuizzes = 0;

    //ADDED THIS LINE
    addStudent();
  }


  //static methods
  public static void addStudent() {
    numStudents++;
  }

  public static int getNumStudents() {
    return numStudents;
  }

  public static String getClassName() {
    return className;
  }


  //instance methods
  public String getName() {
    return name;
  }

  public int getTotalScore() {
    return totalScore;
  }

  public void addQuiz(int score) {
    totalScore += score; 
    ++numQuizzes;        
  }
  
  public double getAverageScore() {
    double result = (double)totalScore/numQuizzes; 
    return result;
  }
}
