The question is compPickInt will now be a 0,1, or 2. Use an ‘if-else if’ structure to convert the numbers to a char variable with the value of R or S or P and Prompt the user to enter R for Rock, S for Scissors or P for Paper. Use this java code to store the user’s choice as a char variable:char userPick = s.next().charAt(0).
I can't do the convertion int to char and the display is wrong like that;
I have my pick behind my back
What is your pick? R, S, P
P
My pick = 2 Your pick = P
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication33game;
import java.util.Random;
import java.util.Scanner;
import static javax.swing.text.html.HTML.Tag.P;
/**
*
* @author abdal
*/
public class JavaApplication33Game {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
Random ran = new Random();
System.out.println("I have my pick behind my back ");
System.out.println("What is your pick? R, S, P");
int compPickInt = ran.nextInt(3);
char userPick = s.next().charAt(0);
int R = 0;
int S = 1;
int P = 2;
System.out.println("My pick = "+compPickInt+ " Your pick = "+userPick);
System.out.println("I have my pick behind my back ");
//Condition R
if (userPick ==R && compPickInt == 1){
System.out.println("The ˜Rock player wins because a rock breaks scissors.");
}
if (userPick == R && compPickInt == 2) {
System.out.println("The ˜Paper player wins because paper covers a rock.");}
if (userPick == R && compPickInt == 0){
System.out.println("It is a tie - we both picked Rock");}
//Condition S
if (userPick == S && compPickInt == 0){
System.out.println("The ˜Rock player wins because a rock breaks scissors.");
}
if (userPick == S && compPickInt == 2) {
System.out.println("The ‘Scissors’ player wins because scissors cut paper");}
if (userPick == S && compPickInt == 1){
System.out.println("It is a tie - we both picked Rock");}
//Condition P
if (userPick == P && compPickInt == 0){
System.out.println("The ˜Paper player wins because paper covers a rock.");
}
if (userPick == P && compPickInt == 1) {
System.out.println("The ‘Scissors’ player wins because scissors cut paper.");}
if (userPick == P && compPickInt == 2){
System.out.println("It is a tie - we both picked Rock");}
}
}