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

*well aware there our similar posts like this please ready last part* I\'m worki

ID: 3830664 • Letter: #

Question

*well aware there our similar posts like this please ready last part* I'm working on a lottery application taht simulates a lottery. The class should have an array of five integers named lotteryNumbers. The constructor should use the Random class to generate a random number in the range of 0 through 9 for each element in the array. The class should also have a method that accepts an array of five integers thatt represent a person's lottery pick. The method is to compare the corresponding elements in the two arrays and return the number of digits that match. For example, the following shows the lotteryNumbers array and the user's array with sample numbers stored in each. There are two matching digits (elements 2 and 4). lottery Numbers array: 7 4 9 1 3 User's array: 4 2 9 7 3

I've seen other posts but none actually compare the two and display both the random numbers and the numbers picked in the output and then also display what there winnings are based on how many matches there are. i have looked at all the other posts either they dont work or it only displays half of what the problem is asking for

Explanation / Answer

Here is the code. As I haven't seen this question before so this is all I can do from the provided information. Do comment if this is not working with proper error message/possible tester code and I will fix if there are any issues.

Please note that random number generated in constructor need not be unique as question doesn't ask for it.

import java.util.Random;

public class Lottery {
private int[] lotteryNumbers = new int[5];
  
private static Random rn = new Random();
  
public Lottery()
{
for(int i = 0; i < 5; i++)
lotteryNumbers[i] = rn.nextInt(10);
}
  
public int numDigitMatch(int[] usersNumber)
{
int count = 0;
for(int i = 0; i < lotteryNumbers.length; i++)
{
if(usersNumber[i] == lotteryNumbers[i])
{
count++;
}
}
return count;
}

}