• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Powerball program for school, Need to to run program 8 times.

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Peace & Blessing family,

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.

School Assignment:

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.

Details:

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.

Here is my code:
 
Greenhorn
Posts: 24
Mac MySQL Database PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Anthony Bennett
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
David Hulse
Greenhorn
Posts: 24
Mac MySQL Database PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
David Hulse
Greenhorn
Posts: 24
Mac MySQL Database PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


THIS ONE WORKS EVERY TIME. DONE.
 
Anthony Bennett
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
David Hulse
Greenhorn
Posts: 24
Mac MySQL Database PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That last one.. sorry if I confused you. That one is the one.
 
David Hulse
Greenhorn
Posts: 24
Mac MySQL Database PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually it's not.. but I think you can figure out the rest. Your counter is what's being printed instead of the number that was generated.
 
Anthony Bennett
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David,

Now it will run 8 times with different numbers? That was the assignment. I wasn't sure how to do that, but your code was right on. I am still trying to get it. Thanks again.
 
David Hulse
Greenhorn
Posts: 24
Mac MySQL Database PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well.. right now the numbers aren't really random.. they're just different.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anthony, please UseCodeTags when you post source code. I added them for you in your post above. See how much nicer the code looks when you use code tags?
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic