I've run into a few problems with this one. I've tried my best following the directions. I can't figure out how to properly use "switch" since we haven't really put it to use in class. I want to create random integers (this I know how to do) that will become Strings (letters converted to strings). How would I go about converting the integers to "strings" from the alphabet?
Also, if I comment out the switch statement I get a compile error about my else and if states for the game.
Help with any details you can.
Thanks!
/*Rock, Paper, Scissors
$ 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();
//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)
//Translate computer's randomly generated play to string
switch (computerInt)
{
}
//Print computer's play
//See who won.
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 (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 (personPlay.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 (computerPlay.equals("R"))
System.out.println ("Rock breaks scissors. You lose!!");
}
}
}