Question: Need help implementing this Java code package hmwk3; import java.util.Scanner; /** * Revise the Lottery.java from self-review part, to * generate a lottery of a

Need help implementing this Java code

package hmwk3;

import java.util.Scanner;

/** * Revise the Lottery.java from self-review part, to * generate a lottery of a three-digit number. The program * prompts the user to enter a three-digit number and determines * whether the user wins according to the following rules: * If the user input matches the lottery number in the exact order, the award is $10,000. * If all digits in the user input match all digits in the lottery number, the award is $3,000. * If one digit in the user input matches a digit in the lottery number, the award is $1,000. * @author DR * */ public class PE05 { public static void main(String[] args) { // Generate a lottery int lottery = (int)(Math.random() * 1000);

// Prompt the user to enter a guess Scanner input = new Scanner(System.in); System.out.print("Enter your lottery pick (three digits): "); int guess = input.nextInt();

// Get digits from lottery int lotteryDigit1 = lottery / 100; int remainingLotteryDigits = lottery % 100; int lotteryDigit2 = remainingLotteryDigits / 10; int lotteryDigit3 = remainingLotteryDigits % 10;

// Get digits from guess int guessDigit1 = guess / 100; int remainingGuessDigits = guess % 100; int guessDigit2 = remainingGuessDigits / 10; int guessDigit3 = remainingGuessDigits % 10;

System.out.println("The lottery number is " + lottery);

// Check the guess if (guess == lottery) { System.out.println("Exact match: you win $10,000"); } //TODO else if statement sees if the input from user mathches the lottery number, the numbers can be in any order else if () { } else if (guessDigit1 == lotteryDigit1 || guessDigit1 == lotteryDigit2 || guessDigit1 == lotteryDigit3 || guessDigit2 == lotteryDigit1 || guessDigit2 == lotteryDigit2 || guessDigit2 == lotteryDigit3 || guessDigit3 == lotteryDigit1 || guessDigit3 == lotteryDigit2 || guessDigit3 == lotteryDigit3) { System.out.println("Match one digit: you win $1,000"); } else { System.out.println("Sorry, no match"); } input.close(); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!