Hi riabear123,
Let's take a look at your Lotto.java file and try to figure out what it's doing.
First, you import the Random class from java.util, because you need some way of generating random numbers. Then you set up the object-oriented overhead - the class and main method declarations. Then you get to the meat.
You create a Random object called 'r'. You can think of this little guy as a worker who will perform certain jobs upon request. One job he can perform is called '.nextInt()' - the idea behind this job is given in the
documentation for the Random class:
nextInt(int n)
Returns a pseudorandom, uniformly distributed int value between 0
(inclusive) and the specified value (exclusive), drawn from this random
number generator's sequence. That's a little confusing. What it means is, if you create a Random object called r, and then say something like:
- r will put the numbers 0, 1, 2, 3, and 4 into a hat and draw one out at random, then return that number. It doesn't include 5 (that's what the word "exclusive" means in the documentation) and it will pull any of those five numbers with the same probability (that's what the term "uniformly-distributed" means in the documentation).
But don't take my word for it! After you've finished your program, try this out for yourself - it's the only way to learn how to code!
I should also note that the name '.nextInt(n)' is a little misleading, since all it does is generate a random number. You are probably wondering "nextInt? Next to what?" Don't worry about that right now - it has to do with the internal design of how a Random object picks elements randomly, and it really has little to do with your program.
So, keeping all that in mind, let's return to your program. After you create r, you create an array of integers called mynums[]. It has six slots, and those slots are filled by the numbers 6, 25, 31, 15, 42, and 36. Being a
Lost fan, I prefer 4, 8, 15, 16, 23, and 42, but that's just me

Then you create an integer variable called match, and set it equal to 0. Then you create six integer variables called lotto1, lotto2, lotto3, lotto4, lotto5, and lotto6. Each of these variables gets set equal to a random number - lotto1 through lotto5 get set equal to a random number between 1 and 50, and lotto6 gets set equal to a random number between 1 and 43. You get the random numbers by using successive calls to r.nextInt(n), where n is either 49 or 42, then adding one to shift the range.
This is all clear so far, right?
Now you enter a loop. The loop has an iterator called i, which increases by one after each iteration (cycle) of the loop. The loop only stops when i hits one million and one. In each iteration of the loop, you check the "lotto" variables against the entries in the "mynums" array. Whenever you find a match, you increase the match variable by one - except for the case when lotto1 is equal to mynums[0] - then, you increase match by two (I'm not sure if you really want to do this or not). Then you print out the value of match at this point.
First, let's make an observation: the way the program is currently written, you never change the lotto variables, and you never change the mynums array. Thus, each iteration of the loop makes the
exact same checks of the
exact same numbers. Are you sure you want to do this? Why not make the lotto variables
change inside the loop? Wouldn't that be more like a real sequence of lotteries?
What's more, aren't you only supposed to win when all your numbers match up? The way you have it now, a match between any of your numbers and the corresponding lotto number will increase the value of match. Is this correct? Maybe you need to check all the numbers at once using the && operator, like so:
if (condition1 && condition2 && ... && conditionN) {
// Do stuff
} The thing in the parenthesis is often called a
boolean expression - it's like an arithmetic expression, except that instead of resolving into a number, it resolves into either "True" or "False." Have you learned about these guys in class yet?
I would like to help more, but I can't until you tell me what the assignment asks you to do. I hope that I have at least helped clear up some of the concepts.