HELP!!! I need to create a Lottery game application. Here are the rules: Generat
ID: 3570852 • Letter: H
Question
HELP!!! I need to create a Lottery game application. Here are the rules:
Generate four random numbers, each between 0 & 9 (inclusive). Allow the user to guess 4 numbers. Compare each of the user's guesses to the four random numbers and display a message that includes the user's guess, the randomly determined 4-digit number, and the amount of points the user has won -
I need to name the class Lottery.java, create a TestLottery.java class to instantiate and run the Lottery class, the Lottery class SHALL NOT have a main or perform input or output. All input and output must be done in the TestLottery class and shall be done using dialogs, NOT System.out, System.in or Scanner.
this is what I have so far:
import java.util.Random;
import javax.swing.JOptionPane;
public class TestLottery
{
public static void main(String[] args)
{
int[] randomNumber = new int[4];
Random random = new Random();
int[] userInput = new int[4];
for(int i =0; i<4;i++)
{
int userInput = JOptionPane.showInputDialog("Enter the %d number: ",i+1);
userInput[i] = input.nextInt();
}
for(int i =0; i<4;i++)
{
randomNumber[i] = random.nextInt(10);
}
int correctCount=0;
int userInput = JOptionPane.showMessageDiaglog(null, userInput);
for(int i=0;i<4;i++)
{
int userInput = JOptionPane.showMessageDialog(null, "%d ",userInput[i]);
}
int randomNumber = JOptionPane.showMessageDialog(null, randomNumber);
for(int i=0;i<4;i++)
{
int randomNumber = JOptionPane.showMessage(null, "%d ",randomNumber[i]);
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(randomNumber[i] == userInput[j])
{
correctCount++;
userInput[j] = 11;
break;
}
}
}
int correctCount = JOptionPane.showMessageDialog (null, "Your Score is: ");
switch(correctCount)
{
case 4:
int correctCount = JOptionPane.showMessage.Dialog(null, "1,000,0000");
break;
case 3:
int correctCount = JOptionPane.showMessage.Dialog(null, "2000");
break;
case 2:
int correctCount = JOptionPane.showMessage.Dialog(null, "100");
break;
case 1:
int correctCount = JOptionPane.showMessage.Dialog(null, "5");
break;
case 0:
default:
int correctCount = JOptionPane.showMessage.Dialog(null, "0");
}
}
}
}
Explanation / Answer
import java.util.*; class RandomNumbers { public static void main(String[] args) { int c; Random t = new Random(); // random integers in [0, 100] for (c = 1; cRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.