Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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: Write a stream processing that produces a List from the file Input2.txt that contains only numeric, positive values. 1. Use the Files.lines() and Paths.get() to open and read the file to a stream. 2. Use the Stream.map() method to spit the lines into an array of four strings containing the values. 3. 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. 4. Use the Stream.map() method to convert each array of string into an array of Doubles. 5. Use the Stream. filter() method to pass only arrays that have all positive values. 6. Use the Steam.collect() method to collect the arrays into a list. The Collectors.toList() can do this. 7. After the stream has produced the list, display it. Use Arrays.toString() to display each array: Listcontains:[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 average of each of the arrays of Double. 1. Use the stream() method to turn the List into a stream. 2. Use the Stream.map() method to calculate the average of each array in the stream. 3. Use the Stream.collect ) method to collect the averages into a list. 4. After the Stream has produces the list, display it (use System.out.printf (%.2f%n ", a) to show only two decimal places): List contains the averages 211.84 157.72 251.07 166.17 Submit your code to pass the second test. Step 3) Write a stream that produces the overall average from your List. 1. Use the stream() method to create the stream from your List. 2. Use the reduce() method to accumulate the sum of your values. Use the reduce(T identity, BinaryOperator) overloading. 3. 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. 4. Divide the sum from 2. by the count from 3. to get the overall average. Display the overall average using System.out.printf("\%.2f\%n", a) Overal1average:199.36 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("\%.2f\%n", a): Highestaverages:251.07295.13256.29262.44 Submit your code to pass the fourth test. 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("\%.2f\%n", a): Submit your code to pass the fourth test. Downloadable files StreamProcessing.java Load default template

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Explain in detail how the Mughal Empire was established in India

Answered: 1 week ago

Question

=+1 What would you do if you were the IHR manager?

Answered: 1 week ago