Question

In: Computer Science

write the outline pseudocode (code is also allowed) for the following problem... Catherine wants to simulate...

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.

Solutions

Expert Solution

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:


Related Solutions

write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
Write the Pseudocode for the following programming problem. Write a program that will calculate a tip...
Write the Pseudocode for the following programming problem. Write a program that will calculate a tip based on the meal price and a 6% tax on a meal price. The user will enter the meal price and the program will calculate tip, tax, and the total. The total is the meal price plus the tip plus the tax. Your program will then display the values of tip, tax, and total. The tip amounts based on the mean price are as...
write the pseudocode and code to solve the following: you are given a list. determine the...
write the pseudocode and code to solve the following: you are given a list. determine the sum of all the elements in the list without using the built in puthon function sum(). Take your code and create your own function and name it my_sum_algo() which will return the sum of numbers PS please write comments in the code for my understanding, and please write jn jn PYTHON 3 languge. Thank you, have a great day !
Write a pseudocode for the following code: /*every item has a name and a cost */...
Write a pseudocode for the following code: /*every item has a name and a cost */ public class Item {    private String name;    private double cost;    public Item(String name, double cost) {        this.name = name;        this.cost = cost;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public double getCost() {        return cost;...
write JAVA code with the following condition Write the pseudocode for a new data type MyStack...
write JAVA code with the following condition Write the pseudocode for a new data type MyStack that implements a stack using the fact that you have access to a queue data structure with operations enqueue(), dequeue(), isEmpty(). Remember that every stack should have the operations push() and pop(). Hint: use two queues, one of which is the main one and one is temporary. Please note that you won’t be able to implement both push() and pop() in constant time. One...
Write source code in C to simulate the contiguous file allocation with the following conditions: •...
Write source code in C to simulate the contiguous file allocation with the following conditions: • Prompt the user to ender the no of files • Enter the name of the file • Enter the Starting block number • Enter no of block occupied by the file i.Condition: No two files must have the same block(if the user enter the same block no present in the previous file prompt the user “Block already in use”) #include<stdio.h> #include<conio.h> struct {    ...
Please use C programming to write the code to solve the following problem. Also, please use...
Please use C programming to write the code to solve the following problem. Also, please use the instructions, functions, syntax and any other required part of the problem. Thanks in advance. Use these functions below especially: void inputStringFromUser(char *prompt, char *s, int arraySize); void songNameDuplicate(char *songName); void songNameFound(char *songName); void songNameNotFound(char *songName); void songNameDeleted(char *songName); void artistFound(char *artist); void artistNotFound(char *artist); void printMusicLibraryEmpty(void); void printMusicLibraryTitle(void); const int MAX_LENGTH = 1024; You will write a program that maintains information about your...
1. Write pseudocode for the following program. You do not have to write actual C++ code....
1. Write pseudocode for the following program. You do not have to write actual C++ code. Assume you have a text file, that has been encrypted by adding 10 to the ASCII value of each character in the message. Design a decryption program that would reverse this process, and display the original message to the console.to the new array. 2.Write the code for the specified program. Use proper style and naming. Test and upload your code as a CPP file....
The following problem should be done in pseudocode. Problem 1 The programmer intends for this pseudocode...
The following problem should be done in pseudocode. Problem 1 The programmer intends for this pseudocode to display three random numbers in the range of 1 through 7. According to the way we've been generating random numbers in the book; however, there appears to be an error. Assume that the random() function is a built-in library function. Correct the pseudocode so that the program works as it should (This has 1 error and is easy to spot) //This program displays...
use modelsim write Verilog code for the following digital logic circuits and then simulate them by...
use modelsim write Verilog code for the following digital logic circuits and then simulate them by writing a testbench module for each of them , (a)The FSMs for the snail problem that is in the slides (a snail crawls over a tape that has 0 and 1 and smiles if it has detected the '10' bits using both Moore and Mealy FSM. Note that the pattern is '10' not '01' as in the slides. (b) A rock-paper-scissor game played by...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT