Ask Question

Write a program that accepts any number of homework scores ranging in value from 0 through

10. Prompt the user for a new score if they enter a value outside of the specified range. Prompt

the user for a new value if they enter an alphabetic character. Store the values in an array.

Calculate the average excluding the lowest and highest scores. Display the average as well as the

highest and lowest scores that were discarded.

+4
Answers (1)
  1. 26 August, 22:42
    0
    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

    catch (Exception e)

    {

    check = true;

    }

    }

    while (check);

    int [] tests = new int[numTest];

    //Accept Input

    for (int i = 0; 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
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program that accepts any number of homework scores ranging in value from 0 through 10. Prompt the user for a new score if they ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers