Purchase Solution

Lottery Problem in Java, Simulate Random Lottery Numbers

Not what you're looking for?

Ask Custom Question

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.

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.

Purchase this Solution

Solution Summary

I have coded a very compact yet elegant code by exploiting the object oriented functionality of Java. The code is a like a story, it is full of comments that will tell you how things are happening as well as why.

Solution Preview

I have coded a very compact yet elegant code by exploiting the object oriented functionality of Java. The code is a like a story, it is full of comments that will tell you how things are happening as well as why.

I have attached both the .java and .class files so that you can check it immediately.

/**
*
* User: Abdun Mahmood, OTA 103644
* Date: Dec 9, 2006
* Time: 11:38:56 AM
* All Rights Reserved. 2006. Permission granted to reproduce in part or full, provided a mention of credits
*/
public class randomNumberSets {
public int [] numSet; // the set of random numbers to be generated
public static final int RANGE = 49; //range of acceptable integer values
public static final int setSize = 6; //Number of elements in each set

...

Purchase this Solution


Free BrainMass Quizzes
C++ Operators

This quiz tests a student's knowledge about C++ operators.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.