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...
-
Lynn Cantwell, an architect, organized Cantwell Architects on July 1, 2014. During the month, Cantwell Architects completed the following transactions: a. Issued capital stock to Lynn Cantwell in...
-
The following data relating to direct materials cost for November of the current year are taken from the records of Tot Toys Inc., a manufacturer of plastic toys: Determine the standard direct...
-
The wedding date for a couple is quickly approaching, and the wedding planner must provide the caterer an estimate of how many people will attend the reception so that the appropriate quantity of...
-
Case 3: Suppose Emily has the same loss distribution as Sam and Jack. Emily, Sam and Jack pool risk together and each pays 1/3 whenever the other one experiences a loss. Which of the following is...
-
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...
-
Match each of the following histograms to the correct situation. 1. Ages of college students studying psychology at an undergraduate college. 2. Year (1 = First Year, 2 = Second Year, 3 = Third Year,...
-
Machine-hours required to support estimated production Fixed manufacturing overhead cost Variable manufacturing overhead cost per machine-hour Required: 1. Compute the plantwide predetermined...
-
Assume now that a new firm (firm N) discovers and patents a more efficient technology, summarized by thetotal cost function C = 10q. The new technology can be used only by the new firm, which enters...
-
1. How has Dell used virtual integration to become an industry leader? Dell has used virtual integration to become an industry leader by leveraging its global suppliers to reduce costs and provide...
-
3) Consider the asset pricing model with uncertainty in the slide. We derived the asset prices as Pb = Ps = - [nu' (y+Yn + e) + (1 )u' (y + y + e)] u'(e1) [nu' (y +n + ) + (1 )u' (y + y + e2)] u'(e1)...
-
Amazon is considered a leader in managing its supply chain. Describe in detail two parts of Amazon's Supply Chain Management that you see as critical to their success. Please provide your reasoning...
-
In Problem, find f(x) and find the value (s) of x where the tangent line is horizontal. f (x) = x2 + 4x +5
-
Maria Castigliani is head of the purchasing department of Ambrosiana Merceti, a medium-sized construction company. One morning she walked into the office and said, The main problem in this office is...
-
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...
-
Palisade Creek Co. is a merchandising business that uses the perpetual inventory system. The account balances for Palisade Creek Co. as of May 1, 2019 (unless otherwise indicated), are as follows:...
-
1-When accounting for an acquisition, goodwill is the difference between what two things? 2- What factors should be considered when deciding whether an acquisition should be financed with cash or...
-
What is the main friction Fluidity aims to address? REAL STATE
Study smarter with the SolutionInn App