Could someone write the code for this in java? I cannot use java.util random(but i can use scanner). also, i cannot use switch or case.


Program Rock.java contains a skeleton for the game Rock, Paper, Scissors. Add statements to the program as indicated by the comments so that the program asks the user to enter a play, generates a random play for the computer, compares them and announces the winner (and why). For example, one run of your program might look like this:


Enter your play: R, P, or S


r


Computer play is S


Rock crushes scissors, you win!


Note that the user should be able to enter either upper or lower case r, p, and s. Add a loop to make sure the user only enters an R, P, or S. The user's play is stored as a string to make it easy to convert whatever is entered to upper case. Use if statements to convert the randomly generated integer for the computer's play to a string.


public class Rock


{


public static void main(String[] args)


{


String personPlay; //User's play -- "R", "P", or "S"


String computerPlay; //Computer's play -- "R", "P", or "S"


int computerInt; //Randomly generated number used to determine


//computer's play


// Add the code for each action beneath the comment. // more than one line may be needed in some cases // Get player's play -- note that this is stored as a string


// Make player's play uppercase for ease of comparison


// Generate computer's play (0,1,2) – use (int) (Math.random() * 3) to


// generate a random play


// Translate computer's randomly generated play to string // using mutually exclusive conditional statements


// Print computer's play


// See who won. Use nested ifs instead of &&.


}


}


People hardly ever play Rock, Paper, Scissors one game at a time. They play matches that are best 2 out of 3, best 3 out of 5, etc. Change your program to prompt the user for the odd number of games they want to play and use a loop to make sure it is an odd number. Then, add a loop to your program to play the game multiple times. Keep track of who wins, and make sure the loop stops when either the computer or the user has accumulated enough wins. Ties do not count in either the game total or the win totals – so a best 2 out of 3 match requires 3 games to be played where someone wins 2 times.

Answers

Answer 1

Program Rock.java contains a skeleton for the game Rock, Paper, Scissors. Open it and save it to your directory.

Add statements to the program as indicated by the comments so that the program asks the user to enter a play,

generates a random play for the computer, compares them and announces the winner (and why). For example, one run

of your program might look like this:

$ java Rock

Enter your play: R, P, or S

r

Computer play is S

Rock crushes scissors, you win!

Note that the user should be able to enter either upper or lower case r, p, and s. The user's play is stored as a

string to make it easy to convert whatever is entered to upper case. Use a switch statement to convert the randomly

generated integer for the computer's play to a string.*/

// ****************************************************************

// Rock.java

//

// Play Rock, Paper, Scissors with the user

//

// ****************************************************************

import java.util.Scanner;

import java.util.Random;

public class Rock

{

public static void main(String[] args)

{

String personPlay; //User's play -- "R", "P", or "S"

String computerPlay; //Computer's play -- "R", "P", or "S"

int computerInt; //Randomly generated number used to determine

//computer's play

Scanner scan = new Scanner(System.in);

Random generator = new Random();

System.out.println ("Enter R for Rock, P for Paper, S for Scissors: "); //Get player's play -- note that this is stored as a string

personPlay = scan.next();

personPlay = personPlay.toUpperCase();

computerInt = generator.nextInt(3);

switch (computerInt)

{

case 0:

{

computerPlay = "R";

break;

}

case 1:

{

computerPlay = "P";

break;

}

case 2:

{

computerPlay = "S";

break;

}

default:

{

computerPlay = "will not happen";

}

}

System.out.println ("Computer plays: " + computerPlay);

if (personPlay.equals(computerPlay))

{

System.out.println("It's a tie!");

}

else if (personPlay.equals("R"))

{

if (computerPlay.equals("S"))

System.out.println("Rock crushes scissors. You win!!");

else if (computerPlay.equals("P"))

System.out.println ("Paper eats rock. You lose!!");

}

else if (personPlay.equals("P"))

{

if (computerPlay.equals("S"))

System.out.println ("Scissor cuts paper. You lose!!");

else if (computerPlay.equals("R"))

System.out.println ("Paper eats rock. You win!!");

}

else if (personPlay.equals("S"))

{

if (computerPlay.equals("P"))

System.out.println ("Scissor cuts paper. You win!!");

else if (computerPlay.equals("R"))

System.out.println ("Rock breaks scissors. You lose!!");

}

else

{

System.out.println ("Invalid user input.");

}

}

}

// Enter R for Rock, P for Paper, S for Scissors:

// P

// Computer plays: P

// It's a tie!


Related Questions

limitations of systems analysis and design​

Answers

Answer:

Explanation:

Although System analysis offers an extensive range of benefits it might also have some disadvantages. One of the main disadvantages which is mostly overlooked is the risk of too much analysing which may be costly and time consuming. It is therefore part of the analyst's job to find the right balance.

Write a program that prompts the user to enter the month and year and displays the number of days in the month. For example, if the user entered month 2 and year 2000, the program should display that February 2000 has 29

Answers

Answer:

5

Explanation:

becauss it is impossible to actually di

beth chooses fresh vegetables every time she does marketing. she pares and cuts right away these vegetable considering that they are fresh. the moment she serves the appetizer, she washes the plate and uses it without drying. what statement best describes the situation inside teh box

Answers

Answer:

spell correctly "teh=the

Explanation:

beth chooses fresh vegetables every time she does marketing. she pares and cuts right away these vegetable considering that they are fresh. the moment she serves the appetizer, she washes the plate and uses it without drying. what statement best describes the situation inside teh box

Given the following code, what logic would you need to include to print all even values stored within the array:

int[] myArray = {1,2,38,4,54,6,7,8,9,10};

for (int i = 0; i < myArray.length; i++) {
//your code goes here
}
NOTE: Your response should be just the missing logic--not the entire problem set.

