I need this done in java Problem 1 (name this Lab4_Problem1) Use an outer if str
ID: 671003 • Letter: I
Question
I need this done in java
Problem 1 (name this Lab4_Problem1)
Use an outer if structure for validation, and a multiple-selection if structure inside one of the outer if block's paths to handle your core logic. Exam scores are based on 100 possible points. Determine the corresponding letter grade using the +/- grading scale found in the syllabus. The syllabus has lower and upper cutoffs for each letter grade; use the lower cutoff to build your code.
The algorithm follows:
Obtain a numeric score from the end user; note that fractional points may be awarded (e.g., 68.5 points).
Validate the input range for the score. Assume for this problem that any score greater than 100, or a score less than 0, is considered invalid data entry. Code accordingly to identify this out-of-range problem, and if so, display Invalid Data Entry; Range is 0 to 100 instead of the letter grade (see second example below). Otherwise, proceed with the remaining steps.
Using the most appropriate if structure, evaluate the percentage score and output it, along with the corresponding letter grade, A through F as shown in the sample output. Use as few statements as necessary consistent with class standards. Use the +/- grading scale shown in the syllabus.
Input capture dialog (acceptable range):
Enter score: 79
Output sample:
Score: 79
Letter grade equivalent: C+
Input capture dialog (out of range):
Exam score: 1297
Output sample:
Invalid Data Entry: Range is 0 to 100
Explanation / Answer
import java.io.*;
public class grade {
public static void main(String args[]) throws IOException{
System.out.println("Exam score: ");
//get input from the user
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
double mark = Double.parseDouble(br.readLine());
if (mark<0||mark>100)
System.out.println("Invalid Data Entry: Range is 0 to 100");
else
{
if(mark>=95&&mark<=100)
System.out.println("Letter grade equivalent: A+");
if(mark>=90&&mark<=94)
System.out.println("Letter grade equivalent: A");
if(mark>=85&&mark<=89)
System.out.println("Letter grade equivalent: B+");
if(mark>=80&&mark<=84)
System.out.println("Letter grade equivalent: B");
if(mark>=75&&mark<=79)
System.out.println("Letter grade equivalent: C+");
if(mark>=70&&mark<=74)
System.out.println("Letter grade equivalent: C");
if(mark>=65&&mark<=69)
System.out.println("Letter grade equivalent: D+");
if(mark>=60&&mark<=64)
System.out.println("Letter grade equivalent: D");
if(mark<40)
System.out.println("Letter grade equivalent: F");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.