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
Which of the following is a useful policy to minimize waste and mistakes?
anastassius [24]

Answer:

Option C

Explanation:

To ensure correct input data, proper  procedure is must in order to minimize waste and mistakes.

5 0
3 years ago
How is it possible for the router to know whether it is supposed to send a cat photo to your laptop
kupik [55]

It is possible for the router to know whether it is supposed to send a cat photo to your laptop because  It uses the private IP address.

Router  is a  device that help to transfer data and across the internet or across the user device and the internet.

Private IP addresses are internet protocol addresses that is often  assign to user device by   router in order to a successful communicate to take place between the internet and user device.

Private IP addresses are mostly at:

•Home

•Office

•Business  environments

Inconclusion It is possible for the router to know whether it is supposed to send a cat photo to your laptop because  It uses the private IP address.

Learn more here:

brainly.com/question/19112414

3 0
2 years ago
If your address is 10 B Street, what are the first three bytes in ASCII
STALIN [3.7K]

They are 49, 48, 32

The 32 is important because it is a space.

3 0
4 years ago
An alternative to configuring individual workstations is to establish configurations dynamically when the computers connect to t
Lapatulllka [165]

Answer:

come help me on my last question please

Explanation:

6 0
3 years ago
Which wireless communication technology is most likely used when synchronizing device information to an automobile?
seropon [69]
Bluetooth is the most reasonable answer
8 0
4 years ago
Other questions:
  • Today, air travel allows large numbers of people to move quickly over long distances. Which of the following is a likely effect
    8·1 answer
  • An unwanted 'explosion' of inbox messages is called​
    8·2 answers
  • People use a computer connected to the internet to manage financial accounts
    15·1 answer
  • How is it possible to find encyclopedias and reference texts on the internet
    11·2 answers
  • What do these terms have in common? google, yahoo!, bing they are important books. they are internet search engines. they are wo
    10·1 answer
  • You have been asked to report on the feasibility of installing an IP CCTV camera system at your organization. Detail the pros an
    5·1 answer
  • . What type of computer implementation does the following code represent? Load A,10 Load B,1:5 Add A,B STORE A, [20]
    5·1 answer
  • Which term describes a visual object such as a picture a table or text box
    15·2 answers
  • Examples of email use that could be considered unethical include _____.
    14·2 answers
  • With which type of test question should you leave yourself extra time to answer?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!