Name: Anonymous 2010-10-18 19:03
So I'm writing a Rock Papper Scissors program for my programming class.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package lab4;
/**
*
* @author LAPPY
*/
// ****************************************************************
// 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 = null; //Computer's play -- "R", "P", or "S"
//Randomly generated number used to determine
int computerInt; //Randomly generated number used to determine
//computer's play
Scanner scan = new Scanner(System.in);
Random generator = new Random();
computerInt = generator.nextInt (3); //Generate computer's play (0,1,2)
//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;
}
//Get player's play from input-- note that this is stored as a string
System.out.println ("Enter your play: R, P, or S");
personPlay = scan.nextLine();
//Make player's play uppercase for ease of comparison
personPlay.toUpperCase();
//Print computer's play
System.out.println ("Computer play is " + computerPlay);
//See who won. Use nested ifs instead of &&.
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 covers rock. You lose!!");
if(personPlay.equals("P"))
if (computerPlay.equals("S"))
System.out.println("Scissors cut paper. You lose!!");
else if(computerPlay.equals("R"))
System.out.println("Paper covers rock. You win!!");
if (personPlay.equals("S"))
if (computerPlay.equals("R"))
System.out.println("Rock crushes scissors. You lose!!");
else if(computerPlay.equals("P"))
System.out.println("Scissors cut paper. You win!!");
}
}
The problem is, the "personPlay.toUpperCase();" won't do anything at all. I have to enter an uppercase letter as if that command isn't there.
What am I missing?
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package lab4;
/**
*
* @author LAPPY
*/
// ****************************************************************
// 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 = null; //Computer's play -- "R", "P", or "S"
//Randomly generated number used to determine
int computerInt; //Randomly generated number used to determine
//computer's play
Scanner scan = new Scanner(System.in);
Random generator = new Random();
computerInt = generator.nextInt (3); //Generate computer's play (0,1,2)
//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;
}
//Get player's play from input-- note that this is stored as a string
System.out.println ("Enter your play: R, P, or S");
personPlay = scan.nextLine();
//Make player's play uppercase for ease of comparison
personPlay.toUpperCase();
//Print computer's play
System.out.println ("Computer play is " + computerPlay);
//See who won. Use nested ifs instead of &&.
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 covers rock. You lose!!");
if(personPlay.equals("P"))
if (computerPlay.equals("S"))
System.out.println("Scissors cut paper. You lose!!");
else if(computerPlay.equals("R"))
System.out.println("Paper covers rock. You win!!");
if (personPlay.equals("S"))
if (computerPlay.equals("R"))
System.out.println("Rock crushes scissors. You lose!!");
else if(computerPlay.equals("P"))
System.out.println("Scissors cut paper. You win!!");
}
}
The problem is, the "personPlay.toUpperCase();" won't do anything at all. I have to enter an uppercase letter as if that command isn't there.
What am I missing?