The solution is to have only one call to the coolDownSamples() method and assign the result to an array variable. Then use that array variable consistently when you call the print, max, and min methods.
Edit: looking over your code again, maybe sampleCoolDownTimes is really what you should name that array. Or just sampleTimes. I hope you get the point.
Look how much ceremony it contains. You're dealing with such a low level details beforehand as creating an array, specifying its size in advance, then iterating over an empty array, also you need to take care of indices in order to get them right. Then populating array and finally returning. That is a very imperative way, as you are telling your program how exactly to do things, and that HOW is quite easy to get wrong when the program's logic becomes more complex.
On the other hand, you have a tool to tell program WHAT to do, so you leave underlying mechanics to accomplish for the tool and for yourself leave to worry about the business logic.
Look how simplified version might look using streams:
Explanation might not even needed what this nice method is doing, as it is pretty expressive in its own language. Apparently it does the same, just in much more concise and less error prone way.
Consider learning streams in parallel with old habitual style of writing code, as that might be beneficial for you.
Junilu Lacar wrote:Nice one, Campbell, and I learned something new,
But all you have to do is change three letters I‑n‑t to six letters D‑o‑u‑b‑l‑e in the name of the class (and the same in the import) and it will work
However, since OP is using double, java.util.DoubleSummaryStatistics might be more appropriate.
Campbell Ritchie wrote:That is the nice thing about good object programming (or in this case good functional programming): it is possible to make small changes to accommodate new requirements.
A few minuste ago, I wrote:. . . all you have to do is . . .
In this case, it wasn't object-oriented programming per se that made that possible, it was consistency in choosing names for related classes, i.e. a sensible and intuitive API design.