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

Working with arrays Write a program that reads a number of scores into an array

ID: 3701139 • Letter: W

Question

Working with arrays Write a program that reads a number of scores into an array and determines how many scores are above or equal to the average. Assume that the maximum number of scores is 100 and that each score is a double value. Write a method that returns a double array using user's inputs from the console window. The method should have the following header. The formal parameter size is the size of the return array. 1. public static double[ inputScores (int size) Your input should be through the console. 2. Write a method that return the number of scores above or equal to the average. > public static int highScoreCount (double [ scores) Your program should contain the "main" method that invokes the inputScores and highScoreCount methods. The number of scores above or equal to the average should be displayed in the console window as the output of this program. 3. Please note: You must finish this work by the end of the lab period. If you do not finish, please just submit what you have at the end of the lab. Submission: Submit in folio your source code using the dropbox folder Lab 12.

Explanation / Answer


import java.util.Scanner;
public class WorkWithArrays {
public static double[] inputScores(int size)
{
Scanner sc= new Scanner(System.in);
double input[]= new double[size];
System.out.println("Enter double values:");
for(int i=0;i<size;i++)
{
if(sc.hasNext())
input[i]=sc.nextDouble();
}
return input;
}
public static int highScoreCount(double[] scores)
{
double sum=0d;
for(int i=0;i<scores.length;i++)
{
sum=sum+scores[i];
}
double avg=sum/scores.length;
int count=0;
for(int i=0;i<scores.length;i++)
{
if(scores[i]>=avg)
count++;
}
return count;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc= new Scanner(System.in);
System.out.println("Enter the size of array");
int size=sc.nextInt();
WorkWithArrays wa= new WorkWithArrays();
System.out.println("The number of scores above are equal to avg is :"+wa.highScoreCount(wa.inputScores(size)));
}
}

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