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

Island Paradise just started running their city lotto. You\'ve been tasked with

ID: 3877301 • Letter: I

Question

Island Paradise just started running their city lotto. You've been tasked with writing a program for them. The program is going to allow to user to first select their lotto numbers. The program will then randomly generate the winning lotto numbers for the week and then check the winning numbers against the random ticket the user played in the Lotto to see how many numbers the user guessed correctly.

The rules for lotto work as follows:

Select 7 numbers between 1 and 50

Twice every week 7 numbers are drawn at random

If a player matches all 7 numbers they win a million dollar prize

If a player matches 6 numbers they win $100,000

If a player matches 5 numbers they win $5,000

If a player matches 4 numbers they win $100.

If a player matches 3 numbers they win a free ticket.

Your program should work as follows. (NOTE:  I have listed some functions you need to include in your program – you may include other functions if you would like and they make your program more readable/efficient).

Step 1

Create an array named UserTicket to hold each of the user’s lotto number selections.

Create an array named WinningNums to hold the winning lotto numbers.

Step 2

Display the following menu:

ISLAND PARADISE LOTTO MODEL:

--------------------------------------------------

1) Play Lotto

q) Quit Program

Please make a selection:

If the selection is 1:

a. First ask the user their name and store it in an appropriate variable.

b. Next, call a function named getLottoPicks that asks the user to enter their 7 lotto number picks (selections) for the week. Each of the user’s lotto picks should be stored in the UserTicket array. The lotto does NOT have duplicate numbers in it. Find a way to not allow duplicate numbers to be picked by the user. You may want to create another function called NoDuplicates that checks to see if the user’s selection is already in the UserTicket array. If the user enters a number already in the array, ask them to enter another number until they enter one that is not a duplicate.   This means the UserTicket array should contain no duplicate numbers.

c. Next, call a function named GenWinNums that randomly generates the winning lotto numbers for the week based on the rules stated above and stores the winning lotto numbers in the WinningNums array (so you are going to fill the WinningNums array with random numbers between 1 and 50). Do not allow this function to generate duplicate winning numbers (if you design your NoDuplicates function above well you should be able to re-use it to check for duplicates in the WinningNums array).

HINT: There are two ways to avoid having duplicate numbers in an array. The first method is to check the array after each number is generated or entered to make sure that number is not already in the array. If the number generated/entered is already in the array a new number should be generated/entered. The second method involves sorting and checking that the numbers next to each other in the array after the sort are not the same.

d. The next step is to check the user’s lotto ticket (represented by the UserTicket array) to see if they have won any prizes in the Lotto game. Check each number the UserTicket array to see if that number is in the WinningNums array and count how many numbers are matched.

Output

Display a report similar to the following showing user’s lotto results – the example output below assumes the user entered a name of “Alex” when the program started.

In the “Winnings” section of the report

Display: JACKPOT!!! - $1 MILLION if all 7 numbers were correct

Display: GREAT! - $100,000 if 6 numbers were correct

Display: LUCKY YOU! - $5,000 if 5 numbers were correct

Display: NOT BAD - $100 if 4 numbers were correct

Display: FREE TICKET if 3 numbers were correct

Display: SORRY NOTHING if 2 or less numbers were correct

Sample Output:-

ALEX'S LOTTO RESULTS

WINNING NUMBERS: 35 03 01 15 10 25 22

ALEX’S TICKET: 33 15 02 06 21 20 19

RESULTS:

--------------

Number Matches: 1          

Winnings      : SORRY NOTHING

If the selection is q: Quit the program

If the selection is not q and not 1: Display an invalid selection message

Allow the user to play lotto as many times as they would like.

This code

Explanation / Answer

Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you

To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i


import java.util.Scanner;

