Write a Java program that determines if a person hits the \"Pick 3\" loterry num
ID: 672339 • Letter: W
Question
Write a Java program that determines if a person hits the "Pick 3" loterry numbers. Have the program to randomly create a 3 digit lottery number. Have the user enter the number they will be playing and the results: (DO NOT USE ARRAYS or STRINGS)
-If the user input matches the lottery number in the exact order, the award is $5Million.
-If all the digits in the user input match all the digits in the lottery number, the award is $500,000.
-If one digit in the user input matches a digit in the lottery number, the award is $5,000.
-If nothing matches, inform the person, “Sorry, try again!”.
BOOK USED: Java How to Program, 10th Edition, by Paul Deitel and Harvey Deitel, Publisher: Prentice Hall ONLY PRACTICE
BEST ANSWER POSSIBLE
Explanation / Answer
import java.util.Random;
import java.io.*;
class jackpot{
public static void main(String args[])throws IOException
{
Random no = new Random();
int Low = 100,High = 999,a,b,c,x,y,z,temp1,temp2,dig;
int rand = no.nextInt(High-Low) + Low;
System.out.println("Lucky lottery number is: "+rand);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Kindly enter your number: ");
int player= Integer.parseInt(br.readLine());
temp1=rand;temp2=player;
x=temp1%10;a=temp2%10;
temp1=temp1/10;temp2=temp2/10;
y=temp1%100;b=temp2%10;
temp1=temp1/10;temp2=temp2/10;
z=temp1%10;c=temp2%10;
if(rand==player)
System.out.println("Congratulations You just won 5 Million Dollars");
else if(((a==x)&&(b==y)&&(c==z))||((a==x)&&(b==z)&&(c==y))||((a==y)&&(b==z)&&(c==x))||((a==y)&&(b==x)&&(c==z))||((a==z)&&(b==x)&&(c==y))||((a==z)&&(b==y)&&(c==x)))
System.out.println("Congratulations You just won 500,000 Dollars");
else if(((a==x)||(b==y)||(c==z))||((a==y)||(b==z)||(c==x))||((a==z)||(b==x)||(c==y)))
System.out.println("Congratulations You just won 5,000 Dollars");
else
System.out.println("Sorry, try again!");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.