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
openinnewfullscreen
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:
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 nonpositive values in the file and the file may contain values that are not numeric.
Step : 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:
Submit your code to pass the first test.
Step : 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.printfdn a:
List contains the averages
Submit your code to pass the second test.
Step 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 reduceT 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 by the count from to get the overall average. Display the overall average using System.out.printfdn a
Overall average:
Submit your code to pass the third test.
Step 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 above the overall average. Collect these averages in another List Display this the highest averages using System.out.printfdn a:
Highest averages:
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
