Question: Help with java coding question ... Write a program that allows the user to enter students names followed by their test scores. Use an array

Help with java coding question ...

Write a program that allows the user to enter students names followed by their test scores. Use an array of String to store students names and an array of double to store their test scores. The program then outputs the following information (assume that there are 10 students total):

Each students name and the test score

Highest test score

The names of all the students having the highest score

Class average score

The names of all the students whose test scores are less than the class average

The names of all the students whose test scores are greater than or equal to the class average

-It outputs the students with scores lower/greater than & equal to the average, but it keeps looping. I also need help with finding the student that has the highest score and outputting that score. Thank you in advance.

1 import java.util.Scanner; 2 3 public class Grades{ 4 5 public static void main(String[] args){ 6 7 //create a keyboard representing the scanner 8 Scanner console = new Scanner(System.in); 9 10 //define variables 11 double [] score = new double[10]; 12 13 String [] name = new String[10]; 14 double average = 0.0, sum = 0.0, studentAverage = 0.0, highestScore = 0.0, lowestScore = 0.0; 15 16 17 for(int i= 0; i < score.length; i++){ 18 19 System.out.println("Enter the student's name: "); 20 name[i] = console.next(); 21 System.out.println("Enter the student's score: "); 22 score[i] = console.nextDouble(); 23 24 sum += score[i]; 25 26 }//end for loop 27 28 //calculate average 29 average = sum/score.length; 30 31 System.out.println("The average score is: " + average); 32 33 34 int highestIndex = 0; 35 36 for(int i = 1; i < score.length; i++){ 37 38 if(score[highestIndex] < score[i]){ 39 40 highestIndex = i; 41 42 } 43 44 45 if(score[i] < average){ 46 System.out.print(" Names of students whose test scores are less than average: " + name[i]); 47 } 48 49 if(score[i] >= average){ 50 System.out.print(" Names of students whose test scores are greater than or equal to average: " + name[i]); 51 } 52 53 54 }//end for loop 55 56 }//end main 57 }//end class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!