During Hours 19 and 20 of Sams' Teach Yourself Java 2 in 24 Hours, you'll learn how to write a Java program called Lotto Madness. This program is a Lotto number cruncher that will assess a user's chance of winning one of the multimillion-dollar Lotto contests in the span of a lifetime. This chance will be determined by running random six-number Lotto drawings again and again until the user's numbers turn up as a big winner.
Instead of using probability to figure this problem out, the computer will take a more anecdotal approach: It will conduct drawing after drawing after drawing until you win. Because the 6-out-of-6 win is extremely unlikely, the program also will report on any combination of three, four, or five winning numbers.
There also is a souped-up version of this applet called Lottorobics. Be sure to visit that page while you're here.
If you spend some time running the LottoMadness applet, you will become even more bitter and envious about the good fortune of the people who win these six-number lottery drawings. Tests conducted during the writing of this book indicates that you could blow $27 grand and the best 266 years of your life buying tickets, only to win a handful of 4-of-6 and 3-of-6 prizes. In comparison to those odds, the chance to make Java programming skills pay off almost seems like a sure thing.
Note: The version of Lotto Madness running on this page has been modified to work with Java 1.0.2, the version of the language supported by current versions of the Netscape and Microsoft browsers. If you'd like to see how this differs from the one in the book, you can download the source code here.