Question
package E11; import java.util.Scanner; public class tringal { public static void main(String[] args) { //Scanner for user input Scanner sc = new Scanner(System.in); //Prompt for
package E11; import java.util.Scanner;
public class tringal { public static void main(String[] args) { //Scanner for user input Scanner sc = new Scanner(System.in); //Prompt for user input System.out.print("Enter a Letter grade: "); char lg = sc.next().charAt(0); //Call method print result System.out.println("The quality points " + qualityPoints(lg));
} //Required method private static double qualityPoints(char lg) {
if (lg == 'A') return 3.75; else if (lg == 'B') return 3; else if (lg == 'C') return 2; else if (lg == 'D') return 1; else }
java
Please add the catch method.
Objectives: In this lab, the following topic will be covered: 1. Exception Handling Task Write a method that returns quality points for a letter grade if it is valid and throws invalid exception otherwise. Write a test program that prompts the user to enter a letter grade and displays the quality points, as presented in the following sample run: Enter a letter grade: A The quality points 3.75 Enter a letter grade: The quality points 2.0 Enter a letter grade: X Invalid gradeStep 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