Write a Java program to simulate a pick 3, 4 or 5 lottery drawing. A lottery gam
ID: 3760466 • Letter: W
Question
Write a Java program to simulate a pick 3, 4 or 5 lottery drawing. A lottery game of this type will draw values between 0 and 9. You should use the Math.Random() or the java.util.Random() class to generate the values in the lottery drawing. The program should prompt the user for which lottery game they want to play. The program should also ask how many times they want to play the game. The output should show the numbers picked for each game and the sum of the numbers of all games. Here is a sample run:
Which lottery game do you want to play (Enter 3 for pick-3, 4 for pick-4 or 5 for pick-5? 3 How many games would you like to play? 10
Thank you! The numbers selected were:
349
247
331
032
931
924
452
110
017
863
The sum for all numbers picked was: 107
I started on this and im a little stuck. Here is where I'm at:
import java.util.Random;
import java.util.Scanner;
public class LotteryNumbers{
public static void main(String[] args){
Scanner userinput = new Scanner(System.in);
System.out.print("TIME TO PLAY THE LOTTERY");
System.out.print("Please select which lottery you would like to play.(Enter 3 for pick-3 Enter 4 for pick-4 Enter 5 for pick-5) You have selected:");
int gameSelected = userinput.nextInt();
System.out.println("How many games would you like to play? ");
int roundsSelection = userinput.nextInt();
System.out.println("Thank you! The numbers selected are: ");
int sum = 0;
Random randomGen = new Random();
I believe that my next move should be to enter in a for statement.
Please help :)
Thank you!
Explanation / Answer
import java.util.Random;
import java.util.Scanner;
public class LotteryNumbers
{
public static void main(String[] args)
{
Scanner userinput = new Scanner(System.in);
System.out.print("TIME TO PLAY THE LOTTERY");
System.out.print("Please select which lottery you would like to play.(Enter 3 for pick-3 Enter 4 for pick-4 Enter 5
for pick-5) You have selected:");
int gameSelected = userinput.nextInt();
System.out.println("How many games would you like to play[0 to 9 only]? ");
int roundsSelection = userinput.nextInt();
System.out.println("Thank you! The numbers selected are: ");
int sum = 0,R,i;
int a[]=new int[1000];
Random randomGen = new Random();
int Low = 10;
int High = 100;
if(gameSelected ==3)
{
Low =100;
High=999;
}
if(gameSelected ==4)
{
Low =1000;
High=9999;
}
if(gameSelected ==5)
{
Low =10000;
High=99999;
}
for(i=0;i<gameSelected;i++)
{
R = randomGen.nextInt(High-Low) + Low;
a[i]=R;
sum=sum+a[i];
System.out.println(a[i]);
}
System.out.println("The sum for all numbers picked was: "+sum);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.