Question: Complex Stream from a File open _ in _ newfullscreen 5 / 2 0 In this lab, you will write a program that processes a

Complex Stream from a File
open_in_newfullscreen5/20
In this lab, you will write a program that processes a file using Java stream processing. The file is a text file containing lines of the form:
271.72296.3347.70231.61
That is, each line of the file contains four positive double values. Unfortunately, mistakes in the collection and production of the file are possible: their may be non-positive values in the file and the file may contain values that are not numeric.
Step 1: Create a stream that contain
Use the Files.lines() and Paths.get() to open and read the file to a stream. S
Use the Stream.map() method to spit the lines into an array of four strings containing the values.
Use the Stream.filter() method to pass only arrays that only have strings that represent double values (use the String.matches() method in the filter.
Use the Stream.map() method to convert each array of string into an array of Doubles.
Use the Stream.filter() method to pass only arrays that have all positive values.
Use the Steam.collect() method to collect the arrays into a list. The Collectors.toList() can do this.
After the stream has produced the list, display it. Use Arrays.toString() to display each array:
List contains: [271.72,296.33,47.7,231.61][84.85,208.83,77.3,259.89]...
Submit your code to pass the first test.
Step 2: Now write the stream processing code that takes your List and produces an List that contains the integral average of each of the arrays of Double. To compute the integral average, the doubles values are truncated to integers (cast the double values as integers), and divided by the number of values to produce an integer.
Use the .stream() method to turn the List into a stream.
Use the Stream.map() method to calculate the average of each array in the stream.
Use the Stream.collect() method to collect the averages into a list.
After the Stream has produces the list, display it (use System.out.printf(%d%n", a)):
List contains the averages
211157250160...
Submit your code to pass the second test.
Step 3) Write a stream that produces the overall integral average from your List.
Use the stream() method to create the stream from your List.
Use the reduce() method to accumulate the sum of your values. Use the reduce(T identity, BinaryOperator) overloading.
Use the stream() method to create a second stream from your List and use the Stream.count() method to count the number of elements in the stream.
Divide the sum from 2. by the count from 3. to get the overall average. Display the overall average using System.out.printf("%d%n", a)
Overall average: 198
Submit your code to pass the third test.
Step 4) Now that you have a List of averages and the overall average, write a last stream that produces only the averages fro your List that more than 25% above the overall average. Collect these averages in another List Display this the highest averages using System.out.printf("%d%n", a):
Highest averages: 250
294256261...
Submit your code to pass the fourth test.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!