Campbell Ritchie wrote:A Stream‑based solution might be eminently suitable for beginners, but we shall have to make them do it the hard way with a loop () because these exercises are for teaching people how to use loops.
Campbell Ritchie wrote:You can't iterate a Map. only one of the three sets you can get out of it. You can get access to those three sets via three of the Map's methods. You can use the map() mathod to take the price and count and produce a number. If you have the price as a primitive you may be able to get a Stream of primitives with a method called mapToXYZ() and use its sum() method, otherwise you would have to write a Collector with its three parts yourself, or use the reduce() method which you will find examples of in the package documentation.
Show us what you have tried and tell us how it is going. This is one of the circumstances where it is much easier to use an IDE than the command line.
Also I am curious, why do you want to come up with such a method in the first place ?