Write a program that emulates the popular lottery game \"Powerball\". First ask
ID: 3847838 • Letter: W
Question
Write a program that emulates the popular lottery game "Powerball". First ask the user how many times he wants to play. Then ask the user for 5 numbers between 1 and 69, and one additional "Power Ball" between 1 and 26. Then simulate the drawing as many times as indicated initially by creating random numbers in the given ranges, and comparing them to the numbers the user put in. After each drawing, let the user know if he won, and how many numbers he has guessed correctly. Output each drawing's result in the console.Explanation / Answer
import java.util.Scanner;
import java.util.Arrays;
public class Powerball {
public static void main(String a[])
{
final int max=69;
int powerball,n,elem,temp,iloop,iloop1,iloop2,iloop3,match=0;
int arr[];
int draw[];
arr=new int[5];
draw=new int[5];
Scanner sc=new Scanner(System.in);
System.out.println("Enter how many times u want to play:");
n=sc.nextInt();
System.out.println("Enter The 5 Numbers:");
for(iloop=0;iloop<5;iloop++) //taking input through user
{
System.out.println("Enter The Number Between 1 & 69:");
arr[iloop]=sc.nextInt();
}
System.out.println("Enter The powerBall(Between 1 & 26):");
powerball=sc.nextInt();
for(iloop=0;iloop<n;iloop++) //traversing loop n times
{
System.out.println();
elem=max;
match=0;
for( iloop1 = 0; iloop1< 5; iloop1++ ) //assingning Random Value
{
temp = (int)( Math.random() * elem);
draw[iloop1]=temp;
}
for(iloop1=0;iloop1<5;iloop1++)
{
System.out.print(arr[iloop1]+" ");//printing user inputed values
}
System.out.println();
for(iloop1=0;iloop1<5;iloop1++) //printing Random Value
{
System.out.print(draw[iloop1]+" ");
}
for(iloop2=0;iloop2<5;iloop2++)
{
for(iloop3=0;iloop3<5;iloop3++)
{
if(arr[iloop2]==draw[iloop3]) //finding how many values matches
{
match=match+1;
}
}
}
if(5==match) //if all values matches
{
System.out.println("Congratulation!!You Have Won..!!");
}
else
{
System.out.println("No. Of Elements Match:"+match);
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.