/home/caleb/ASDV-Java/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse4.java
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.calebfontenot.lab6_calebfontenot;

import java.util.Scanner;

/**
 *
 * @author caleb
 */
public class IfElse4 {

    static double inputPrompt() {
        double grade;
        System.out.print("Enter your exam grade for it to be letter graded: ");
        grade = new Scanner(System.in).nextDouble();
        return grade;
    }    
    static void ifLogic(double grade) {
        // Use if else logic and output
        if (grade > 100) {
            System.out.println("Your grade seems too high, please try again...");
            throw new IllegalArgumentException("Invalid grade entered!");
        }
        else if ( grade > 90)
        {
            System.out.println("Congrats! You got a " + grade + ", which means you got an A!");
        }
        else if ( grade > 80)
        {
            System.out.println("Good job! You got a " + grade + ", which means you got a B!");
        }
        else if ( grade > 70)
        {
            System.out.println("Not bad, you got a " + grade + ", which means you got a C.");
        }
        else if ( grade > 60)
        {
            System.out.println("You got a " + grade + ", which means you got a D.");
        }
        else if (grade < 0) {
            System.out.println("Your grade seems too low, please try again...");
            throw new IllegalArgumentException("Invalid grade entered!");
        }
        else 
        {
            System.out.println("Sorry, you got a " + grade + ", so you unfortunately got an F.");   
        }
    }

    public static void main(String[] args) {
        // Setup variables
        double grade;
        String letterGrade;
        
        while (true) {  // Unintended behavior: This will only run twice. I intended this try and catch to run indefinately, but it only will catch once before terminating on its own.
            // Call ifLogic function
            try {
                // Prompt for input
                grade = inputPrompt();
                ifLogic(grade);
                System.exit(0);
        }
            catch(Exception IllegalArgumentException) { // ifLogic failed, try again...
                // Prompt for input
                grade = inputPrompt();
                ifLogic(grade);
        }
        }
    }

}