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...
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
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)
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...
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……..
Write a complete MiniMIPS program that accepts a seqeunce of integers at input and after the...
Write a complete MiniMIPS program that accepts a seqeunce of integers at input and after the receipt of each new input value, displays the largest and smallest integers thus far. An input of 0 indicates the end of input values and is not an input value itself. Note that you do not need to keep all integers in memory.
In python, write a function, called ThreeSum, that accepts a list of non-negative numbers as input,...
In python, write a function, called ThreeSum, that accepts a list of non-negative numbers as input, and returns the highest sum of three neighboring elements in it. Write a main method that initializes the following five lists, gets the ThreeSum result for all of them using the above function, and prints the result to the screen. Example of the output: List 1: [4,5,4,5] , Three sum = 14 List 2: [7] , Three sum = 7 List 3: [ ]...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT