Question
JAVA Programming Requirements, Modify and edit from the given code. The numeric ranges for the different grade letters are store in an array or arraylist.
JAVA Programming Requirements,
- Modify and edit from the given code.
- The numeric ranges for the different grade letters are store in an array or arraylist.
- The corresponding grade letters are also in an array or arraylist.
- Any array are read-only meaning they are look-up array (the logic should not modify them
- Therefore, declare the array as a final static array.
- The handing of the invalid numeric value should display the same message.
- The output for the grade letter should look the same.
---------------------------------------------------------------------------------------------------------------------
//Given code
import java.util.*;
public class Main { public static void main(String[] args) {
//Get the user input Scanner sc = new Scanner(System.in);
//Loop while(true) { System.out.print("Enter your numeric grade (enter -1 to end the program): "); double grade = sc.nextDouble();
//End the program if user entered -1 if(grade == -1) { System.out.print("The program ended"); break; }
//validating the grade between 0 and 100 if(grade<0 || grade>100)//if user entered invalid input { while(true)//infinity loop to read input untill user enter valid input. { //Displaying error message. System.out.print("You entered inalid numeric grade."); System.out.print("Please enter valid numeric grade from 0-100: "); grade = sc.nextDouble(); //End the validating loop if user entered valid input. if(grade>=0 && grade<=100) { break; } } }
//Convert numeric grade to letter grade if(grade>=93 && grade<=100) System.out.print("Your grade letter is A. "); if(grade>=90 && grade<93) System.out.print("Your grade letter is A-. ");
else if(grade>=87 && grade<90) System.out.print("Your grade letter is B+. "); else if(grade>=83 && grade<87) System.out.print("Your grade letter is B. "); else if(grade>=80 && grade<83) System.out.print("Your grade letter is B-. ");
else if(grade>=73 && grade<80) System.out.print("Your grade letter is C+. "); else if(grade>=70 && grade<73) System.out.print("Your grade letter is C. ");
else if(grade>=60 && grade<70) System.out.print("Your grade letter is D. ");
else if(grade<60) System.out.print("Your grade is F. You are failed. "); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started