public class LottoGame {
private static Scanner keyboard = new Scanner(System.in);


public static boolean IsNumPresent(int arr[], int len, int search)
{
for(int i = 0; i < len; i++)
if(arr[i] == search)
return true;

return false;
}

public static void GetLottoPicks(int[] UserTicket)
{
System.out.println("Select 7 numbers between 1 and 50");
int i = 0;
while(i < 7)
{
System.out.print("Enter lotto ticket #" + (i+1) + ": ");
int num = keyboard.nextInt();
if(num < 1 || num > 50)
{
System.out.println("Number is not in range 1-50");
}
else if(IsNumPresent(UserTicket, i, num))
{
System.out.println("Duplicate ticket. Enter again");
}
else
UserTicket[i++] = num;
}
}

public static void GetWinNums(int[] WinningNums)
{
int i = 0;
while(i < 7)
{
int num = 1+(int)(Math.random()*50);
if(!IsNumPresent(WinningNums, i, num))
{
WinningNums[i++] = num;
}
}
}

public static int GetMatches(int[] UserTicket, int[] WinningNums)
{
int matches = 0;
for(int i = 0; i < UserTicket.length; i++)
{
if(IsNumPresent(WinningNums, WinningNums.length, UserTicket[i]))
matches++;
}
return matches;
}


public static void DisplayResults(String name, int[] UserTicket, int[] WinningNums)
{
System.out.println(name + "'s LOTTO RESUTS");
String s1 = "WINNING NUMBERS:";
String s2 = name +"'s TICKET:";

System.out.print("WINNING NUMBERS:");
for(int i = 0; i < 7; i++)
{
System.out.printf(" %02d", WinningNums[i]);
}


System.out.print(" " + name + "' TICKET:");
for(int i = 0; i < 7; i++)
{
System.out.printf(" %02d", UserTicket[i]);
}

System.out.println(" RESULTS:");
System.out.println("=============");
int matches = GetMatches(UserTicket, WinningNums);

String winnings;
if(matches == 7)
winnings = "JACKPOT!!! - $1 MILLION";
else if(matches == 6)
winnings = "GREAT! - $100,000";
else if(matches == 5)
winnings = "LUCKY YOU! - $5,000";
else if(matches == 4)
winnings = "NOT BAD - $100";
else if(matches == 3)
winnings = "FREE TICKET";
else
winnings = "SORRY NOTHING";

System.out.println("NUMBER OF MATCHES: " + matches);
System.out.println("WINNINGS: " + winnings);
}

public static void main(String[] args) {
String choice="";
int[] UserTicket = new int[7];
int[] WinningNums = new int[7];
String name;
System.out.println("Enter your name: ");
name = keyboard.nextLine().trim();

while(!choice.equalsIgnoreCase("q"))
{
System.out.println("1) Play Lotto");
System.out.println("q) Quit program");
choice = keyboard.next();
if(choice.equals("1"))
{
GetLottoPicks(UserTicket);
GetWinNums(WinningNums);
DisplayResults(name, UserTicket, WinningNums);
}
else if(!choice.equalsIgnoreCase("q"))
System.out.println("Invalid choice! Try again.");
}
}

}

output
Enter your name:
Alex
1) Play Lotto
q) Quit program
1
Select 7 numbers between 1 and 50
Enter lotto ticket #1: 33
Enter lotto ticket #2: 33
Duplicate ticket. Enter again
Enter lotto ticket #2: 15
Enter lotto ticket #3: 2
Enter lotto ticket #4: 6
Enter lotto ticket #5: 21
Enter lotto ticket #6: 20
Enter lotto ticket #7: 19
Alex's LOTTO RESUTS
WINNING NUMBERS: 03 05 38 26 37 43 42
Alex' TICKET: 33 15 02 06 21 20 19
RESULTS:
=============
NUMBER OF MATCHES: 0
WINNINGS: SORRY NOTHING
1) Play Lotto
q) Quit program
1
Select 7 numbers between 1 and 50
Enter lotto ticket #1: 34
Enter lotto ticket #2: 50
Enter lotto ticket #3: 23
Enter lotto ticket #4: 45
Enter lotto ticket #5: 12
Enter lotto ticket #6: 19
Enter lotto ticket #7: 30
Alex's LOTTO RESUTS
WINNING NUMBERS: 06 38 29 45 18 22 39
Alex' TICKET: 34 50 23 45 12 19 30
RESULTS:
=============
NUMBER OF MATCHES: 1
WINNINGS: SORRY NOTHING
1) Play Lotto
q) Quit program
1
Select 7 numbers between 1 and 50
Enter lotto ticket #1: 20
Enter lotto ticket #2: 10
Enter lotto ticket #3: 30
Enter lotto ticket #4: 40
Enter lotto ticket #5: 50
Enter lotto ticket #6: 22
Enter lotto ticket #7: 29
Alex's LOTTO RESUTS
WINNING NUMBERS: 42 02 20 33 47 50 29
Alex' TICKET: 20 10 30 40 50 22 29
RESULTS:
=============
NUMBER OF MATCHES: 3
WINNINGS: FREE TICKET
1) Play Lotto
q) Quit program
q

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