import java.util.Random; import java.util.Scanner; public class RockPaperScissors { public static void main (String[] args) { Random rand = new Random(); System.out.println ("How about a friendly game "+ "Rock, Paper, Scissors?"); System.out.println ("Choose 1 for rock, 2 for paper" + " or 3 for scissors"+ " then hit enter."); userPick(); computerPick(); winner(); } public static void userPick() { int userPick; Scanner keyboard = new Scanner(System.in); userPick = keyboard.nextInt(); switch (userPick) { case 1: System.out.println("You chose ROCK"); break; case 2: System.out.println("You chose PAPER"); break; case 3: System.out.println("You chose SCISSORS"); break; default: System.out.println("Invalid choice"); break; } } public static void computerPick() { int computerWeapon; Random weapon = new Random(); computerWeapon = (weapon.nextInt(3)+ 1); switch (computerWeapon) { case 1: System.out.println("Computer chose ROCK"); break; case 2: System.out.println("Computer chose PAPER"); break; case 3: System.out.println("Computer chose SCISSORS"); break; } } public static void winner() { int computerWeapon; Random weapon = new Random(); computerWeapon = (weapon.nextInt(3)+ 1); int userPick; Scanner keyboard = new Scanner(System.in); userPick = keyboard.nextInt(); if (computerWeapon == 1) { if (userPick==2) System.out.println ("Paper covers rock. "+ "You WIN!"); else if (userPick==3) System.out.println ("Rock crushes scissors. " + "You LOSE!"); else if (userPick==1) System.out.println ("You both chose rock. "+ "It's a tie game!"); } else if (computerWeapon == 2) { if (userPick == 1) System.out.println ("Paper covers rock. "+ "You LOSE!"); if (userPick == 3) System.out.println ("Scissors cut paper. "+ "You WIN!"); else if (userPick ==2) System.out.println ("It's a tie game!"); } else if (computerWeapon == 3) { if (userPick == 1) System.out.println ("Rock crushes scissors. " + "You WIN!"); if (userPick == 2) System.out.println ("Scissors cut paper. "+ "You LOSE!"); else if (userPick == 3) System.out.println ("It's a tie game!"); } } }
The game runs, but only up until the winner part, that does not run.