In: Computer Science
write a Java program
Write a program to assign a letter grade according to the
following scheme:
A: total score >= 90
B: 80 <= total score < 90
C: 70 <= total score < 80
D: 60 <= total score < 70
F: total score < 60
Output - the student's total score (float, 2 decimals) and letter
grade
Testing - test your program with the following input data:
test1 = 95; test2 = 80; final = 90; assignments = 80
The expected output is: score = 86.25 and letter grade =
B.
import java.util.Scanner;
public class TestPerson {
public static void main(String[] args) {
System.out.println("Enter scores: ");
Scanner sc = new Scanner(System.in);
double test1=sc.nextDouble();
double test2=sc.nextDouble();
double finalSc=sc.nextDouble();
double assignment=sc.nextDouble();
double total = (test1 + test2 + finalSc+assignment)/4;
System.out.printf("score = %.2f\n",total);
System.out.println("letter grade = "+getGrade(total));
}
private static String getGrade(double n) {
if(n>=90) return "A";
if(n>=80) return "B";
if(n>=70) return "C";
if(n>=60) return "D";
return "F";
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME