Answer to Question #95659 in Java | JSP | JSF for Jabu

Question #95659
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) twodimensional array to store the test score, and a parallel one-dimensional array to store grades. Your program must contain a function to read and store data, function to calculate largest , function to calculate average grade and test scores and a function to output the results and function for the best student.
1
Expert's answer
2019-10-02T08:04:21-0400

import java.util.stream.IntStream;


public class Question {


public static void main(String[] args) {

String[] name = { "Johnson", "Aniston", "Cooper", "Gupta", "Blair", "Clark", "Kennedy", "Bronson", "Sunny",

"Smith" };

int[][] scores = { { 85, 83, 77, 91, 76 }, { 80, 90, 95, 93, 48 }, { 78, 81, 11, 90, 73 },

{ 92, 83, 30, 69, 87 }, { 23, 45, 96, 38, 59 }, { 60, 85, 45, 39, 67 }, { 77, 31, 52, 74, 83 },

{ 93, 94, 89, 77, 97 }, { 79, 85, 28, 93, 82 }, { 85, 72, 49, 75, 63 } };

printResults(name, scores);

calculateEachAverrage(name, scores);

findBestStudent(name, scores);

}


public static void printResults(String[] name, int[][] scores) {

for (int i = 0; i < name.length; i++) {

System.out.print(name[i]);

for (int j = 0; j < scores.length; j++) {

for (int j2 = 0; j2 < scores[j].length; j2++) {


System.out.printf("%4d", scores[j][j2]);

}

System.out.println();

}


}

}


public static void calculateEachAverrage(String[] names, int scores[][]) {


for (int i = 0; i < scores.length; i++) {

for (int g = 0; g < scores[i].length; g++) {

System.out.print(scores[i][g] + " ");

}

int avg = (int) IntStream.of(scores[i]).average().getAsDouble();


System.out.println("The avarage is: " + avg);

System.out.println();

}

}


public static void findBestStudent(String[] names, int scores[][]) {

int averages[] = new int[10];

int avg = 0;

for (int i = 0; i < scores.length; i++) {

for (int g = 0; g < scores[i].length; g++) {

}

avg = (int) IntStream.of(scores[i]).average().getAsDouble();

for (int j = 0; j < averages.length; j++) {

averages[j] = avg;

}

}


int maxValue = 0;

int indexMaxValue = 0;

for (int i = 0; i < averages.length; i++) {

if (maxValue < averages[i]) {

maxValue = averages[i];

indexMaxValue = i;


}

}

for (int i = 0; i < names.length; i++) {

if (i == indexMaxValue) {

System.out.println(names[i] + " has value: " + maxValue);

}

}

}

}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS