In: Computer Science
write the outline pseudocode (code is also allowed) for the following problem...
Catherine wants to simulate a lottery game. What steps would this require?
Imagine that Catherine wants a computer to simulate a lottery game. The computer will be generating two-digit numbers. Each time the computer generates a number, the user is first invited to guess what the number is. If the user guesses the exact number, the award is 10 000 EUR. If the user makes a correct guess on one of the digits, and on the right place, the award is 3 000 EUR. If the user guesses correctly that a digit was selected, but not which position it is in, the award is 100 EUR.
Examples:
Computer: 96: Computer: 47: Computer: 42:
User: 96 User: 43 User: 29
Award Award Award
10 000 EUR 3 000 EUR
100 EUR
Catherine’s algorithm and program can follow the below-mentioned steps:
Step 1: The computer generates a random two-digit number.
Step 2: The user makes a guess of what the number is and enters it through the keyboard.
Step 3: The computer compares the two numbers and evaluates whether the user wins anything.
Step 4: The computer displays the number that was generated in
step 1.
Step 5: the computer displays a message of whether the user wins
something, as suggested
above.
Step 6: The computer repeats the procedure from step 1 to step 5. The game is played 3 times.
The code is written in java (as asked pseudo code (code is also allowed))
Code :
import java.io.*;
import java.util.*;
class Game{
public static void main(String[] args)
{
Scanner scan = new
Scanner(System.in);
Random random = new Random();
for(int i=0;i<3;i++){
int computerNumber = random.nextInt(90)+10; // for random number between 10 to 99
System.out.println("Enter the guessing number : ");
int guess =
scan.nextInt();
if(computerNumber == guess){
System.out.println("The computer generated
number is : " + computerNumber);
System.out.println("The guessed number is : " +
guess);
System.out.println("Award : 10000 EUR");
}
else if(computerNumber/10 == guess/10 || computerNumber%10 == guess%10){
System.out.println("The computer generated
number is : " + computerNumber);
System.out.println("The guessed number is : " +
guess);
System.out.println("Award : 3000 EUR");
}
else if(computerNumber/10 == guess%10 || computerNumber%10 == guess/10){
System.out.println("The computer generated
number is : " + computerNumber);
System.out.println("The guessed number is : " +
guess);
System.out.println("Award : 100 EUR");
}
else{
System.out.println("The computer generated
number is : " + computerNumber);
System.out.println("The guessed number is : " +
guess);
System.out.println("Award : 0 EUR");
}
}
}
}
Screenshot of the full working code along with output: