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.
R-S-P Requirement: - write one C++ program that mimics the Rock-Scissor-Paper game. This program will ask...
R-S-P Requirement: - write one C++ program that mimics the Rock-Scissor-Paper game. This program will ask user to enter an input (out of R-S-P), and the computer will randomly pick one and print out the result (user wins / computer wins). - User's input along with computer's random pick will be encoded in the following format: -- user's rock: 10 -- user's scissor:          20 -- user's paper:            30 -- comp's rock:            1 -- comp's scissor:        2 -- comp's...
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...
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...
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....
Using R Programming language write a program to Check Prime Number (entered by the user) using...
Using R Programming language write a program to Check Prime Number (entered by the user) using control statements. Note: a prime number is an integer number greater than 1 whose only factors are 1 and itself. For example: 2, 3, 5, 7, 11, 13, 17.19 etc. USING R PROGRAMMING
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...
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...
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