Modify the StockAverage2 program in Figure 12.13 by inserting into the streams method-call chain a .peek method
Question:
Modify the StockAverage2 program in Figure 12.13 by inserting into the stream’s method-call chain a .peek method call that prints the previously entered values. Use a lambda expression for peek’s argument.
Figure 12.13
Transcribed Image Text:
/***** * StockAverage2.java *Dean & Dean * * This program stores user-entered stock values in an ArrayList. * Then converts to stream to compute average value and avoid error. import java.util.Scanner; import java.util.ArrayList; public class StockAverage2 ( public static void main(String[] args) ( Scanner stdIn = new Scanner (System.in); ArrayList stocks = new ArrayList (); double stock; System.out.print("Enter a stock value (-1 to quit):"); stock = stdin.nextDouble(); while (stock >= 0) { stocks.add(stock); System.out.print("Enter a stock value (-1 to quit): "); stock = stdIn.nextDouble(); } // end while System.out.printf(" Average stock value // a stock value. $%.2f ", stocks.stream() // sourcing op. .mapToDouble (Double::double Value) // intermediate op. .average ( ) // terminal op. .or Else (0.0)); // avoids error } // end main ] // end class StockAverage 2 = 1
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 0% (1 review)
The peek method in Java streams is an intermediate operation that can be used to perform an action o...View the full answer
Answered By
Kainat Shabbir
i am an experienced qualified expert with a long record of success helping clients overcome specific difficulties in information technology, business and arts greatly increasing their confidence in these topics. i am providing professional services in following concerns research papers, term papers, dissertation writing, book reports, biography writing, proofreading, editing, article critique, book review, coursework, c++, java, bootstarp, database.
5.00+
184+ Reviews
255+ Question Solved
Related Book For
Introduction To Programming With Java A Problem Solving Approach
ISBN: 9781260575248
3rd International Edition
Authors: John Dean
Question Posted:
Students also viewed these Computer science questions
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
A five-year follow-up study was carried out in a certain metropolitan area to assess the relationship of diet and weight to the incidence of stomach cancer. Data were obtained on n = 2,000 subjects....
-
Declare and assign these variables as shown (all your code must appear in the body of the main method): String firstName = "Blueberry"; String lastName = "Strawberry"; In addition, declare and...
-
Define and explain the Bioptic Telescope
-
The hash join algorithm as described in Section computes the natural join of two relations. Describe how to extend the hash join algorithm to compute the natural left outer join, the natural right...
-
Consider Review Exercise 9.101. Let us assume that the data have not been collected yet. Let us also assume that previous statistics suggest that 1 = 2 = $4000. Are the sample sizes in Review...
-
Cooling pipes at three nuclear power plants are investigated for deposits that would inhibit the flow of water. From 30 randomly selected spots at each plant, 13 from the first plant, 8 from the...
-
What internal control procedure(s) would best prevent or detect the following problems? a. A production order was initiated for a product that was already overstocked in the companys warehouse. b. A...
-
Convert the following C code to assembly: if (a b || c == 10) { . . . codel... } else { . . . code2... } ...more code...
-
What is the Unicode hexadecimal value for (uppercase Greek sigma)? Show or explain how you got your answer.
-
Improve the CityTravel program by prompting the user to enter origin and destination cities and using the user-entered values in the getDistance method call. If the user does not spell one of the...
-
Some anonymous digital cash products are touted as being free from the constraints of any banking system or government regulation. In about 100 words, evaluate this claim and outline how such a...
-
Why would a business enter into a sale-and-leaseback transaction?
-
Jameson appears at Klempers Jewellery and asks to buy an expensive watch on credit. She identifies herself as Johnson, a wealthy local financier. Klemper agrees and hands over possession of the watch...
-
In what circumstances may a bailee claim a lien on bailed goods?
-
If a lessee defaults in paying the rent, is the lessor entitled to retake possession of the leased property as well as to sue for the rent owing?
-
What does it mean that goods are fungible? How does that affect a bailees liability?
-
The system development project team at Birdie Masters golf schools has been working on defining the architecture design for a new system. The major focus of the project is a networked school location...
-
Banner Company acquires an 80% interest in Roller Company for $640,000 cash on January 1, 2013. The NCI has a fair value of $160,000. Any excess of cost over book value is attributed to goodwill. To...
-
Discuss with your class factors affecting pricing decisions. Identify the six stages involved in the process of establishing prices. Discuss why pricing decisions are important to an organization.
-
How does an open market purchase by the Fed increase bank reserves? How does it increase the money supply?
-
The excess Gibbs energy for binary systems consisting of liquids not too dissimilar in chemical nature is represented to a reasonable approximation by the equation: where A is a function of...
-
Write a standalone function outside of the DynamicArray class that receives a dynamic array already in sorted order, either non-descending or non-ascending. The function will return a tuple...
-
Heterogeneous reactions between gas and solid catalysts will be done to produce syngas. There are 3 kinds of reactors used to get syngas, namely Fluidized Bed, Fixed Bed, and Fix Bed Multi Tube....
-
Instructions You are to complete a ten page, typed, double-spaced essay on one of the following: Gender Differences in Communication The paper should include relevant research on your topic. You...
Study smarter with the SolutionInn App