|
help with rock paper scissors
it compiles fine, but when i run it, and press r,s, or p, it gives me more than what i want....does anyone know what's wrong?
import java.util.Scanner;
import java.util.Random;
public class Rock
{
//instance variables / properties
private static String personPlay;
private static String computerPlay;
private static int computerInt;
private static int c=0;
private static int p=0;
private static int t=0;
public static void main(String[] args)
{
Random generator = new Random();
Scanner kb = new Scanner(System.in);
//Get player's play -- note that this is stored as a string
for(int a=1;a<=10;a++){
System.out.println("Enter one of the following: \"R\"ock, \"P\"aper, or \"S\"cissors");
personPlay=kb.nextLine();
//Make player's play uppercase for ease of comparison
personPlay=personPlay.toUpperCase();
//Generate computer's play (0,1,2)
computerInt = generator.nextInt(3);
//Translate computer's randomly generated play to string
switch (computerInt){
case 0: computerPlay = "R";break;
case 1: computerPlay = "P";break;
case 2: computerPlay = "S";break;
}
System.out.println("Computer plays: " + computerPlay);
if (personPlay.equals(computerPlay))
{System.out.println("It's a tie!");
t++;}
if (personPlay.equals("R"))
{
{
if (computerPlay.equals("S"))
p++;
System.out.println("Rock crushes scissors. You win!!");
}
{
if (computerPlay.equals("P"))
c++;
System.out.println("Paper covers rock. Computer wins!!");
}
}
if(personPlay.equals("S"))
{
{
if (computerPlay.equals("R"))
System.out.println("Rock crushes scissors. Computer wins!!");
c++;
}
{
if (computerPlay.equals("P"))
p++;
System.out.println("Scissors shred paper. You win!!");
}
}
if(personPlay.equals("P"))
{
{
if (computerPlay.equals("S"))
System.out.println("Scissors shred paper. Computer wins!!");
c++;
}
{
if (computerPlay.equals("R"))
System.out.println("Paper covers rock. You win!!");
p++;
}
}
System.out.println("Computer: "+c+" Player: "+p+" Ties: "+t);
}
}
}
|