In: Computer Science
Instructions | |
Write a Java program that asks the user t enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program:
Score Letter Grade 90-100 A 80-89 B 70-79 C 60-69 D Below 60 F |
According to the problem statement above,
I have coded the function using Java
Below are the Snippets:
Code Snippet:
Output Snippet:
Code in Text format:
import java.io.*;
import java.util.*;
public class
demo
// class starts from here
{
public static double calcAverage(double a,
double b, double c,double d, double
e) //
method to calculate average
{
return (a + b + c + d +
e) /
5;
// returning the average
}
public static char determineGrade(double
g)
// method to determice Grade
{
if(g>=90 &&
g<=100)
// A between 90 and 100
{
return
'A';
}
else if(g>=80 &&
g<=90)
// B between 80 and 89
{
return
'B';
}
else if(g>=70 &&
g<=80)
// C between 70 and 79
{
return
'C';
}
else if(g>=60 &&
g<=70)
// D between 60 and 69
{
return
'D';
}
else
if(g<60)
// A less than 60
{
return
'F';
}
return 0;
}
public static void main(String[]
args)
// main method
{
Scanner z = new
Scanner(System.in);
// scanner to scan inputs
double num1 =
z.nextDouble();
// scanning 5 scores
double num2 =
z.nextDouble();
double num3 =
z.nextDouble();
double num4 =
z.nextDouble();
double num5 =
z.nextDouble();
double average =
calcAverage(num1, num2, num3, num4,
num5);
// passing scores to average
char grade =
determineGrade(average);
// passing average to grade
System.out.println("The
average of Scores is: "
+average);
// printing average
System.out.print("The
grade of Test Score is: "
+grade);
// printing grade
}
}
I hope the above snippets, information, and the explanation will help you out!
Please comment if you have any queries/errors!
Thank you!