Hi I am having trouble with a Rock, paper, scissors program.
Just so there is no doubt, I am doing this for a course. I just want help with the error message.
The code I have got is rather simple. Though I am still clueless why i get errors.
any help is greatly appreciated.
Just so there is no doubt, I am doing this for a course. I just want help with the error message.
.\Input>javac RPScissors2.java
RPScissors2.java:29: error: '.class' expected
Game Rock = new Game(int comp, int other, int jj);
^
RPScissors2.java:29: error: <identifier> expected
Game Rock = new Game(int comp, int other, int jj);
^
RPScissors2.java:29: error: not a statement
Game Rock = new Game(int comp, int other, int jj);
^
RPScissors2.java:29: error: ';' expected
Game Rock = new Game(int comp, int other, int jj);
^
RPScissors2.java:29: error: ';' expected
Game Rock = new Game(int comp, int other, int jj);
^
5 errors
The code I have got is rather simple. Though I am still clueless why i get errors.
// File: SystemDetailsMenu.java
// Purpose: Rock, Paper, scissors game.
// Author: Gu7g34r
import java.util.Scanner;
class RPScissors2 {
int comp, other, jj; // computer's answer, other's answer.
String prson; // person's answer.
Scanner Sc = new Scanner(System.in);
public void main(String[] args) {
System.out.println( "This is a Rock, Paper, Scissors Game." ); // Just a little intro.
System.out.println( "Type R for Rock, P for Paper, S for Scissors." );
prson = Sc.next(); //get the players move.
if ( "R" == prson || "r" == prson ) {
other = 1;
}
else if( "P" == prson || "p" == prson ) {
other = 2;
}
else if( "S" == prson || "s" == prson ) {
other = 3;
}
else {
System.out.println( "That is not a valid option." );
}
Game Rock = new Game(int comp, int other, int jj);
}
public int Game( int comp, int other, int jj ) {
String R = "Rock"; // Rock = 1.
String P = "Paper"; // Paper = 2.
String S = "Scissors"; // Scissor = 3.
jj = (int)(Math.random() * 100 );
comp = jj % 3;
if ( Comp == 0 ) { //get the computers move.
comp = 3;
}
switch( comp ) { //print what the Computer is.
case 1:
System.out.println( "Computer1 is " + R );
break;
case 2:
System.out.println( "Computer1 is " + P );
break;
case 3:
System.out.println( "Computer1 is " + S );
break;
default:
System.out.println( "Error" );
break;
}
switch( other ) { //print what the users is.
case 1:
System.out.println( "Computer2 is " + R );
break;
case 2:
System.out.println( "Computer2 is " + P );
break;
case 3:
System.out.println( "Computer2 is " + S );
break;
default:
System.out.println( "Error" );
break;
}
if( comp == other ) { // compute and print who wins.
System.out.println( "It is a tie, want to play again?" );
}
else if( comp == other - 1 || ( 1 == other && 3 == comp )) {
if( CompVSprson ) {
System.out.println( "Player Wins! Wsnt to play again?" );
}
else {
System.out.println( "Computer2 Wins! Wsnt to play again?" );
}
}
else if( other == comp - 1 || ( 1 == comp && 3 == other )) {
if( CompVSprson ) {
System.out.println( "Computer Wins! Wsnt to play again?" );
}
else {
System.out.println( "Computer1 Wins! Wsnt to play again?" );
}
}
else {
System.out.println( "Error" );
}
return 1;
}
} // Done.
any help is greatly appreciated.