/*Student problem from the quiz
  Same as Student2.java, plus 
  made the addQuiz method more user-friendly 
    - illustrates simple standard input (via Scanner)
    - illustrates simple if statements and boolean expressions
    - added ability to remove quiz score if user messed up

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

  Note2: 
        With the current setup, some programs using this class may not work 
        (though the StudentMain3 does work).  This has to do with how Scanner 
        works, and is out of the scope of what we currently know.  If you try other 
        programs that use this class, and get weird errors, DON'T WORRY. */


import java.util.Scanner; //needed for std input

public class Student3 {

  //static variables
  private static final String className = "Student"; 
  private static int numStudents = 0;    

  private int numQuizzes;
  private int totalScore;
  private String name;



  //constructor
  public Student3(String name) {
    this.name = name;
    totalScore = 0; 
    numQuizzes = 0;
    addStudent();
  }

  //static methods

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

  public static int getNumStudents() {
    return numStudents;
  }

  public static void printClassName() {
    System.out.println("This is the class: " + className);
  }


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

  public int getTotalScore() {
    return totalScore;
  }

  public void addQuiz() {
    //notice i tell the user whose quiz score they're adding
    //conceptually, think about why this is done.

    System.out.println("Enter quiz score for " + name);

    int scoreToAdd = 0; //this is a local variable

    Scanner inScan = new Scanner(System.in);
    //grab the score
    scoreToAdd = inScan.nextInt(); 

    if(scoreToAdd < 0) {
      System.out.println("You entered a negative Score.");
      System.out.println("Is this a typo? Please enter score again.");

      scoreToAdd = inScan.nextInt();
      //if they still added negative score, we add zero
      //and print an angry message
        
      //this illustrates that you can "next" if's within if's
      if(scoreToAdd < 0) {
        System.out.println("Adding a score of zero!");
        //this line would be redundant: 
        //totalScore += 0;
      }
      else { //answer.equals("no")
        totalScore += scoreToAdd;
      } 
      //notice we still increase the number of quizzes for both options
      ++numQuizzes;
    }//score < 0
    else {
      totalScore += scoreToAdd; 
      ++numQuizzes;       
    }//added score
  }
  
  public double getAverageScore() {
    double result = (double)totalScore/numQuizzes; 
    return result;
  }
}
