Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNuno Freitas
1,054 PointsI did not understand that nextBoolean() method.
So in the Minigolf step he uses the Random function but in the code part: ballInHole = luck.nextBoolean();
I really not understand what it does there.
1 Answer
jmac pd
11,490 PointsI am pretty new to java but I saw your question was not answered and though I would give a try.
I wouldn't worry too much about it. He was mostly trying to demonstrate while loops and this was something he packed in there to demonstrate but was something to explain for another class, much like the Random() method (number greater than or equal to 0.0 and less than 1.0).
I did a little digging and it looks like it is a method in a package called java.util.
Looks like nextBoolean will go through a group of data in a string or maybe list, until it finds a boolean value (1 or 0), and then return the value true or false). here the code is generating a random number, and if the number is 1, it will be a boolean number and True, then the program return ballInHole = True, exiting the loop, if the number is 0 it will be a boolean and false, and if the number is 0.1 - 0.9 it will just generate again.
I wonder if the nextBoolean will count a putt if the value is 0.1 or if it only counts a put if the value is 0 or 1...
Here are the docs on java.util https://www.tutorialspoint.com/java/util/index.htm