Question
Write a Java program that checks the 4 purchased tickets against the winning numbers. For that purpose, you need to do the following: Create a
Write a Java program that checks the 4 purchased tickets against the winning numbers. For that purpose, you need to do the following:
Create a method called "generateTicket" that includes the code provided (5 non-repeating random numbers) below and returns a single dimension array of type integer.
Create a single dimension array called "winningNumbers" for the winning numbers.
Create a two-dimensional array called "Tickets" to hold all 4 tickets' information.
Compare each ticket to the winning numbers and announce the winning as follows:
$100K if the ticket matches all 5 winning numbers.
$20K if the ticket matches 4 winning numbers.
$2K if the ticket matches 3 winning numbers.
int[] numbers = new int[5];
for (int i = 0; i < 5; i++)
int randomNum = new Random().nextint(10) + 1;
boolean unique = true;
for (int j = 0; j < i; i++) {
if (numberslil == randomNum) {
unique = false;
break;
}
}
if (unique) {
numbers[i] = randomNum;
}else {
i-;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started