Ok, hi every one. This is my first time here on stackoverflow, I've doing a lot of searching here so I figure that this would be a good place to get some answers. I am a beginner programmer currently in school. I am working on my assignment of creating a rock, paper, scissors game. I feel like my code is good so far, I compiled it but it wont run at all. Take a look:
import java.util.Scanner;
public class RPSGame {
public static void gameModeSelect ()
{
System.out.println("Welcome to Rock, Paper, Scissors 1.0 !\n Please select your game mode: ");
System.out.println("1. Player vs. Computer\n 2. Player vs. Player ");
}
public static void winLoss ()
{
int P1 = 0, P2 = 0;
if (P1 == 'P' && P2 == 'R'){
System.out.println("Paper covers rock!\nPlayer one wins!");
} else if (P1 == 'R' && P2 == 'P'){
System.out.println("Paper covers rock!\nPlayer two wins!");
}
if (P1 == 'R' && P2 == 'S'){
System.out.println("Rock breaks scissors!\nPlayer one wins!");
} else if (P1 == 'S' && P2 == 'R'){
System.out.println("Rock breaks scissors!\nPlayer two wins!");
}
if (P1 == 'S' && P2 == 'P'){
System.out.println("Scissor cuts paper!\nPlayer one wins!");
} else if (P1 == 'P' && P2 == 'S'){
System.out.println("Scissor cuts paper!\nPlayer two wins!");
}
}
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int P1;
P1 = 0;
int P2;
P2 = 0;
int modeSelect;
modeSelect = keyboard.nextInt();
gameModeSelect ();
if (modeSelect == 1){
System.out.println("Oops, this feature in currently unavailable. Play with a friend for now :-)");
} else if (modeSelect == 2){
System.out.println("Rules of the game: R = Rock, P = Paper, S = Scissors\n Good luck! ");
System.out.println("Player one: Enter your move");
P1 = keyboard.nextInt();
System.out.println("Player two: Enter your move");
P2 = keyboard.nextInt();
} else if (modeSelect > 2){
winLoss();
}
}
}
It compiles without errors but nothing runs, however when I enter anything in the running section I get this error:
run:
S
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at RPSGame.main(RPSGame.java:41)
C:\Users\AVLG2\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 12 seconds)
I'm stuck here, and my assignment is due tomorrow. Any suggestions? It would be highly appreciated. BTW, glad to be part of the stackoverflow community!!