java rock-paper-scissors

I tried to make a rock-paper-scissors program somehow.

janken.java


import java.util.Random;

public class janken {
    //Goo Choki Paa constant definition
    int GU = 0;
    int CHOKI = 1;
    int PA = 2;

    //player;
    int player1;
    int player2;
    //hand
    String te1;
    String te2;

    //Random numbers determine the move of player 1
    public void player1() {
        Random random = new Random();
        int hand1 = random.nextInt(3);
        switch (hand1) {
            case 0:
                player1 = GU;
                te1 = "Goo";
                break;
            case 1:
                player1 = CHOKI;
                te1 = "Choki";
                break;
            case 2:
                player1 = PA;
                te1 = "Par";
                break;
        }
    }
    //Random numbers determine the move of player 2
    public void player2() {
        Random random = new Random();
        int hand2 = random.nextInt(3);
        switch (hand2) {
            case 0:
                player2 = GU;
                te2 = "Goo";
                break;
            case 1:
                player2 = CHOKI;
                te2 = "Choki";
                break;
            case 2:
                player2 = PA;
                te2 = "Par";
                break;
        }
    }

    public static void main(String[] args) {
        janken janken = new janken();
        janken.player1();
        janken.player2();


        System.out.println("Play rock-paper-scissors with player1 and player2.");
        System.out.println("hand of player1: " + janken.te1);
        System.out.println("hand of player2: " + janken.te2);

        //Judgment
        if (janken.player1 == 0 && janken.player2 == 1) {
            System.out.println("Preiya-1 Kachi");
        } else if (janken.player1 == 1 && janken.player2 == 2) {
            System.out.println("Preiya-1 Kachi");
        } else if (janken.player1 == 2 && janken.player2 == 0) {
            System.out.println("Preiya-1 Kachi");
        } else if (janken.player1 == janken.player2) {
            System.out.println("Divide");
        } else {
            System.out.println("Preyya 2 Kachi");
        }
    }
}

Recommended Posts

java rock-paper-scissors
Rock-paper-scissors in Java
Rock-paper-scissors app in Java
Rock-paper-scissors game java practice
Java
Java
[Introduction to rock-paper-scissors games] Java
Java learning (0)
Studying Java ―― 3
Java protected
[Java] Annotation
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
java (override)
Java Day 2018
Java string
Rock-paper-scissors game for beginners in Java
java (array)
Java static
Java serialization
java beginner 4
JAVA paid
Simple rock-paper-scissors
Studying Java ―― 4
Java (set)
java shellsort
[Java] compareTo
Studying Java -5
java (interface)
Java memorandum
☾ Java / Collection
Java array
Studying Java ―― 1
[Java] Array
[Java] Polymorphism
Studying Java # 0
java framework
Java features
[Java] Inheritance
FastScanner Java
Java features
java beginner 3
Java memo
java (encapsulation)
Java inheritance
Java basics
Decompile Java
[Java] Annotation
java notes
java beginner
Java (add2)
JAVA (Map)
[java] interface