Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are going to create a program that generates SuperLotto lottery numbers. Cre

ID: 3604702 • Letter: Y

Question

You are going to create a program that generates SuperLotto lottery numbers.

Create a class called SuperLottoPlus.java Create a static method called generateSuperLottoNumbers() that returns an array of 6 random SuperLotto lottery numbers.

Must have correct method signature, and return the entire array of lotto numbers. [1 pt]

The first 5 numbers must be from the range 1 to 47 [1 pt]

The 6th number (the MEGA) must be from 1 to 27. [1 pt]

Create a static method called printTicket() that takes an integer array as a parameter Must have correct method signatures [1 pt]

it will loop through the integer array and print out the data [1 pt]

Display the data in the format: 47 22 25 4 13 (MEGA: 14)

In the main method Ask the user how many lotto tickets they want. If the user enters N then, using a for loop, loop N number of times. [1 pt] In each loop iteration, call the printTicket() method, passing a call to the method generateSuperLottoNumbers() as an argument [1 pts] Hint: numbers[i] = (int) (10 * Math.random()) + 1; // will assign your array element to a random number from 1 to 10 Extra Credit:

Create another method called generateSuperLottoNoDupes() which does the same thing as generateSuperLottoNumbers(), but returns an array without duplicates in the first 5 numbers. It is OK for the MEGA number to be a duplicate of any of the first 5 (+1 point) Example output: How many Super Lotto tickets do you want?

4 28 8 11 9 28 MEGA (4)

38 39 29 47 27 MEGA (27)

15 17 33 12 6 MEGA (19)

30 29 18 20 31 MEGA (12)

Explanation / Answer

Given below is the code with output. To indent code in eclipse, select code and press Ctrl+a and then Ctrl+i.
Please don't forget to rate the answer if it helped. Post a comment in case of any issues.


import java.util.Scanner;
public class SuperLottoPlus {
private static int[] generateSuperLottoNumbers()
{
int[] ticket = new int[6]; //array of 6 numbers
for(int i = 0; i < 5; i++)
ticket[i] = ((int) (47 * Math.random()) + 1);
//generate MEGA
ticket[5] = ((int) (27 * Math.random()) + 1);
return ticket;
}
private static int[] generateSuperLottoNoDupes()
{
int[] ticket = new int[6]; //array of 6 numbers
for(int i = 0; i < 5;) //not incrementing index here...
{
int n = ((int) (47 * Math.random()) + 1);
boolean dupe = false;
//check if n is one of the previous values
for(int j = 0; j < i; j++)
{
if(ticket[j] == n)
{
dupe = true;
break;
}
}
if(!dupe)
{
ticket[i] = n;
i++; //increment to go to next location
}
}
//generate MEGA
ticket[5] = ((int) (27 * Math.random()) + 1);
return ticket;
}
private static void printTicket(int[] ticket)
{

for(int i = 0; i < 5; i++)
System.out.print(ticket[i] + " ");
System.out.println("(MEGA: " + ticket[5] + ")");
}
public static void main(String[] args) {
Scanner keybd = new Scanner(System.in);
int n ;
int[] ticket;
System.out.print("How many Super Lotto tickets do you want? ");
n = keybd.nextInt();
//printing normal super lotto tickets, may contain duplicates
System.out.println("Normal Super Lotto Tickets (May contain duplicates)");
for(int i = 1; i <= n; i++)
{
printTicket(generateSuperLottoNumbers());
}
//EXTRA credit ...printing super lotto tickets without duplicates
System.out.println("Super Lotto Tickets without duplicates");
for(int i = 1; i <= n; i++)
{
printTicket(generateSuperLottoNoDupes());
}
}
}

output

How many Super Lotto tickets do you want? 4
Normal Super Lotto Tickets (May contain duplicates)
26 36 26 20 20 (MEGA: 4)
14 39 19 9 11 (MEGA: 17)
39 19 33 31 31 (MEGA: 11)
31 2 30 22 9 (MEGA: 1)
Super Lotto Tickets without duplicates
31 45 41 19 32 (MEGA: 6)
1 28 6 33 20 (MEGA: 4)
16 23 22 43 47 (MEGA: 4)
33 29 47 10 44 (MEGA: 6)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote