A program that simulates a lottery the program should have


Java programming

A program that simulates a lottery. The program should have array of 6 integers named winning, with a randomly generated number in the range of 1 through 9 for each element in the array. The program should ask user to enter 6 numbers and store them in another integer array named player. The program then compares the numbers in 2 arrays to find out how many numbers match.

If the two numbers are on the same position in both arrays, it is a match. (This is using parallel array concept to compare two arrays.) The program output should display the winning numbers, player's numbers, and how many numbers matched. For instance, if your winning numbers are 3,5,9,1,4,7 and your player's numbers are 2,5, 7,1, 9,8, then you have two matches (5 and 1). 5 is on the second position and 1 is on the fourth position in both arrays.

Input Validation: Do not accept player's number out of range of 1-9.

Use the following design tips

1. Create two integer arrays with 5 elements each.

2. You can create methods such as generateWinningNumber, getPlayerNumber, getMatches, and printNumber.

3. Use Random class to generate random numbers. Here is the example of how to create method generateWinningNumber;

public static void generateWinningNumber(int[] wList)

{

Random rNum = new Random();

final int MIN=1, MAX=9;

for (int i=0; i

{

wList[i]=rNum.nextInt(MAX-MIN+1)+MIN;

}

}

 

4. Use for loop to complete each task.

 

5. Use while loop to validate user input as follows;

 

while (pList[i]<1 || pList[i]>9) //pList is the array of player number

{

System.out.print("Invalid Number. Enter number 1-9:");

pList[i]=input.nextInt();

}

6. To compare two arrays to find out the matches, use the following code;

 

for (int i=0; i

{

if (wList[i]==pList[i]) //wList is the array of winning numbers

match++;

}

If someone could help me solve this and possibly give me some tips on how these should be laid out, I would be very appreciative.

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: A program that simulates a lottery the program should have
Reference No:- TGS02773697

Now Priced at $30 (50% Discount)

Recommended (95%)

Rated (4.7/5)