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
Derek is creating an animation for his class project. What is the first step Derek should follow while creating the animation?
quester [9]

Answer:

D

Explanation:

6 0
3 years ago
Read 2 more answers
In a large kitchen what is meant by the partie system? Who devised this system?
denis-greek [22]

Answer:

While at the Savoy in London, Escoffier formally introduced his army-influenced organisational method to the kitchens there. It became known as the Chef de partie system, and the idea was to avoid duplication of tasks, and to make communication between the various staff members easier.

8 0
3 years ago
Which feature in word automatically corrects typos, minor spelling errors, and capitalization as you type? autocomplete spelling
Fed [463]
I think auto correct.....,
8 0
3 years ago
You have repaired a broken lcd panel in a notebook computer. however, when you disassembled the notebook, you bent the hinge on
Shtirlitz [24]

First things first, you'll have to explain what happened, Secondly you must give the customer the option to choose whether he/she would prefer to temporarily take the laptop and schedule another time to have the hinge be repaired as you can provide the reason that you have prioritize to fix the functional aspect of the laptop rather than the cosmetic issues of the laptop. Putting yourself in the shoes of the customer whilst picking your statement would help to alleviate the concern or complain from the customer.

4 0
4 years ago
I NEED HELP ASAP!!!!!! IM IN THE MIDDLE OF A QUIZ!!!! Why did the film industry agree to set standards for film production?
Pani-rosa [81]

Answer:

My guess is "It was cheaper to follow standards than having to guess what audiences wanted."

Explanation:

Not 100% but I tRiEd

5 0
3 years ago
Other questions:
  • Find an element inside a div using javascript
    12·1 answer
  • ou have spent the last two hours creating a report in a file and afterwards you use cat to create a new file. Unfortunately the
    13·1 answer
  • What invention was key to computers being moved into homes and personal use?
    10·2 answers
  • Someone who wants to learn a skilled trade on the job should consider
    6·2 answers
  • What are some other features of sending attachments in Outlook 2016? Check all that apply.
    9·2 answers
  • The template code provided is intended to take two inputs, x and y, from the user and print "pass" if one or more of the followi
    5·1 answer
  • What are some ways you can work with templates? Check all that apply.
    9·2 answers
  • what stage is the most inner part of the web architecture where data such as, customer names, address, account numbers, and cred
    11·1 answer
  • What could be done to make sure that people follow copy right laws?
    13·2 answers
  • In the 1760s and early 1770s, the British government wanted to raise money by taxing the residents of its colonies in North Amer
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!