We are assigned to develop a program to play lottery.The program will randomly generates lottery of a two-digit numbers, and prompts the user to input a two-digit numbers. And if the numbers is only a single digit(0-9) the numbers must be treated as a two-digit number (00 - 09). Below are the conditions:
- If the user input matches the lottery numbers in exact order, the reward is Php 100,000.
- If all numbers in the user input matches all the lottery numbers, the reward is Php 30,000.
- If only one number in the user input matches a lottery number, the reward is Php 10,000.
This is my code so far...I actually have a problem on the 2nd condition (reward is Php30,000) whenever I matched only 1 number it says that "You matched all the lottery numbers. You won Php30,000."
public static void main(String[] args) {
Scanner lottery = new Scanner(System.in);
int a, b, c;
System.out.println("\t\t\t\t\t\t~Welcome to THE LOTTERY~");
System.out.println("Enter your first two-digit lucky number!");
int l = lottery.nextInt();
System.out.println("Enter your second two-digit lucky number!");
int y = lottery.nextInt();
System.out.println("Enter your last two-digit lucky number!");
int n = lottery.nextInt();
System.out.println("\nThe winning numbers are: ");
System.out.printf("%02d", a = (int)(Math.random() * 100));
System.out.printf("\n" + "%02d", b = (int)(Math.random() * 100));
System.out.printf("\n" + "%02d", c = (int)(Math.random() * 100));
if(l == a && y == b && n == c ){
System.out.println("\n\nCongratulations! You matched all the lottery numbers in order.");
System.out.println("You won Php100,000!");
}else if(l == a || a == l && l == b || b == l && l == c || c == l
&& y == a || a == y && y == b || b == y && y == c || c == l
&& n == a || a == n && n == b || b == n && n == c || c == n){
System.out.println("\n\nCongratulations! You matched all the lottery numbers.");
System.out.println("You won Php30,000!");
}else if(l == a || l == b || l == c || y == a || y == b || y == c || n == a || n == b || n == c){
System.out.println("\n\nCongratulations! You matched a lottery number.");
System.out.println("You won Php10,000!");
}else{
System.out.println("\n\nSorry, your lucky numbers didn't matched any of the lottery numbers!");
}
}`
Aucun commentaire:
Enregistrer un commentaire