Please help with this, and leave comments explainging the code you wrote, thank you for your help
Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an array of six integers named lotteryNumbers, and another array of six integers named userLotteryPicks. The class' constructor should use the Random class to generate a unique random number in the range of 1 to 60 for each of the 6 elements in the lotteryNumbers array. Thus, there should be a loop that keeps generating random numbers until all 6 numbers are unique. The Lottery class should have a method, getUsersPicks(), which prompts the user to enter 6 unique numbers between 1 - 60, which will be stored in the array of integers named usersLotteryPicks. Thus, there should be validation to ensure that each number the user selects is different from all the other numbers that he/she entered previously, and to keep looping until the user enters 6 unique numbers. Finally, the Lottery class should have a method, checkLotteryMatch(), which will compare the 2 arrays - lotteryNumbers & usersLotteryPicks - and return the number of digits that match. The digits do not have to match in the exact order, so a nested loop should be created that goes through each digit in the user's lottery picks array and compares it to each digit in the lotteryNumbers array, counting each of the matches. The checkLotteryMatch() method will return an int containing the number of matches.
Write a Driver class called the LotteryGame, which instantiates the Lottery class. Once a Lottery object has been created, the driver will call the Lottery object's getUsersPicks() method, followed by the checkLotteryMatch() method. Use the results of the checkLotteryMatch() method to determine if the user is a winner by using the following criteria:
For a 3-digit match, display a message to the user that he/she will receive a free Lottery ticket as the prize
For a 4-digit match, display a message to the user that he/she will receive a $2000 prize
For a 5-digit match, display a message to the user that he/she will receive a prize of $50,000.
For a 6-digit match, display a message to the user that he/she will receive a grand prize of $1,000,000.
If there are no matches, display the following message to the user: "Sorry, no matches today. Try again!"
This is what I have so far
Domain
package lotterygame;
import java.util.Scanner;
import java.util.Random;
//
///**
// *
// * @author morty
// */
public class Lottery
{
static int[] lotteryNumbers = new
int[6];
static int[] userLotteryPicks = new
int[6];
static int userNums;
int numMax, numMin;
public int noDuplicates (int numMax, int
numMin)
{
return
((int)(Math.random()*(numMax - numMin))) + numMin;
}
public Lottery()
{
for (int i = 0; i <
lotteryNumbers.length; i++)
{
int
rand = noDuplicates(1, 60);
lotteryNumbers [i] = rand;
}
}
public void getUsersPicks()
{
Scanner key= new
Scanner(System.in);
do
{
System.out.println("Please enter 6 numbers between 1 and 60. GOOD
LUCK! ");
userNums =
key.nextInt();
} while (userNums >
60 || userNums < 1);
for (int j = 0; j <
6; j++)
{
userLotteryPicks[j] = userNums;
}
}
public int checkLotteryMatch()
{
int sameNums = 0;
for (int k = 0; k <
lotteryNumbers.length; k++)
{
if (lotteryNumbers.equals(userLotteryPicks))
{
sameNums++;
System.out.println(sameNums);
}
} return sameNums;
}
}
Driver
package lotterygame;
/**
*
* @author morty
*/
public class LotteryGame {
/**
* @param args the command line
arguments
*/
public static void main(String[] args)
{
Lottery lotto = new
Lottery();
lotto.getUsersPicks();
lotto.checkLotteryMatch();
int counter =
lotto.checkLotteryMatch();
if (counter == 3)
{
System.out.println("You get a free Lottery ticket as the
prize");
}
else if (counter ==
4)
{
System.out.println("Bravo, you won $2,000");
}
else if (counter ==
5)
{
System.out.println("Fantastic, you won $50,000");
}
else if (counter ==
5)
{
System.out.println("Congratulations, you won the grand prize of
$1,000,000");
}
else
{
System.out.println("Sorry, no matches today. Try again!");
}
}
}
import java.util.Random; //For random number
creation
import java.util.Scanner; //For scanner class to accept
data
//Class Lottery
class Lottery
{
//Array declaration
int lotteryNumbers[];
int userLotteryPicks[];
Lottery()
{
//Array creation
lotteryNumbers = new int[6];
userLotteryPicks = new
int[6];
//Random number object
created
Random r = new Random();
//Sets the lower and upper
bound
int Low = 1;
int High = 60;
//Generates the random number
int i, Result, f = 0;
//Initializes the array elements to
zero
for(i = 0; i < 6; i++)
{
lotteryNumbers[i] = 0;
userLotteryPicks[i] = 0;
}
i = 0;
//Generates unique random
number
do
{
Result =
r.nextInt(High-Low) + Low;
//Checks for the
duplicate
for(int t = 0; t
< 6; t++)
{
if(lotteryNumbers[t] == Result)
f = 1;
}
//If no
duplicate then store the number and increase the counter
if(f == 0)
{
lotteryNumbers[i] = Result;
i++;
}
else
f = 0;
}while(i < 6);
}
//Accepts 6 unique numbers from the user
void getUsersPicks()
{
//Scanner calss object created to
accept numbers
Scanner sc = new
Scanner(System.in);
int i = 0, f = 0, no;
System.out.println("\n Enter 6
Unique numbers: ");
//Loops till 6 unique numbers
do
{
System.out.println("Enter a number: ");
no =
sc.nextInt();
//Checks for the
duplicate number
for(int t = 0; t
< 6; t++)
{
if(userLotteryPicks[t] == no)
f = 1;
}
//If not a
duplicate number then store the number increase the counter
if(f == 0)
{
userLotteryPicks[i] = no;
i++;
}
//If duplicate
displays the error message
else
{
System.out.println("\n Duplicate Number Entered:
");
f = 0;
}
}while(i < 6);
}
//Matches the lotteryNumbers with userLotteryPicks and
counts number of match
int checkLotteryMatch()
{
int match = 0, r, c;
//Checks for the matching
for(r = 0; r < 6; r++)
{
for(c = 0; c
< 6; c++)
{
if(lotteryNumbers[r] ==
userLotteryPicks[c])
match++; //Counts
number of matching
}
}
return match;
}
}
//Driver class
public class LotteryGame
{
public static void main(String ss[])
{
//Creates object for the Lottery
class
Lottery lg = new Lottery();
int res;
//Displays the unique random
generated
System.out.println("Random Numbers:
\n");
for(int t = 0; t < 6; t++)
System.out.print(" " + lg.lotteryNumbers[t]);
lg.getUsersPicks();
res = lg.checkLotteryMatch();
//Checks the number of match and
displays the appropriage message
if(res == 3)
System.out.println("he/she will receive a free Lottery ticket as
the prize");
else if(res == 4)
System.out.println("he/she will receive a $2000 prize");
else if(res == 5)
System.out.println("he/she will receive a prize of $50,000");
else if(res == 6)
System.out.println("he/she will receive a grand prize of
$1,000,000");
else if(res == 0)
System.out.println("Sorry, no matches today. Try again!");
else
System.out.println("\n Less than 3 match");
}
}
Output 1:
Random Numbers:
50 53 19 35 1 46
Enter 6 Unique numbers:
Enter a number:
10
Enter a number:
53
Enter a number:
50
Enter a number:
10
Duplicate Number Entered:
Enter a number:
1
Enter a number:
46
Enter a number:
33
he/she will receive a $2000 prize
Output 2:
Random Numbers:
15 58 20 34 57 3
Enter 6 Unique numbers:
Enter a number:
15
Enter a number:
58
Enter a number:
3
Enter a number:
57
Enter a number:
20
Enter a number:
34
he/she will receive a grand prize of $1,000,000
Please help with this, and leave comments explainging the code you wrote, thank you for your...
Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an array of six integers named lotteryNumbers, and another array of six integers named userLotteryPicks. The class' constructor should use the Random class to generate a unique random number in the range of 1 to 60 for each of the 6 elements in the lotteryNumbers array. Thus, there should be a loop that keeps generating random numbers until all 6 numbers are unique. The Lottery class...
Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If you do actually win the lottery, please be sure to give back to your alma mater, Orange Coast College. We will be happy to put your name on the building!**) Ok, time to get real. The Fantasy 5 (TM) lottery is a game in which 5 numbers from 1 to 36 are randomly drawn by the State of California. If you correctly guess all...
need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...
Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...
Need help with assignment This assignment involves simulating a lottery drawing. In this type of lottery game, the player picks a set of numbers. A random drawing of numbers is then made, and the player wins if his/her chosen numbers match the drawn numbers (disregarding the order of the numbers). More specifically, a player picks k distinct numbers between 1 and n (inclusive), as well as one bonus number between 1 and m (inclusive). "Distinct" means that none of the...
*This needs comments for each line of code. Thanks in advance!* import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int numCount = scnr.nextInt(); int[] Array = new int[numCount]; for(int i = 0; i < numCount; ++i) { Array[i] = scnr.nextInt(); } int jasc = Array[0], gws = Array[1], numbers, tempo; if (jasc > gws) { tempo = jasc; jasc...
Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp { public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...
//please help I can’t figure out how to print and can’t get the random numbers to print. Please help, I have the prompt attached. Thanks import java.util.*; public class Test { /** Main method */ public static void main(String[] args) { double[][] matrix = getMatrix(); // Display the sum of each column for (int col = 0; col < matrix[0].length; col++) { System.out.println( "Sum " + col + " is " + sumColumn(matrix, col)); } } /** getMatrix initializes an...
need help with this JAVA lab, the starting code for the lab is below. directions: The Clock class has fields to store the hours, minutes and meridian (a.m. or p.m.) of the clock. This class also has a method that compares two Clock instances and returns the one that is set to earlier in the day. The blahblahblah class has a method to get the hours, minutes and meridian from the user. Then a main method in that class creates...
Hello, Could you please input validate this code so that the code prints an error message if the user enters in floating point numbers or characters or ANYTHING but VALID ints? And then could you please post a picture of the output testing it to make sure it works? * Write a method called evenNumbers that accepts a Scanner * reading input from a file with a series of integers, and * report various statistics about the integers to the...