1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lilavasa [31]
3 years ago
11

In JAVA please:

Computers and Technology
1 answer:
Nostrana [21]3 years ago
7 0

Answer:

If there's any problem with the out put, please let me know

RockPaperScissors.java

import java.util.Random;

import java.util.Scanner;

public class RockPaperScissors {

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

static Scanner sc = new Scanner(System.in);

public static void main(String[] args) {

while(true)

{

char user=selection();

char computer=CP();

w(user,computer);

char ch=Repeat();

if(ch=='y' || ch=='Y')

continue;

else

break;

}

}

private static char Repeat() {

//Getting the character from the user 'Y' or 'y' or 'N' or 'n'

System.out.print("Do you want to Play again (Y/N) ?");

char ch = sc.next(".").charAt(0);

return ch;

}

private static void w(char user, char computer) {

String winner ="";

/* Based on user and computer selected numbers

* the corresponding block will get executed

*/

if (user == 'r' && computer == 's')

{

winner = "Rock versus Scissors..You win!";

}

else if (user == 's' && computer == 'r')

{

winner = "Scissors versus Rock..You Lose!";

}

else if (user == 'r' && computer == 'p')

{

winner = "Rock versus Paper..You Lose!";

}

else if (user == 'p' && computer == 'r')

{

winner = "Paper versus Rock..You Win!";

}

else if (user == 'p' && computer == 's')

{

winner = "Paper versus Scissors..You lose!";

}

else if (user == 's' && computer == 'p')

{

winner = "Scissors versus Paper..You Win!";

}

else

{

if (user == 'r' && computer == 'r')

{

winner = "Rock versus Rock...Tie!";

}

else if (user == 'p' && computer == 'p')

{

winner = "Paper versus Paper...Tie!";

}

else if (user == 's' && computer == 's')

{

winner = "Scissors versus Scissors...Tie!";

}

}

System.out.println(winner);

}

private static char CP() {

char comp = 0;

//Creating an random class object

Random r = new Random();

int num=r.nextInt((3 - 1) + 1) + 1;

if(num==1)

comp='r';

else if(num==2)

comp='p';

else if(num==3)

comp='s';

return comp;

}

private static char selection() {

char user;

while(true)

{

System.out.print("Enter Choice Rock 'r',Paper 'p', Scissors 's' :");

user=sc.next(".").charAt(0);

if(user!='r' && user!='p' && user!='s')

{

System.out.println("** Invalid Input **");

continue;

}

else

break;

}

return user;

}

}

__________________

Output:

Enter Choice Rock 'r',Paper 'p', Scissors 's' :r

Rock versus Paper..You Lose!

Do you want to Play again (Y/N) ?y

Enter Choice Rock 'r',Paper 'p', Scissors 's' :r

Rock versus Paper..You Lose!

Do you want to Play again (Y/N) ?y

Enter Choice Rock 'r',Paper 'p', Scissors 's' :r

Rock versus Scissors..You win!

Do you want to Play again (Y/N) ?y

Enter Choice Rock 'r',Paper 'p', Scissors 's' :s

Scissors versus Paper..You Win!

Do you want to Play again (Y/N) ?y

Enter Choice Rock 'r',Paper 'p', Scissors 's' :p

Paper versus Paper...Tie!

Do you want to Play again (Y/N) ?n

You might be interested in
Sending messages electronically to one or more recipients is called
maks197457 [2]

Answer:

Forward all

Explanation:

7 0
3 years ago
Read 2 more answers
QUESTION 4 of 10: What term refers to the basic characteristics of a population segment, such as gender, age, and income?
marshall27 [118]
272727727272727226282829292
7 0
4 years ago
Read 2 more answers
Assume 151 and 214 are signed 8-bit decimal integers stored intwo’s complement format. Calculate 151 214 using saturating arithm
larisa [96]

Answer:

The result is -63

Explanation:

First, we discover the Binary value of 151 which is 10010111.

1 = most significant bit and it represents the sign as negative.

Two's compliment of 10010111, is calculated by adding 1 to one's compliment. We get 01101001 which is 105 in decimal.

Therefore the value of A (the first part) is -105.

Second, the binary value of 214 = 11010110.

1 = most significant bit and it represents the sign as negative.

Two's compliment of 11010110, is calculated by adding 1 to one's compliment. We get 00101010 which is 42 in decimal.

Therefore, the value of B (the second part) is -42.

Simplify further,

A - B = -105 - (-42)

        = -105 + 42

        =  -63

Therefore, the result is -63,

6 0
4 years ago
Identify 3 ways mobile phone could be used to contact a bank apart from making a phone call to the bank
Zepler [3.9K]

Answer:

1. Email

2. Website

3. Customer service

8 0
4 years ago
A ___describes a particular attribute of the dates item in a table​
Vikentia [17]

Answer:

\huge\star{\underline{\mathtt{\red{A}\red{n}\red{s}\red{w}\red{e}\red{r}}}}\huge\star

.

<h3><em>A</em><em><u> objective</u></em><em><u> </u></em><em><u>of</u></em><em><u> technique</u></em><em> </em><em>describes a particular attribute of the dates item in a table</em><em>.</em></h3>

<em>.</em>

<em>I </em><em>hope</em><em> </em><em>this</em><em> </em><em>helps</em><em> </em><em>you</em><em>.</em><em>.</em><em>.</em><em>.</em><em>.</em><em>.</em><em>.</em>

5 0
3 years ago
Other questions:
  • ________ network each device is connected directly to a central network switch.
    8·1 answer
  • The Tab dialog box helps you set tabs in your word processing document. What does this dialog box control the movement of when y
    15·2 answers
  • A restaurant has a case type that allows customer to book the dining room for events. Customers provide basic information includ
    7·1 answer
  • Write an abstract data type for a queue in Java whose elements are generic elements of type T that have an associated integer pr
    15·2 answers
  • Write the algorithm for finding the perimeter of a rectangle using English like form step by step
    10·1 answer
  • "1jaiz4 and 1 more users found this answer helpful" - who the heII is 1jaiz4?
    12·1 answer
  • What is the function below Missing?
    7·2 answers
  • PLEASE HELP ME WITH MY UNIT TEST!!!!!!!!!!!!!! I'M STRUGGLING AND I AM ESPECIALLY STUCK ON THIS ONE!!!!!!!!!!!!!!!!!!!!!! FOR BR
    7·1 answer
  • Please i need your help
    12·1 answer
  • Use the round function to modify the program to display at most two digits of precision in the output number.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!