Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help in qns (chp9 qns 13) In Java Write a program to calculate students ave

ID: 3762708 • Letter: N

Question

Need help in qns (chp9 qns 13) In Java

Write a 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) two-dimensional 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.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

/**
* Main class
*
*/
public class AverageScoreandGrade {

/**
* @param args */
public static void main(String[] args) throws IOException{
//one-dimensional array to store the student name
String StuNames[] = new String[5];
//(parallel) two- dimensional array to store the test score
int tstscores[][] = new int[5][5];
//a parallel one-dimensional array to store grades
char storeGrades[] = new char[5];
//read data from file
int totalStudents = read(StuNames, tstscores);
print(totalStudents, StuNames, tstscores);
}

/**
* Read students from file students.txt */
public static int read(String StuNames[], int tstscores[][])throws IOException {
BufferedReader br = null;
int counter = 0;
  
String fileLine;
br = new BufferedReader(new FileReader("D://students.txt"));
while ((fileLine = br.readLine()) != null) {
//get name from file
try{
StuNames[counter] = fileLine.split(" ")[0];
  
//get score 1 from file
tstscores[counter][0] = Integer.parseInt(fileLine.split(" ")[1]);
//get score 2 from file
tstscores[counter][1] = Integer.parseInt(fileLine.split(" ")[2]);
//get score 3 from file
tstscores[counter][2] = Integer.parseInt(fileLine.split(" ")[3]);
//get score 4 from file
tstscores[counter][3] = Integer.parseInt(fileLine.split(" ")[4]);
//get score 5 from file
tstscores[counter][4] = Integer.parseInt(fileLine.split(" ")[5]);
counter++;
}
catch(Exception e)
{
//e.printStackTrace();
}
}

return counter;
}

/**
*calculate the average test score
*@return
*/
public static double calculateAverageTestScore(int tstscores[][], int studentIndex) {
double sum = 0;
for (int s = 0; s < 5; s++) {
//calculate total sum of scores of selected student
sum += tstscores[studentIndex][s];
}
return sum / 5;
}

/**
*getGrade
*@param averageTestScore
*@return
*/
public static char getGrade(double averageTestScore) { //85 - 100 A
if (averageTestScore >= 85) {
return 'A';
}
//75 - 84 B
if (averageTestScore >= 75) {
return 'B';
}
//65- 74 C
if (averageTestScore >= 65) {
return 'C';
}
//50 - 64 D
if (averageTestScore >= 50) {
return 'D';
}
//<50 F
return 'F';
}

/***
*calculate Class Average
*@param tstscores
*@return
*/
public static double calculateClassAverage(int tstscores[][]) {
double sum = 0;
for (int i = 0; i < 5; i++) {
for (int s = 0; s < 5; s++) {
//calculate total sum of all scores sum+=tstscores[i][s];
}
}
return sum / 25;
}

  
public static void print(int totalStudents, String StuNames[], int tstscores[][]) {
//display information
for (int i = 0; i < totalStudents; i++) {
System.out.print(StuNames[i] + ": ");
for (int s = 0; s < 5; s++) {
System.out.print(tstscores[i][s] + " ");
}
//calculate average Test Score
double averageTestScore = calculateAverageTestScore(tstscores, i);
//display averageTestScore
System.out.println(" average test score: " + averageTestScore + " grade: " + getGrade(averageTestScore));
}

}
}

output

run:
Johnson: 85 83 77 91 76 average test score: 82.4 grade: B
Aniston: 80 90 95 93 48 average test score: 81.2 grade: B
Cooper: 78 81 11 90 73 average test score: 66.6 grade: C
Gupta: 92 23 30 69 87 average test score: 60.2 grade: D
Blair: 23 45 96 38 59 average test score: 52.2 grade: D
BUILD SUCCESSFUL (total time: 0 seconds)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote