1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Arturiano [62]
3 years ago
7

Write a program that reads a stream of integers from the console and stores them in an array. The array is then analyzed to comp

ute the average of all the values in the array and finally all of the values that are above the average should be printed out to the screen. Specifically, you must write three methods: main(), readIntoArray(), and printAboveAverage(). main() creates a scanner, as well as an array of 100 integers, and outputs a message to the screen asking for a sequence of numbers.
readIntoArray() is then called to read values from the scanner and store them in the array. It must be passed two arguments: the scanner and the array. You should only store as many integers as the array can handle. Note, however, that there might be fewer than 100 values typed at the console – store whichever is fewer. This method must return how many integers, up to the length of the array, were read into the array. The hasNextInt() method of the scanner will be useful to determine if there are additional integers to read from the console. Additionally, when you are testing your code in Eclipse, and are done typing integers, press enter (i.e. to proceed to a new line) and then press CTRL+D to indicate to Eclipse that you are done typing (this is code for EOF, or end-of-file). Finally, printAboveAverage() should be called to read through the array, compute the average, and then print out all values in the array that are above the average. In particular, for each value above the average it should print the index in the array, as well as the value itself.

printAboveAverage() should take two arguments: the array and the actual number of values in the array. Note that this second argument is not the total number of elements that the array can hold, but is instead the number of values that are valid (i.e. populated in the readIntoArray() method). For example, the array should be able to hold up to 100 values, but there might have only been 15 values typed at the console. You have been supplied JUnit tests for the two methods, as well as the output for several example input sequences.
Computers and Technology
1 answer:
den301095 [7]3 years ago
6 0

Answer:

See explaination for Program source code.

Explanation:

Program source code below.

/Import the required package.

import java.util.Scanner;

//Define the class AboveAverageArray.

public class AboveAverageArray

{

//Start the execution of the main() method.

public static void main(String[] args)

{

//Create an object of scanner class.

Scanner sc = new Scanner(System.in);

//Declare and create an array of 100 integers.

int[] arr = new int[100];

//Call the method readIntoArray() and store the

//returned value into the variable countOfInt.

int countOfInt = readIntoArray(arr, sc);

//Call the method printAboveAverag() to print the

//values of the array above average value.

printAboveAverage(arr, countOfInt);

}

//Define the method printAboveAverage().

public static void printAboveAverage(int[] array, int

countOfArr)

{

//Declare the required variables.

double sumOfValues = 0;

//Calculate the sum of elements of the array.

for (int i = 0; i < countOfArr; i++)

sumOfValues += array[i];

//Calculate the average of the elements of the

//array.

double avgOfArr = sumOfValues/countOfArr;

//Display the elements which are above the

//average.

System.out.print("The elements above ");

System.out.println("average "+avgOfArr +

" are:");

for (int i = 0; i < countOfArr; i++)

{

//Check if the current element is greater than

//average or not.

if(array[i] > avgOfArr)

//Display the element with the current

//index.

System.out.println("Array["+i+"]"+" = " +

array[i]);

}

}

//Define the method readIntoArray().

public static int readIntoArray(int[] arrOfInt,

Scanner sc)

{

//Declare teh required variables.

int num_values = 0;

//Prompt the user to enter the values of the

//array till the user press CTRL+D.

System.out.print("Enter the elements of ");

System.out.println("the array: ");

//Start the try/catch block.

try

{

//Start the while loop till the scanner has

//a integer input and the number of elements

//in the array is less than 100.

while(sc.hasNextInt() || num_values <

arrOfInt.length)

{

arrOfInt[num_values] = sc.nextInt();

num_values++;

}

}

//Catch block.

catch (Exception e)

{}

//Return the number of elements in the array.

return num_values;

}

}

You might be interested in
The _____ constraint assigns a value to an attribute when a new row is added to a table
bixtya [17]

The default constraint gives a value to an attribute when a new row is added to a table.

<h3>Is default a kind of constraint?</h3>

This is known to be a type of constraint that often apply a value to a column if an INSERT statement does not really give the value for the column.

Therefore, one can say that the default constraint gives a value to an attribute when a new row is added to a table.

Learn more about default constraint from

brainly.com/question/19130806

#SPJ12

5 0
2 years ago
WHAT IS SQL AND HOW CAN YOU MEET THE DATA REQUIREMENTS ALSO MAINTAINING DATA INTEGRITY,AND LASTLY STATE THE FULL MEANING OF SQL
castortr0y [4]
SQL stands for Structured Query Language, it is a standard query language that is used in a computer usually used for manipulation of data in a system through its database management by using its query codes or commands. It is widely used in database management and manipulation because it use a CRUD query method or Create, Update, Delete and Insert of data in the database.
5 0
4 years ago
You have been hired as a security administrator. While analyzing your organization's personnel policies, you notice the presence
Lorico [155]

To deal with presence of multiple orphaned accounts as a security administrator in an organization, the user accounts should be disabled.

<h3>What is orphaned accounts?</h3>

The orphaned accounts are the accounts which do not have any valid business owner but provide the access to the services and corporate systems. One best way to deal with such account is to disable the user account.

Steps to deal with orphaned accounts-

  • Using the automated provisioning and deprovisioning can save the
  • Control the accounts with micro-certification.
  • Regular check of account to prevent the hidden access risk.

You have been hired as a security administrator. While analyzing your organization's personnel policies, you notice the presence of multiple orphaned accounts.

In such case, one should disable these accounts.

Thus, to deal with presence of multiple orphaned accounts as a security administrator in an organization, the user accounts should be disabled.

Learn more about the orphaned accounts here:

brainly.com/question/11211623

#SPJ1

8 0
2 years ago
Projects used for print and web have different ?
mr Goodwill [35]

Answer:

Sizes

Explanation:

6 0
4 years ago
The "origin" of the cartesian plane in math is the point where x and y are both zero. Given a variable, origin of type Point-- a
Sergeeva-Olga [200]

Answer:

  1. #include <iostream>
  2. using namespace std;
  3. struct Point{
  4.    double x;
  5.    double y;
  6. };
  7. int main()
  8. {
  9.    Point origin;
  10.    origin.x = 0;
  11.    origin.y = 0;
  12.    return 0;
  13. }

Explanation:

The solution code is written in C++.

Firstly, we create a data structure Point with two fields, x and y (Line 5 -8).

In the main program, declare an origin object with Point type (Line 12).

Set the x and y fields of origin object to zero using dot syntax (Line 13-14).

3 0
4 years ago
Other questions:
  • 3.A customer has a system with a Gigabyte B450 Aorus Pro motherboard. He wants to upgrade the processor from the AMD Athlon X4 9
    11·1 answer
  • Which statement about information published on the internet is true?
    9·2 answers
  • Plz help me! No guessing plz!
    13·1 answer
  • Modify the definition of the throttle class on page 35, to create a new throttle ADT, which allows the user of the ADT to specif
    6·1 answer
  • What type of malicious software technology is used to monitor user behavior or gather information about the user, sometimes incl
    5·1 answer
  • Convert 42DB5000 base 16 to base 10 floating point form assuming this is a signed floating point encoding (IEEE754) (32-Bit)
    10·1 answer
  • the one disadvantage of a digital vom is a. difficulty in reading the lcd display. b. long scan times sometimes miss quickly cha
    6·2 answers
  • We will cover email use and management. Training topics include:
    5·1 answer
  • Point out the correct statement:_____.
    6·1 answer
  • Core to resource management system is the _________that coordinates the server hardware.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!