Answer:
This program is written in Java programming language.
It uses an array to store scores of each test.
And it also validates user input to allow only integers 0 to 10,
Because the program says the average should be calculated by excluding the highest and lowest scores, the average is calculated as follows;
Average = (Sum of all scores - highest - lowest)/(Total number of tests - 2).
The program is as follows (Take note of the comments; they serve as explanation)
import java.util.*;
public class CalcAvg
{
public static void main(String [] args)
{
Scanner inputt = new Scanner(System.in);
// Declare number of test as integer
int numTest;
numTest = 0;
boolean check;
do
{
try
{
Scanner input = new Scanner(System.in);
System.out.print("Enter number of test (1 - 10): ");
numTest = input.nextInt();
check = false;
if(numTest>10 || numTest<0)
check = true;
}
catch(Exception e)
{
check = true;
}
}
while(check);
int [] tests = new int[numTest];
//Accept Input
for(int i =0;i<numTest;i++)
{
System.out.print("Enter Test Score "+(i+1)+": ");
tests[i] = inputt.nextInt();
}
//Determine highest
int max = tests[0];
for (int i = 1; i < numTest; i++)
{
if (tests[i] > max)
{
max = tests[i];
}
}
//Determine Lowest
int least = tests[0];
for (int i = 1; i < numTest; i++)
{
if (tests[i] < least)
{
least = tests[i];
}
}
int sum = 0;
//Calculate total
for(int i =0; i< numTest;i++)
{
sum += tests[i];
}
//Subtract highest and least values
sum = sum - least - max;
//Calculate average
double average = sum / (numTest - 2);
//Print Average
System.out.println("Average = "+average);
//Print Highest
System.out.println("Highest = "+max);
//Print Lowest
System.out.print("Lowest = "+least);
}
}
//End of Program