Answer to Question #301066 in Java | JSP | JSF for Kiddo

Question #301066

Develop a Java program for a lottery winning game. The secret win number is “980-6578-854-976”. The user is allowed to enter their try, up to 10 times. For any incorrect entry, the program displays “Sorry. Try Again.” For each wrong entry, the program displays number of attempts remaining. When the 10 attempts are over, it displays “You have exhausted your chances to win. Bye.” The user can also press “E” to opt out of the game any time during the attempts. If they enter the win number at any point, the program displays “CONGRATULATIONS!! YOU HAVE WON 6 MILLION KSHS.” Then allows the user to enter their name, IDNO and phone number, after which the program displays e.g. “John Kamau, IDNO 89765, Phone Number 07863539, we shall contact you on information on how to receive your price. Have a good day”.


1
Expert's answer
2022-02-22T12:13:42-0500
import java.util.Scanner;


class App {


	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		String secretWinNumber = "9806578854976";
		int attempts = 0;


		while (attempts < 10) {
			System.out.print("Enter the secret win number (E - to exit): ");
			String userSecretWinNumber = keyBoard.nextLine();
			if (userSecretWinNumber.compareToIgnoreCase("E") == 0) {
				attempts = 12;
			} else if (userSecretWinNumber.compareToIgnoreCase(secretWinNumber) == 0) {
				System.out.println("CONGRATULATIONS!! YOU HAVE WON 6 MILLION KSHS.");
				System.out.print("Enter the name: ");
				String name = keyBoard.nextLine();
				System.out.print("Enter IDNO: ");
				String IDNO = keyBoard.nextLine();
				System.out.print("Enter the phone number: ");
				String phoneNumber = keyBoard.nextLine();
				System.out.printf(
						"%s, IDNO %s, Phone Number %s, we shall contact you on information on how to receive your price. Have a good day\n\n",
						name, IDNO, phoneNumber);
				attempts = 12;
			} else {
				System.out.println("Sorry. Try Again");
			}
			attempts++;
		}
		if (attempts < 12) {
			System.out.println("You have exhausted your chances to win. Bye.");
		}


		keyBoard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS