Calculate the average of the values in the integer array


Create, using NetBeans, a complete Java program called CalcWeightedAvg according to the following guidelines.

The program should use methods to carry out all computations. The method readIntValues should take no arguments, prompt the user to enter one line of between 5 and 10 space-separated integers with values between 0 and 100 (inclusive) and return an array of these integers.

The method getWeight should take no arguments, and it should prompt the user for a double with value greater than 0.0 but less than or equal to 1.0, and return as a double the value the user entered. The method calcWeightedAvg should return a double and take two parameters: an array of integers and a double called weight (with values greater than 0.0 but less than or equal to 1.0).

It should calculate the average of the values in the integer array, multiply that average by the weight, and return the result. For example, if calcWeightedAvg is invoked as calcWeightedAvg(intArray, weight) (with weight = 0.50) then it should calculate the average of all values in intArray, multiply that average by 0.50 and return the result to the main method which will then display that value to the user.

Example: integer input: 0 20 40 60 80 100 weight input: 0.50 calcWeightedAvg invoked as calcWeightedAvg(intArray, weight) returns 25.0. Thoughts: *) The method readIntValues will probably be the most challenging one to write, since the integer values you want will be embedded in the line of input, which is a string. I'll give some suggestions about how this might be done. *) Print some explanatory information with your result, such as, "With input values 0 20 40 60 80 100, and with a weight of 0.50, the weighted average of the all the values is 25.0."

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Calculate the average of the values in the integer array
Reference No:- TGS01363322

Now Priced at $65 (50% Discount)

Recommended (90%)

Rated (4.3/5)