Write a JAVA program to calculate students average test scores and their grades.
ID: 3583876 • Letter: W
Question
Write a JAVA program to calculate students average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three arrays: a one-dimensional array to store the student names, a (parallel) twodimensional array to store the test score, and a parallel one-dimensional array to store grades. Your program must contain at least the following methods: a method to read and store data into two arrays, a method to calculate the average test score and grade and a method to output the results. Have your program also output the class average. Grade calculation to be computed as follows: Marks Grade 85-100 A 75-84 B 65-74 C 50-64 D <50 F
Explanation / Answer
import java.util.Scanner;
public class StudentGradeCheggTest {
public static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("enter how many members names you want to store");
int no = scanner.nextInt();
String[] names = new String[no];
String[] grades = new String[no];
for (int i = 0; i < no; i++) {
String name = null;
System.out.println("enter the name");
name = scanner.next();
names[i] = name;
}
int arr[][] = new int[no][5];
int count = 0;
System.out.println("enter the test scores");
for (int i = 0; i < arr.length; i++) {
System.out.println("enter the scores of student " + (++count));
for (int j = 0; j < 5; j++) {
int score = scanner.nextInt();
arr[i][j] = score;
}
System.out.println(" ");
}
for (int i = 0; i < arr.length; i++) {
int sum = 0;
double avg = 0;
String grade = null;
for (int j = 0; j < 5; j++) {
sum = sum + arr[i][j];
}
System.out.println("the total score of student ");
System.out.println(sum);
avg = sum / 5;
if (avg > 85) {
grade = "A";
grades[i] = grade;
} else if (avg >= 75 && avg < 85) {
grade = "B";
grades[i] = grade;
} else if (avg >= 65 && avg < 74) {
grade = "C";
grades[i] = grade;
} else if (avg >= 50 && avg < 65) {
grade = "D";
grades[i] = grade;
} else {
grade = "F";
grades[i] = grade;
}
System.out.println(" ");
System.out.println(grades[i]);
}
}
}
output
enter how many members names you want to store
3
enter the name
david
enter the name
lisa
enter the name
antony
enter the test scores
enter the scores of student 1
10
10
10
10
10
enter the scores of student 2
25
25
25
25
25
enter the scores of student 3
90
90
90
90
90
the total score of student
50
F
the total score of student
125
F
the total score of student
450
A
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.