Here is my assignment from school. I think I did this code right. Still not sure though, but it did work. It did give me my .class file. My question is how do I repeat this process 7 more times. How do I do that with a loop, and where do I put the loop? Here is what I've done so far. I want to thank you all for your help on this project. Thank you family.
A lottery requires that you select seven different numbers from the integers 1 to 35. A separate powerball number should also be generated. The powerball number should be within the range of 1-10. Write a Java program that will do this for you and generate eight sets of seven numbers plus one powerball number. You must create an array and you must use the random() method in your solution. The solution must also include the use of at least one repetition statement.
For generating random numbers you can use the random() static method of class Math. It returns a double so you will need to cast it as an integer. If you set the range to 35, you can generate a random number between 1 and 35 through:
number = (int) ( range * Math.random() ) + 1;
Note that you need eight sets of numbers and in each set you have should have seven different numbers - plus a powerball number. There should not be duplicate numbers within each set of seven. Of course the same number can occur in multiple sets, but within the same set of 7 numbers it should only occur once, if at all.
Here is an example of a valid set of numbers: 5, 33, 3, 9, 22, 30, 15, 3
The first seven numbers must be unique and within the range of 1-35. The last number is the powerball number. The powerball number may be a duplicate and that is fine. It must range between 1-10.
Well, you're right. That certainly is a class. Take a look at constructors. Do remember the assignment having anything to do with the creation of a Powerball object? then you could either run it 7 times in your main method or you could write a method into your powerball object that would allow you to return the result of consequent calls. Then you could print those results with system.out
Joined: Apr 03, 2011
I thank you for responding to my post. I am not sure on what you said to do, but I will try to look it up. If you have an example of how to do what you said I will try to incorporate it into my program. I posted all what my Professor want us to do for this assignment. I guess my question is how would you tackle to seven more times? Thanks for your time and help on this assignment.
if this one is working why not just use a double nested for loop?
The way you did it with that array was kind of shotty too.. because you can't use the number 35 in the index.. so it's not really doing what you expected. array indexes are from 0-34 so you need to make them refer to a number higher.
Sounds great, how would you do a double nesting loop? I am three weeks into Java, my head hurts sometimes from all the reading and code. I still don't have a clue on what I am doing. I have nothing but respect for programmers and developers your jobs are crazy to me. I have a lot to learn and a deadline by 12:30 am EST to get this in.