In: Computer Science
Java programming
Question1 You will create a full program called LetterGrade that will have the user enter in 2 test scores as double values. It will compute the average and then using else..if statements it will display the letter grade based on my grading scale listed in the course outline.
This problem statement inputs two test scores and calculate the average of those score. Then based on average, it displays the grade using else.. if . Since grading scale is not given in the question, So I have assumed some grading scales i.e. scores above 80 - Grade A, scores between 60 and 80 - Grade B, scores below 60 - Grade C. I have assumed these grades. You may change these grades as per grading scale listed in your course outline.
//Code starts here
/******************************************************************************
Java programming
Question1 You will create a full program called LetterGrade that
will have the user enter in 2 test scores
as double values. It will compute the average and then using
else..if statements it will display the
letter grade based on my grading scale listed in the course
outline.
*******************************************************************************/
import java.util.Scanner;
public class LetterGrade
{
public static void main(String[] args) {
//variables to store two test scores and average
double
firstTest,secondTest,average;
//Class to get user input
Scanner in = new
Scanner(System.in);
//variable to store grade
char grade;
//Enter first test score
System.out.println("Enter first
test score");
firstTest = in.nextDouble();
//Enter second test score
System.out.println("Enter second
test score");
secondTest = in.nextDouble();
//Calculate average of two
scores
average = (firstTest +
secondTest)/2;
// Since the grade scale is not
given in question, I have assumed that the grade above 80 score is
A.
//The grade between 60 and 80 is
B.
//The grade below 60 is C.
System.out.println("The average of
two scores: "+average); //Display average of two scores
//the grade above 80 score is
A
if(average >= 80){
grade = 'A';
}
//The grade between 60 and 80 is
B.
else if(average >= 60 &&
average <80){
grade = 'B';
}
//The grade below 60 is C.
else{
grade = 'C';
}
//Display grade
System.out.println("The grade is :
"+grade);
}
}
//Code ends here
Output