Question

In: Computer Science

Design a modular program that accepts as input 20 numbers between 0 and 100 (including 0...

Design a modular program that accepts as input 20 numbers between 0 and 100 (including 0 and 100). The program should store the numbers in an array and then display the following information:

  • The lowest number in the array

  • The highest number in the array

  • The total of the numbers in the array

  • The average of the numbers in the array

Your program should consist of the following:

Module main. Accepts input of numbers and assigns them to an array. The array is traversed in order to find the highest number, lowest number, total and average of the numbers.

Module showStats. Displays the highest number, lowest number, total and average of the numbers.

Expected Input/Output

Please enter 20 numbers between 1-100:

64

93

12

45

85

.

.

.

27

43

2

The lowest number in the array is: 1

The highest number in the array is: 95

The total of the numbers in the array is: 811

The average of the numbers in the array is: 40.55

The solution should be in Java. Thank you

Solutions

Expert Solution

Program Code Screenshot :

Sample Output :

Program Code to Copy

import java.util.Scanner;

class Main{

    static int[] readInt(){
        //Read user input
        Scanner obj = new Scanner(System.in);
        int A[] = new int[20];
        //Read 20 integers
        System.out.println("Please enter 20 numbers between 1-100:");
        for(int i=0;i<20;i++){
            A[i] = obj.nextInt();
        }
        return A;
    }

    static void showStats(int A[]){
        //Initialize highest, lowest and total
        int highest = A[0];
        int lowest = A[0];
        int total = 0;
        for(int x : A){
            //Update highest, lowest and total
            highest = Math.max(highest,x);
            lowest = Math.min(lowest,x);
            total += x;
        }
        //Find average
        double avg = (total*1d)/A.length;
        System.out.println("The lowest number in the array is: "+lowest);
        System.out.println("The highest number in the array is: "+highest);
        System.out.println("The total of the numbers in the array is: "+total);
        System.out.println("The average of the numbers in the array is: "+avg);
    }

    public static void main(String[] args) {
        int A[] = readInt();
        showStats(A);
    }
}

Related Solutions

Design a modular program which asks the user to enter a list of numbers. The numbers...
Design a modular program which asks the user to enter a list of numbers. The numbers must be stored in an array. The program then finds the index of the first occurrence of the smallest element in the array and the last occurrence of the largest element in the array. The program displays the position and value of each of these items.
3. Write a program using switch-case statements that accepts an integer number between 0 and 100...
3. Write a program using switch-case statements that accepts an integer number between 0 and 100 and, based on its value, reports its equivalent letter grade (A, B, C, D, or F).
Write a Java program that creates an array with 20 random numbers between 1 and 100,...
Write a Java program that creates an array with 20 random numbers between 1 and 100, and passes the array to functions in order to print the array, print the array in reverse order, find the maximum element of the array, and find the minimum element of the array. The prototype of the methods: public static void printArray(int arr[]) public static void printArrayReverse(int arr[]) public static int searchMax(int arr[]) public static int searchMin(int arr[]) Sample output: Random Array: [17 67...
Design a program that will ask the user to input two integer numbers and then perform...
Design a program that will ask the user to input two integer numbers and then perform the basic arithmetic operations such as addition and subtraction. Each calculation is done by a separate function. The main function gets the input from the user, then calls the addition function and the subtraction function one at a time to perform the calculations. Each calculation function (addition or subtraction function) performs an arithmetic operation and then returns the calculation results back to where it...
Player 1 and Player 2 choose and integer between 0 and 100 (including 0 and 100)....
Player 1 and Player 2 choose and integer between 0 and 100 (including 0 and 100). Their choice is made simultaneously and independently. Suppose Player 1 chooses x and Player 2 chooses y. If x < y Player 1 obtains x and Player 2 obtains zero. Similarly, if y < x Player 2 obtains y and Player 1 obtains zero. If x = y then each one obtains x/2 = y/2. Find all pure strategy Nash equilibrium in this game.
Design the logic for a program that allows a user to enter 20 numbers, then displays...
Design the logic for a program that allows a user to enter 20 numbers, then displays them in the reverse order of entry. Design the logic for a program that allows a user to enter 20 numbers, then displays each number and its difference from the numeric average of the numbers entered. The program is C++. I need a Pseudocode
Design a complete program that asks the user to enter a series of 20 numbers. The...
Design a complete program that asks the user to enter a series of 20 numbers. The program should store the numbers in an array and then display each of the following data: I. The lowest number in the array II. The highest number in the array III. The total of the numbers in the array IV. The average of the numbers in the array *PYTHON NOT PSUEDOCODE AND FLOW CHART!!!!*
Write a program that accepts a string and character as input, then counts and displays the...
Write a program that accepts a string and character as input, then counts and displays the number of times that character appears (in upper- or lowercase) in the string. Use C++ Enter a string: mallet Enter a character: a "A" appears 1 time(s) Enter a string: Racecar Enter a character: R "R" appears 2 time(s)
Write a program in Python that will print first 100 numbers of the following series: 0,...
Write a program in Python that will print first 100 numbers of the following series: 0, 1, 1, 2, 3, 5, 8……..
Design a Python script that accepts as input a user-provided list and transforms it into a...
Design a Python script that accepts as input a user-provided list and transforms it into a different list in preparation for data analysis, the transformed list replaces each numeric element in the original list with its base-10 order of magnitude and replaces string elements with blanks. Example: This script accepts as input a user-provided list expected to contain non-zero numbers and strings. It then prints a transformed list replacing numbers with their order of magnitude, and strings as blanks. Type...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT