Question

Design the following game using a function in R studio: 1-The user input a number between...

Design the following game using a function in R studio:

1-The user input a number between 1-12:

2- Then the computer generates a number between (1-12)

3- Then: If the number generated by the computer is less than that of the user, then the user wins.

If the number that is generated by the computer is greater than that of the user, then the computer wins.

If the numbers generated by the user and computer are the same, then it is a super win for the user!

Homework Answers

Answer #1

import java.util.*;
public class Game {

   public static void main(String[] args)
   {
       Random rnum = new Random(); //reference to Random no.
       int SysRandomNumber = rnum.nextInt(12); //Random no. generated by system
       Scanner sc= new Scanner(System.in);
       System.out.print("Please Enter Your Name:- ");
       String UserName= sc.next();
       System.out.println("");
       System.out.println("W E L C O M E T O G A M E " + UserName);
       System.out.println("");
       System.out.print(UserName+ " Please Enter the number between (1-12):- ");
       int UserRandomNumber= sc.nextInt(); //Number enter by User
       System.out.println("");
       if(UserRandomNumber > 0 && UserRandomNumber <= 12) //Verify user enter number between (1-12)
       {
           if(SysRandomNumber == UserRandomNumber) //if statement for Super win
           {
               System.out.println("C O N G R A T U L A T I O N " + UserName + " S u p p e r w i n t o Y o u ! !");
           }
           else if (UserRandomNumber > SysRandomNumber)  //if statement for User win
           {
               System.out.println("C O N G R A T U L A T I O N " + UserName + " Y o u w i n ! !");
           }
           else if (SysRandomNumber > UserRandomNumber)  //if statement for System win
           {
               System.out.println("S O R R Y " + UserName + " Y o u L O O S E ! !");
           }
       }
       else {
           System.out.println(UserName+" Y o u E N T E R W R O N G V A L U E");
       }

   }

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In R- Studio : Write a function that takes as an input a positive integer and...
In R- Studio : Write a function that takes as an input a positive integer and uses the print() function to print out all the numbers less than the input integer. (Example: for input 5, the function should print the numbers 1,2,3,4 { for input 1, the function should not print a number.) Write a recursive function, do not use any of the loop commands in your code.
Game to guess a number %% Guess Number Game while(1) count=0; guess=input('Guess a number between 0...
Game to guess a number %% Guess Number Game while(1) count=0; guess=input('Guess a number between 0 to 10 '); if(R>guess) disp('Your guess is too small') elseif (R<guess) disp('Your guess is too large') elseif (R==guess) disp('You are correct! It is ');guess R=floor( rand()*10 ); end count=count+1; if(count==3) break; end end You need to modify this code: (1)Player fails the game if you cannot make it within 3 tries. (2)Player can do this game up to 10 times. (3)If player input is...
1)Write a program that asks a user for a number. If (and only if) the number...
1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid” 2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid” 3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars....
Lottery The lottery game matches three different integer numbers between 1 and 10. Winning depends on...
Lottery The lottery game matches three different integer numbers between 1 and 10. Winning depends on how many matching numbers are provided by a player. The player provides three different integers between 1 and 10. If there is a match of all 3 numbers, the winning $ 1000. If there is a match with 2 numbers, the winning $ 10. If there is a match with 1 number, the winning $ 1. With no match, the winning is $0. Write...
Write a C program that prompts the user to input as many unsigned(n) as the user...
Write a C program that prompts the user to input as many unsigned(n) as the user wants to type, terminated by non negative number You may assume without checking that when the user is supposed to type an unsigned, he nevertypes a double You may assume without checking that when the user is supposed to type an unsigned, he nevertypes a negative number. For each number the user types, output whether that number is prime or not. You won't need...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the computer through a user interface. The user will choose to throw Rock, Paper or Scissors and the computer will randomly select between the two. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should then reveal the computer's choice and print a statement indicating if the user won, the computer won, or if it was a tie. Allow...
A prime number (or a prime) is an integer greater than 1 that is not a...
A prime number (or a prime) is an integer greater than 1 that is not a product of two smaller integer. Created a program on visual studio named PrimeNumberTest that does the following: 1) prompt the user for input of an integer 2) test if the integer is a prime number 3) display the test result  
Goal: Write a simple number guessing game in java. The game picks a number between bounds...
Goal: Write a simple number guessing game in java. The game picks a number between bounds input by the user, then user has to guess the number. The game will tell you if your guess is too high or too low. When you guess it, the game will tell you how many guesses it took Run multiple games and print statistics (# games, # guesses, avg) when all done. Sample Run: G U E S S I N G G...
The​ random-number generator on calculators randomly generates a number between 0 and 1. The random variable​...
The​ random-number generator on calculators randomly generates a number between 0 and 1. The random variable​ X, the number​ generated, follows a uniform probability distribution. ​(a) Identify the graph of the uniform density function. ​(b) What is the probability of generating a number between 0.740.74 and 0.910.91​? ​(c) What is the probability of generating a number greater than 0.930.93​?
Write a program that prompts the user to enter an integer number between 1 and 999....
Write a program that prompts the user to enter an integer number between 1 and 999. The program displays the sum of all digits in the integer if the input is valid; otherwise, it displays a message indicating that the integer is not between 1 and 999 and hence, is invalid. Name the program file Q1.cpp Example: if the user enters 12, sum of digits is 3. If the user enters 122, sum of digits is 5.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT