/home/caleb/ASDV-Java/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/IfElse4.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package com.calebfontenot.lab6_calebfontenot;
import java.util.Scanner;
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) {
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) {
double grade;
String ;
while (true) {
try {
grade = inputPrompt();
ifLogic(grade);
System.exit(0);
}
catch(Exception IllegalArgumentException) {
grade = inputPrompt();
ifLogic(grade);
}
}
}
}