Answers

The missing logic whigh would allow all the even numbers stored within the array to be printed is if(myArray[i]%2 == 0)

Even numbers are divisible by 2, and hence, will leave no remainder when divided by 2.

Using the modulo operator, each iterated value in the array should be checked if it has a remainder of 0, when divided by 2.

Hence, if the remainder is 0, then the value is even and the value should be printed.

Learn more : https://brainly.com/question/17330574

Write a program that prompt the user to enter a bank balance. The balance entered by the user is read into a variable named balance. The program then prompts the user to enter the amount to be deposited. The amount entered by the user is read into a variable named deposit. The program that calculates the new balance, which is the present balance plus the deposit. The program then displays the new balance.

Answers

Answer:

ertyuiopoijuhgfdsa hiyoufun tresdfghytrefgytredfg

Explanation:

look for the words

Your worksheet contains a price in cell A5 and many formulas refer to that price how would you refer to that price in the formula

Answers

Answer:

$A$5

Explanation:

The A$5 would allow the row part of the reference to stay in place but would allow the column to change.

What does '$' mean in Excel formula?

An absolute reference in Excel exists as a cell address with the dollar symbol ($) in the row or column coordinates, like $A$1. The dollar sign specifies the connection to a given cell so that it stays unchanged no matter where the formula moves.

The A$5 would permit the row position of the authority to remain in place but would permit the column to modify. The location of the $ before either the row or column or both exists what specifies what component stands frozen. Therefore, the correct answer is option b) $A$5.

Complete question:

Your worksheet contains a price in cell A5, and many formulas refer to that price. How would you refer to that price in the formulas?

a. A5

b. $A$5

c. $A5

d. A$5

To learn more about Excel formula

https://brainly.com/question/26276255

#SPJ2

How do I get fix the code to make it input 3 values and get the correct output
-------------------------------------------------------------
12.20 LAB: Driving costs - functions

Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both floats) as input, and output the gas cost for 10 miles, 50 miles, and 400 miles.

Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
print('{:.2f}'.format(your_value))

Ex: If the input is:

20.0
3.1599

the output is:

1.58
7.90
63.20

Your program must define and call the following driving_cost() function. Given input parameters driven_miles, miles_per_gallon, and dollars_per_gallon, the function returns the dollar cost to drive those miles.

Ex: If the function is called with:

50 20.0 3.1599

the function returns:

7.89975

def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon)

Your program should call the function three times to determine the gas cost for 10 miles, 50 miles, and 400 miles.
---------------------------------------------------
I need help for this part
Ex: If the function is called with:

50 20.0 3.1599

how do I get it to input the three to get the output of 7.89975?
-------------------------------------
My code:

# Define your function here.
def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):
return (driven_miles/miles_per_gallon) * dollars_per_gallon

if __name__ == '__main__':
# Type your code here.

# Miles per gallon from input
miles_per_gallon = float(input())

#Dollars per gallon from input
dollars_per_gallon = float(input())


# Display the results as output

print('{:.2f}'.format(driving_cost(10, miles_per_gallon,dollars_per_gallon)))
print('{:.2f}'.format(driving_cost(50, miles_per_gallon,dollars_per_gallon)))
print('{:.2f}'.format(driving_cost(400, miles_per_gallon,dollars_per_gallon)))

Answers

Answer:Change your logic to:

for (int i = 0; i < 4; i++) {

System.out.println("Please input a number between zero to 3");

// use input and don't advance the scanner every time

int input = sc.nextInt();

if (input == 0) {

System.out.println("You have selected " + right);

}

if (input == 1) {

System.out.println("You have selected " + left);

}

// so on and so forth

}

By using sc.nextInt() four times, you are looking for the next token of the input which isn't there. So fetch the input for each run of the for-loop and it will work as expected.

Explanation:

Other Questions
Read each detail from the assignment text. Then, identify whether the detail indicates that the authors purpose is to inform, to entertain, or to persuade. "Many Hispanics spoke only Spanish, and most whites spoke only English. " "He knew he had the courage to blast through tacklers and the toughness to work all day in the beet fields, but this seemed harder. " "There were only two days before the next game. ". what is the total area of the figure below if each unit represents 5 yards? PLEASE PLEASE ANSWER ASAP FOR CHANCE OF BRAINLIEST!!!Photosynthesis Virtual Lab Summarize the results and provide an explanation or reasoning for what was observed. How does light color affect the rate of photosynthesis? Why does the color of light matter? question 6, almost done promise Find the slope between:(4,5)(3,5) If someone approached you stealthily, what would the persons movements be like? How many fossilized snail shells does Elmer have? help please............. In plane ABC the measure of angle A equals 42 the measure of angle B is five times the measure of angle C find the measure of angle B and the measure of angle C. Which of the followi g is equal to (91)+(51/10)+(11/100)? escribo mi opinion sobre los bunos habitos alimenticios What is the role of parentheses in expressions containing exponents? *English Review*1. Which of the following may result in language change?- punctuation- dialogue- isolationThe correct answer is isolation! Pls dont waste your time :) . A rectangular farm has an area of 15 square miles. If its length is 23 miles, what is its width? Matt weighed 60 pounds when he was 8 .He now weighs 80 pounds.Find the percent of increase in weight rounded to the nearest tenth classification of animals is done why ______ is my pen. *A. ThatB. ThoseC. TheseD. They8. Hello, ____ is Peter. Can I speak to Mr. Kim? *A. thatB. thoseC. thisD. these Please help ASAP, probability math question The size of a food Web is lmited by the Number of Mr. and Mrs. Ramirez both have jobs for which 22% of their earnings are taken out of their paychecks for taxes. How much would they need to earn together per month before taxes to have enough income to cover all the expenses in their budget?