RE: rock scissors paper 11-04-2013, 01:18 AM
#9
i fixed this thx for the suggestion appreciate it 
@ArkPhaze as i understood you want me to change scissors rock paper to 0,1,2 and use 0,1,2 while comparing ?

Spoiler:
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package rockpaperscissors;
import java.util.Scanner;
public class RockPaperScissors {
public static String playerChoice() {
Scanner in = new Scanner(System.in);
System.out.println("Player choice : ");
String choicePlayer;
choicePlayer = in.nextLine();
return choicePlayer;
}
public static String pcChoice() {
int random = 1 + (int) (Math.random() * 3);
String choicePc;
if (random == 1) {
choicePc = "rock";
} else if (random == 2) {
choicePc = "paper";
} else {
choicePc = "scissors";
}
return choicePc;
}
public static void chooseWinner(String choice1, String choice2) {
if (choice1.equals(choice2)) {
System.out.println("its a tie !");
}
//if player chose rock
if (choice1.equals("rock") && (choice2.equals("scissors"))) {
System.out.println("player won");
}
if (choice1.equals("rock") && (choice2.equals("paper"))) {
System.out.println("pc won");
}
//if player chose scissors
if (choice1.equals("scissors") && (choice2.equals("paper"))) {
System.out.println("player win");
}
if (choice1.equals("scissors") && (choice2.equals("rock"))) {
System.out.println("pc won");
}
//if player chose paper
if (choice1.equals("paper") && (choice2.equals("rock"))) {
System.out.println("player win");
}
if (choice1.equals("paper") && (choice2.equals("scissors"))) {
System.out.println("pc won");
}
}
public static void main(String[] args) {
String playAgain;
Scanner in = new Scanner(System.in);
do {
// player choice
String choice = playerChoice();
while ((!choice.equalsIgnoreCase("rock")) && (!choice.equalsIgnoreCase("paper")) && (!choice.equalsIgnoreCase("scissors"))) {
System.out.println("choose rock paper or scissors");
choice = in.nextLine();
}
System.out.println("you're choice is " + choice);
//pc choice
String pcChoice = pcChoice();
System.out.println("pc choosed " + pcChoice);
//choosing the winner
chooseWinner(choice, pcChoice);
do {
System.out.println("Do you wanna play again y/n ?");
playAgain = in.nextLine();
} while (!playAgain.equals("y") && (!playAgain.equals("n")));
} while (playAgain.equalsIgnoreCase("y"));
if (playAgain.equals("n")) {
System.out.println("thx for playing");
}
}
}@ArkPhaze as i understood you want me to change scissors rock paper to 0,1,2 and use 0,1,2 while comparing ?
(This post was last modified: 11-04-2013, 01:21 AM by LordPankake.)




![[+]](https://sinister.li/images/modern/collapse_collapsed.png)