Question
Asked by:
Elentius
Elentius
Rating : No Rating
Questions Asked: 11
Tutorials Posted: 0
 

$4.00 Lottery Problem

Q:
The Lottery Problem

A lottery requires that you select six different numbers from the integers 1 to 49. Write a Java program that will do this for you and generate five sets of six numbers as a result.

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 49, you can generate a random number between 1 and 49 through:

number = (int) ( range * Math.random() ) + 1;
Note that you need 5 sets of numbers and in each set you have should have six different numbers. There should not be duplicate numbers within each set. Of course the same number can occur in multiple sets, but within the same set of 6 numbers it should only occur once, if at all.

Here is an example of a valid set of numbers: 5, 41, 3, 9, 22, 30

Here is an example of an invalid set of numbers: 15, 8, 19, 33, 8, 21

It is invalid because the number 8 appears twice.

This should include your Java program with commented Java source code files.
 


   
   
   
   
 
Available Tutorials to this Question
Posted by:
rannok_026
rannok_026
Rating (200): A-
Questions Asked: 5
Tutorials Posted: 1453, earned $4,809.95
 

$5.00 Lottery Problem

  • This tutorial hasn't been purchased yet.
  • Posted on Aug 03, 2009 at 8:09:46PM
A:
Preview: ... e attachm ...

The full tutorial is about 5 words long plus attachments.

Attachments:
Lottery.java (0K) (Preview)
Posted by:
modulo51
modulo51
Rating (110): A-
Questions Asked: 1
Tutorials Posted: 353, earned $2,117.64
 

$9.00 Java: Lottery picks, NetBeans folder, UseNotes, ScreenShot, conolteOutput

  • This tutorial was purchased 1 time and rated C- by students like you.
  • Posted on Aug. 04, 2009 at 12:19:15AM
A:
Preview: ... }<br> }<br> // get index to pick number out of array:<br> int index = (int) ((49 - drawNumber) * Math.random()); // 0 to 48<br> int retNum = allNumbers[index];<br> // now shift remaining numbers in array down:<br> for (int k = index; k < 48 - drawNumber; k++) {<br> allNumbers[k] = allNumbers[k + 1];<br><br> }<br> drawNumber++;<br> return retNum;<br> }<br><br> static void test() {<br>System.out.println( ...

The full tutorial is about 755 words long plus attachments.

Attachments:
Lottery.java (2K) (Preview)
LotteryUseNotes.txt (1K) (Preview)
LotteryScreenShot.JPG (27K) (Preview)
LotteryZipped.zip (35K)
Posted by:
Komsomolets
Komsomolets
Rating (4): A+
Questions Asked: 0
Tutorials Posted: 22, earned $17.80
 

$4.00 The program with comments

  • This tutorial hasn't been purchased yet.
  • Posted on Aug. 04, 2009 at 09:49:56AM
A:
Preview: ... an see ...

The full tutorial is about 7 words long plus attachments.

Attachments:
set.java (0K) (Preview)
main.java (0K) (Preview)
   
Join Now or Log In
Get Tutoring
Get Paid
Academic Honesty