Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an application that displays a series of at least 10 student ID numbers (t

ID: 3719532 • Letter: W

Question

Write an application that displays a series of at least 10 student ID numbers (that you have stored in an array) and asks the user to enter a test letter grade for the student. Create an Exception class named GradeException that contains a static public array of valid grade letters (‘A’, ‘B’, ‘C’, ‘D’, ‘F’, and ‘I’) that you can use to determine whether a grade entered from the application is valid. In your application, throw a GradeException if the user does not enter a valid letter grade. Catch the GradeException, and then display an appropriate message. In addition, store an ‘I’ (for Incomplete) for any student for whom an exception is caught. At the end of the application, display all the student IDs and grades.

Note: This is for Java

Explanation / Answer

import java.util.Scanner;

public class Driver {

public static void main(String[] args) {

String ids[] = new String[10];

String grades[] = new String[10];

Scanner in = new Scanner(System.in);

for(int i = 0; i < 10; i++)

try {

System.out.println("Enter id of student " + (i + 1));

ids[i] = in.nextLine();

System.out.println("Enter grade of student " + (i + 1));

String grade = in.nextLine();

if(grades.equals("A")||grades.equals("B")||grades.equals("C")||grades.equals("D")||grades.equals("F"))

grades[i] = grade;

else

throw new GradeException("Invalid Grade");

}

catch(GradeException E) {

grades[i] = "I";

}

System.out.println(" Ids and Grades of the students are:");

for(int i = 0; i < 10; i++)

System.out.println(ids[i] + " " + grades[i]);

}

}

**Comment for any further queries.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote