Create a Java application to generate and display 5 sets of 6 random unique Lotto numbers between 1 and 50. Display the numbers sorted in ascending order. Use an array to store the numbers. Create a method with the following header: public static boolean isFound(int[] lotto, int number) The purpose of this method is to determine if the lotto array contains the number passed as an argument. The method will return true if the number is already in the array, otherwise it returns false. As random numbers are generated, call this method to make sure the number generated is not already in the array. The output of the program should appear as follows: LOTTO Numbers for set 1 –> 4 7 15 29 44 50 LOTTO Numbers for set 2 –> 11 14 38 42 43 49 LOTTO Numbers for set 3 –> 4 6 7 21 35 49 LOTTO Numbers for set 4 –> 1 7 20 24 27 39 LOTTO Numbers for set 5 –> 14 25 33 48 49 50

In order to create a Java application that generates and displays 5 sets of 6 random unique Lotto numbers between 1 and 50, we will need to use an array to store the numbers and create a method to check if a number is already in the array.

First, let’s create an array to store the Lotto numbers. The size of the array will be 6, as each set contains 6 numbers. We can declare the array as follows:

int[] lotto = new int[6];

Next, we will create a method called isFound to check if a number is already in the lotto array. The method will take two arguments – the lotto array and the number to be checked. The method will return a boolean value, true if the number is already in the array, and false otherwise. The signature of the method is as follows:

public static boolean isFound(int[] lotto, int number)

Inside the isFound method, we will iterate over the elements of the lotto array and compare each element with the number passed as an argument. If any element matches the number, we will return true. If no match is found, we will return false. The implementation of the isFound method looks like this:

public static boolean isFound(int[] lotto, int number) {
for (int i = 0; i < lotto.length; i++) { if (lotto[i] == number) { return true; } } return false; } Now, let's move on to generating the random unique Lotto numbers. We will need to generate 6 random numbers between 1 and 50 for each set. To ensure the numbers are unique, we will use the isFound method to check if a number is already in the array before adding it. We will continue generating numbers until we have 6 unique numbers in the array. We can do this for each set using a loop. Here is the implementation: for (int set = 1; set <= 5; set++) { System.out.print("LOTTO Numbers for set " + set + " --> “);
int count = 0;
while (count < 6) { int randomNumber = (int) (Math.random() * 50) + 1; if (!isFound(lotto, randomNumber)) { lotto[count] = randomNumber; count++; } } Arrays.sort(lotto); for (int i = 0; i < lotto.length; i++) { System.out.print(lotto[i] + " "); } System.out.println(); } In the above code, we first print the header for each set using the set variable. We then initialize a count variable to keep track of how many unique numbers we have generated so far. Inside the while loop, we generate a random number between 1 and 50 and check if it is already in the lotto array using the isFound method. If it is not found, we add it to the array and increment the count variable. Once we have 6 unique numbers in the array, we sort it in ascending order using the Arrays.sort method and print the numbers. By running the above code, you will get the required output of 5 sets of 6 random unique Lotto numbers between 1 and 50, displayed in ascending order as described in the question.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer