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

Java program Write a program that will allow the user to enter 10 test scores in

ID: 3792340 • Letter: J

Question


Java program

Write a program that will allow the user to enter 10 test scores into a testScores array. Write separate methods to perform each of the following operations on the array.

a. Print the array

b. Find the avg of the scores and print it

c. Determine and print the numbers of scores higher and lower than the avg

Test with the following scores: 98.5, 60, 78, 85.5, 100, 74.5, 90.5, 55, 96, 83.5

This is what I have. Everything works I just need help with c

import java.util.*;

public class TestScores
{
static Scanner keyboard = new Scanner(System.in);

public static void main(String[]args)
{
//declare variables
double average = 0;
  
//declare arrays
double[] scores = new double[10];
  
//********print arrays
System.out.println("The test scores in the array are: ");
printArrayScores(scores);
  
  
//*****************load test scores into the array from the keyboard
for(int i = 0; i < scores.length; i++)
{
System.out.print(" Enter a test score for element " + i + ": ");
scores[i] = keyboard.nextDouble();
}//end for
  
//*************print with the scores array again with the values in it
System.out.println(" The new test scores are:");
printArrayScores(scores);
  
//****call the method that calculated the average
calcAverage(scores);
  
//*****call the method that prints how many numbers are highest and lowest than the avg
countHighestLowest(scores, average);//Problem here
  
  
}//end main

public static void printArrayScores(double[] scoreList)
{
for(int i = 0; i < scoreList.length; i++)
System.out.println("" + scoreList[i]);
System.out.println();
}// end printArrayScores

public double calcAverage(double[] scoreList)
{
double sum = 0;
double avg = 0;
  
for(int i = 0; i < scoreList.length; i++)
{
sum = sum + scoreList[i];
}
avg = sum /(double) (scoreList.length);

System.out.println("Average test score is: " + avg);
System.out.println();

return avg;
}//end calcAverage
  
//method to calculate how many numbers are lowest and highest than the average
public static void countHighestLowest(double[] scoreList)//this one is the problem
{
double higher = 0, lowest = 0;
  
for(int i = 0; i < scoreList.length; i++)
{
if(scoreList[i] % avg == 0)
higher++;
  
else if (scoreList[i] % avg == 1)
lowest++;
  


}//end for
  
System.out.println("The number of scores higher than the average: " + higher);
System.out.println();
System.out.println("The number of scores lower than the average: " + lowest);

  
}//end countHighestLowest
}//end class

Explanation / Answer

Note: I rectified the errors.I think no need to print the array elements before inserting elements.So I removed that part.Could you please check this output.Thank You.

____________________

TestScores.java

import java.util.*;
public class TestScores
{
static Scanner keyboard = new Scanner(System.in);

public static void main(String[]args)
{
//declare variables
double average = 0;
  
//declare arrays
double[] scores = new double[10];
  
//*****************load test scores into the array from the keyboard
for(int i = 0; i < scores.length; i++)
{
System.out.print(" Enter a test score for element " +(i+1) + ": ");
scores[i] = keyboard.nextDouble();
}//end for
  
//********print arrays
System.out.println("The test scores in the array are: ");
printArrayScores(scores);
  
  
//****call the method that calculated the average
average=calcAverage(scores);
  
//*****call the method that prints how many numbers are highest and lowest than the avg
countHighestLowest(scores, average);//Problem here
  
  
}//end main

public static void printArrayScores(double[] scoreList)
{
for(int i = 0; i < scoreList.length; i++)
System.out.println("" + scoreList[i]);
System.out.println();
}// end printArrayScores

public static double calcAverage(double[] scoreList)
{
double sum = 0;
double avg = 0;
  
for(int i = 0; i < scoreList.length; i++)
{
sum = sum + scoreList[i];
}
avg = sum /(double) (scoreList.length);

System.out.println("Average test score is: " + avg);
System.out.println();

return avg;
}//end calcAverage
  
//method to calculate how many numbers are lowest and highest than the average
public static void countHighestLowest(double[] scoreList,double avg)//this one is the problem
{
int higher = 0, lowest = 0;
  
for(int i = 0; i < scoreList.length; i++)
{
if(scoreList[i] > avg )
higher++;
  
else if (scoreList[i] < avg )
lowest++;
  


}//end for
  
System.out.println("The number of scores higher than the average: " + higher);
System.out.println();
System.out.println("The number of scores lower than the average: " + lowest);

  
}//end countHighestLowest
}//end class

__________________

output:


Enter a test score for element 1: 98.5

Enter a test score for element 2: 60

Enter a test score for element 3: 78

Enter a test score for element 4: 85.5

Enter a test score for element 5: 100

Enter a test score for element 6: 74.5

Enter a test score for element 7: 90.5

Enter a test score for element 8: 55

Enter a test score for element 9: 96

Enter a test score for element 10: 83.5
The test scores in the array are:
98.5
60.0
78.0
85.5
100.0
74.5
90.5
55.0
96.0
83.5

Average test score is: 82.15

The number of scores higher than the average: 6

The number of scores lower than the average: 4

_____________Thank You

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