
import java.util.Scanner;
/**
 * Creates math quiz with addition, subtraction, division, and multiplication. Also, allows the user to pick between two quiz types
 *
 * @James Coryea
 * @version (10/27/21)
 */
public class MathQuiz
{
    public static void main (String [] args)
   {
       Scanner Input = new Scanner (System.in);
       
       // Askes for quiz type
       System.out.println("Type 1 if you would like to answer a certian number of questions.");
       System.out.println("Type 2 if you would like to go until you get a certian number of questions wrong.");
       int choice = Input.nextInt();
       
       // Makes variables used inside of the quiz
       int guess;
       int answer;
       double incorrect = 0;
       int correct = 0;
       boolean userError = false;
       
       // Makes the quiz's
       if (choice == 1){
           // Askes the user how many questions they want
           System.out.println("How many questions would you like?");
           int numQue = Input.nextInt();
           
           // Uses "for" loop to ask as many questions the user wants 
           for (int i = 0 ; i< numQue ; i++){
            // Generates th numbers used in the equtions 
            int num1 = (int)(Math.random()*100);
            int num2 = (int)(Math.random()*100);
            
            // Generates either addition, subtraction, or multiplication problem
            int sign = (int)(Math.random()*3);
            if (sign == 0){
                System.out.println(num1+" + "+num2+" = ");
                guess =Input.nextInt();
                answer = num1 + num2;
            }
            else if (sign == 1){
                System.out.println(num1+" - "+num2+" = ");
                guess =Input.nextInt();
                answer = num1 - num2;
             }
            else {
                System.out.println(num1+" x "+num2+" = ");
                guess =Input.nextInt();
                answer = num1 * num2;
             }
            // Counts how many incorrect or correct answers the user gets
            if (guess != answer){
                incorrect = incorrect + 1;
            }
            if (guess == answer){
                correct = correct + 1;
            }
           }
           // Once loop finishes, displays statistics and what grade they got on the quiz
           double grade;
           grade = 100.0 - ((incorrect / numQue) * 100) ;
           System.out.println("Number of questions asked: "+numQue);
           System.out.println("Number of correct answers: "+correct);
           System.out.println("Number of incorrect answers: "+incorrect);
		   System.out.println("Grade Percentage: "+grade+"%");
           if (grade > 97.0){
               System.out.println("You scored a A+ on the test");
           }
           else if (grade >= 94.0){
               System.out.println("You scored an A on the test");
           }
           else if (grade >= 91.0){
               System.out.println("You scored a A- on the test");
           }
           else if (grade >= 88.0){
               System.out.println("You scored a B+ on the test");
           }
           else if (grade >= 84.0){
               System.out.println("You scored a B on the test");
           }
           else if (grade >= 80.0){
               System.out.println("You scored a B- on the test");
           }
           else if (grade >= 73.0){
               System.out.println("You scored a C on the test");
           }
           else if (grade >= 65.0){
               System.out.println("You scored a D on the test");
           }
           else{
               System.out.println("You scored a F on the test");
           }
         }
        else if (choice == 2) {
           // Askes the user how many attempts they want
           System.out.println("How many questions can you get wrong?");
           int attempts = Input.nextInt();
           
           // More variables Used in the quiz
           int attemptsLeft = attempts;
           int right = 0;
           boolean done = false;
           
           // Uses "while" loop to ask unlimited questions until the user uses all of their attempts
           while (done == false){
            // Generates th numbers used in the equtions
            int num1 = (int)(Math.random()*100);
            int num2 = (int)(Math.random()*100);
            
            // Generates either addition, subtraction, or multiplication problem
            int sign = (int)(Math.random()*3);
            if (sign == 0){
                System.out.println(num1+" + "+num2+" = ");
                guess =Input.nextInt();
                answer = num1 + num2;
            }
            else if (sign == 1){
                System.out.println(num1+" - "+num2+" = ");
                guess =Input.nextInt();
                answer = num1 - num2;
             }
            else {
                System.out.println(num1+" x "+num2+" = ");
                guess =Input.nextInt();
                answer = num1 * num2;
             }
            if (answer != guess){
                System.out.println("You are inncorect!");
                attemptsLeft = attemptsLeft - 1;
            }
            if (answer == guess){
                right = right + 1;
            }
            if (attemptsLeft == 0) {
                System.out.println("You have run out of attempts!");
                done = true;
            }
           }
           // Once loop finishes, displays statistics and what grade they got on the quiz
           double grade;
           double total = right + attempts;
           grade = 100.0 - ((attempts / total) * 100) ;
           System.out.println("Number of questions asked: "+total);
           System.out.println("Number of correct answers: "+right);
           System.out.println("Number of incorrect answers: "+attempts);
		   System.out.println("Grade Percentage: "+grade+"%");
           if (grade > 97.0){
               System.out.println("You scored a A+ on the test");
           }
           else if (grade >= 94.0){
               System.out.println("You scored an A on the test");
           }
           else if (grade >= 91.0){
               System.out.println("You scored a A- on the test");
           }
           else if (grade >= 88.0){
               System.out.println("You scored a B+ on the test");
           }
           else if (grade >= 84.0){
               System.out.println("You scored a B on the test");
           }
           else if (grade >= 80.0){
               System.out.println("You scored a B- on the test");
           }
           else if (grade >= 73.0){
               System.out.println("You scored a C on the test");
           }
           else if (grade >= 65.0){
               System.out.println("You scored a D on the test");
           }
           else{
               System.out.println("You scored a F on the test");
           }
       }
       else {
           System.out.println("You need to pick either 1 or 2, please try again");
           System.out.println(" ");
           userError = true;
       }
       // Loops the entire thing again if user did not put 1 or 2
       while (userError == true){
        System.out.println("Type 1 if you would like to answer a certian number of questions.");
        System.out.println("Type 2 if you would like to go until you get a certian number of questions wrong.");
        int choice2 = Input.nextInt();
           if (choice2 == 1){
           System.out.println("How many questions would you like?");
           int numQue = Input.nextInt();
           for (int i = 0 ; i< numQue ; i++){
            // Variables 
            int num1 = (int)(Math.random()*100);
            int num2 = (int)(Math.random()*100);
            //Makes Symbol
            int sign = (int)(Math.random()*3);
            
            if (sign == 0){
                System.out.println(num1+" + "+num2+" = ");
                guess =Input.nextInt();
                answer = num1 + num2;
            }
            else if (sign == 1){
                System.out.println(num1+" - "+num2+" = ");
                guess =Input.nextInt();
                answer = num1 - num2;
             }
            else {
                System.out.println(num1+" x "+num2+" = ");
                guess =Input.nextInt();
                answer = num1 * num2;
             }
            if (guess != answer){
                incorrect = incorrect + 1;
            }
            if (guess == answer){
                correct = correct + 1;
            }
           }
           double grade;
           grade = 100.0 - ((incorrect / numQue) * 100) ;
           System.out.println("Number of questions asked: "+numQue);
           System.out.println("Number of correct answers: "+correct);
           System.out.println("Number of incorrect answers: "+incorrect);
		   System.out.println("Grade Percentage: "+grade+"%");
           if (grade > 97.0){
               System.out.println("You scored a A+ on the test");
           }
           else if (grade >= 94.0){
               System.out.println("You scored an A on the test");
           }
           else if (grade >= 91.0){
               System.out.println("You scored a A- on the test");
           }
           else if (grade >= 88.0){
               System.out.println("You scored a B+ on the test");
           }
           else if (grade >= 84.0){
               System.out.println("You scored a B on the test");
           }
           else if (grade >= 80.0){
               System.out.println("You scored a B- on the test");
           }
           else if (grade >= 73.0){
               System.out.println("You scored a C on the test");
           }
           else if (grade >= 65.0){
               System.out.println("You scored a D on the test");
           }
           else{
               System.out.println("You scored a F on the test");
           }
           userError = false;
         }
        else if (choice2 == 2) {
           System.out.println("How many questions can you get wrong?");
           int attempts = Input.nextInt();
           int attemptsLeft = attempts;
           int right = 0;
           boolean done = false;
           while (done == false){
            // Variables 
            int num1 = (int)(Math.random()*100);
            int num2 = (int)(Math.random()*100);
            //Makes Symbol
            int sign = (int)(Math.random()*3);
            
            if (sign == 0){
                System.out.println(num1+" + "+num2+" = ");
                guess =Input.nextInt();
                answer = num1 + num2;
            }
            else if (sign == 1){
                System.out.println(num1+" - "+num2+" = ");
                guess =Input.nextInt();
                answer = num1 - num2;
             }
            else {
                System.out.println(num1+" x "+num2+" = ");
                guess =Input.nextInt();
                answer = num1 * num2;
             }
            if (answer != guess){
                System.out.println("You are inncorect!");
                attemptsLeft = attemptsLeft - 1;
            }
            if (answer == guess){
                right = right + 1;
            }
            if (attemptsLeft == 0) {
                System.out.println("You have run out of attempts!");
                done = true;
            }
           }
           double grade;
           double total = right + attempts;
           grade = 100.0 - ((attempts / total) * 100) ;
           System.out.println("Number of questions asked: "+total);
           System.out.println("Number of correct answers: "+right);
           System.out.println("Number of incorrect answers: "+attempts);
		   System.out.println("Grade Percentage: "+grade+"%");
           if (grade > 97.0){
               System.out.println("You scored a A+ on the test");
           }
           else if (grade >= 94.0){
               System.out.println("You scored an A on the test");
           }
           else if (grade >= 91.0){
               System.out.println("You scored a A- on the test");
           }
           else if (grade >= 88.0){
               System.out.println("You scored a B+ on the test");
           }
           else if (grade >= 84.0){
               System.out.println("You scored a B on the test");
           }
           else if (grade >= 80.0){
               System.out.println("You scored a B- on the test");
           }
           else if (grade >= 73.0){
               System.out.println("You scored a C on the test");
           }
           else if (grade >= 65.0){
               System.out.println("You scored a D on the test");
           }
           else{
               System.out.println("You scored a F on the test");
           }
           userError = false;
        }
        else {
           System.out.println("You need to pick either 1 or 2, please try again");
           System.out.println(" ");
        }
       }
   }
}