Rock-paper-scissors game java practice

Jankengame.java
import java.util.Scanner;

public class Jankengeme {

	public static void main(String[] args) {

		int playerHand;
	    int cpuHand;
	    Scanner sc = new Scanner(System.in);
	    String rpfHands[] = {"Goo","Choki","Par"};
	    int replay;
	    int replay2=1;

	 try {
	    do{


	    //Player-side processing

	    System.out.println("Please enter a number. 0: Goo, 1: Choki, 2: Par");
	    playerHand = sc.nextInt(); //Input numbers with standard input
	    System.out.println("The hand you put out" + rpfHands[playerHand]); //Hand output of the player

	    //Computer-side processing

	     cpuHand = (int)(Math.random()*3); //Random method to decide what to do with the computer
	     System.out.println("The hand of the computer" + rpfHands[cpuHand]); //Computer manual output

	     //Judgment

	     Result result1 = new Result();
	     result1.result(cpuHand,playerHand);

	     System.out.println("Would you like to try again? 0: Yes 1: No");

	     replay = sc.nextInt();

	  }while(replay!=replay2);

	 		} catch( java.lang.ArrayIndexOutOfBoundsException e) {

	 			System.err.println("error" + e.getMessage());

	 			} finally {

	 					System.out.println("Finish");
	 				}

	 					sc.close();
        }
}
Result.java

public class Result {

	   String result;
	   int rock = 0;
	   int scissors = 1;
	   int paper = 2;

	    public void result(int a, int b){

	        if(a == b){

	            result = "I'm Aiko";

	        }else if((a == rock && b == scissors) || (a == scissors && b == paper ) ||
	        		(a == paper && b == rock )){

	        	result = "Computer wins. You lose";


	        }else if((a == rock && b == paper) || (a == scissors && b == rock ) ||
	        		(a == paper && b == scissors )){

	        	result = "You win. Computer losing";


	    }

	        System.out.println(result);

	}
}

Recommended Posts

Rock-paper-scissors game java practice
Rock-paper-scissors game
java rock-paper-scissors
Rock-paper-scissors game for beginners in Java
Rock-paper-scissors in Java
java practice part 1
Rock-paper-scissors app in Java
Scraping practice using Java ②
I made a rock-paper-scissors game in Java (CLI)
Java8 Stream API practice
Scraping practice using Java ①
[Java] Practice of exception handling [Exception]
[Introduction to rock-paper-scissors games] Java
Java
[Practice! ] Java database linkage (Connector / J 8.0.20)
Age guessing game made in Java
Java
[Java] Compare values / strings (AOJ14 --card game)
Game development with two people using java 2
Game development with two people using java 1
Game development with two people using java 3
Java number guessing game (standard programming problem)
# Java: vol1: [java / JDK version control best practice]