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
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started