Hey guys I am trying to write this code to play rock, paper, scissors against the computer. No matter what letter I type in it converts it to 0 and also randomly gives the computer 0 and calls it a tie every time I try it.
/* File Name: rockPaperScissorsGame Programmer: David Wheeler Purpose: Creates the rock, paper, scissor game. */ import javax.swing.JOptionPane; // Needed for JOption class to recieve input. import java.util.Scanner; // Have to import in order to use the Scanner class. import java.util.Random; // Needed for Random class public class rockPaperScissorsGame { public static void main (String[] args) { int CT = 0; String user = "0"; //First thing call the directions funtion to explain the game. directions(); //get the computers choice. computersTurn(CT); //get the users choice. usersTurn(user); //Display the computers choice and the winner. displayResults(user, CT); } public static void directions() { JOptionPane.showMessageDialog(null,"\nTo play the game you type R for ROCK, P for PAPER, or S for Scissors\n\n"+ "A winner is selected according to the following rules:\n\n"+ "* If one player chooses rock and the other player chooses scissors,\n"+ "then rock wins, (The rock smashes the scissors.)\n\n"+ "* If one player chooses scissors and the other player chooses paper,\n"+ "then scissors wins. (Scissors cuts paper.) \n\n"+ "* If one player chooses paper and the other player chooses rock, then paper\n"+ "wins. (Paper wraps rock.)\n\n"+ "* If both players make the same choice, the game must be played again to\n"+ "determine the winner."); } public static int computersTurn(int CT) { Random randomNumbers = new Random(); CT = randomNumbers.nextInt(3); return CT; } public static String usersTurn(String user) { user = JOptionPane.showInputDialog("What is your choice? "); return user; public static void displayResults(String user, int CT) { JOptionPane.showMessageDialog(null,"You have" + user + "and the computer has" + CT + "\n"); if (user == "R" && CT == 2) { JOptionPane.showMessageDialog(null,"You Win! Rock smashes Scissors."); } else if (user == "S" && CT == 0) { JOptionPane.showMessageDialog(null,"You Lose! Rock smashes Scissors."); } else if (user == "P" && CT == 0) { JOptionPane.showMessageDialog(null,"You Win! Paper wraps rock."); } else if (user == "R" && CT == 1) { JOptionPane.showMessageDialog(null,"You Lose! Paper wraps rock."); } else if (user == "S" && CT == 1) { JOptionPane.showMessageDialog(null,"You Win! Scissors cuts paper."); } else if (user == "P" && CT == 2) { JOptionPane.showMessageDialog(null,"You Lose! Scissors cuts paper."); } else { JOptionPane.showMessageDialog(null,"It's a tie. Play again to beat the tie"); } } }