I get the following errors when I compile it: java:75: operator % cannot be applied to java.lang.String,java.lang.String if( Player % Computer == "P")
java:77: operator % cannot be applied to java.lang.String,java.lang.String
if( Player % Computer == "S")
I would also appreciate it, if someone looked over my work to make sure that I've everything correctly.
Thanks!
import java.util.Scanner;
import java.util.Random;
public class RPS
{
public static void main (String[] args)
{
String Player;
String Computer;
int ComputerInt;
Scanner scan = new Scanner(System.in);
Random generator = new Random();
//------------------------------------------------
//User will enter an upper or lowercase r, p, or s
//for his/her selection.
//-------------------------------------------------
System.out.println ("R = Rock");
System.out.println ("P = Paper");
System.out.println ("S = Scissors");
//----------------------------------------------------
//Generate a random number (integer value of 0, 1, or 2)
//for the computer's play.
//------------------------------------------------------
ComputerInt = generator.nextInt(3);
//-----------------------------------------------------
//Convert the computer's random integer to an uppercase
//letter using a switch structure.
//-----------------------------------------------------
switch (ComputerInt)
{
case 0:
Computer = "R";
System.out.println ("Computer chose rock.");
break;
case 1:
Computer = "P";
System.out.println ("Computer chose paper.");
break;
case 2:
Computer = "S";
System.out.println ("Computer chose scissors.");
break;
}
//------------------------------------------------------
//Display the computer's play as a string. For example:
//The computer's play is S
//------------------------------------------------------
System.out.println ("The computer chose" + Computer);
//---------------------------------------------------------------
//Determine who won. Use nested if statements (not using && or ||).
//Display the results as a sentence. For example:
//Rock crushes scissors, you win!
//Remember: Rock crushes scissors. Scissors cut paper.
//Paper covers rock.Ties are possible.
//----------------------------------------------------------------
if(Player == Computer)
{
if( Player % Computer == "P")
{
if( Player % Computer == "S")
System.out.println("Rock crushes scissors, you win!");
else
System.out.println("Scissors cut paper.");
}
else
System.out.println("Paper covers rock.");
System.out.println();
}
}
}
This post has been edited by swim_fan08: 24 March 2009 - 04:21 PM

New Topic/Question
Reply




MultiQuote





|