※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

public class Main{
public static void main(String[] args){
	Judge judge = new Judge();
	Player first  = new Player("のしゃん");
	Player second = new Player("ともちゃん");
	int win = 0;
	
	for(int i = 0 ; i < Judge.GAME ; i++){
		System.out.println("\n\n" + (i + 1) + "回目は・・・\n\n\t");
		int w = judge.judge(first.getHand() , second.getHand());
		switch(w){
			case  1: System.out.println(first.getName() + "の勝ちだよ"); break;
			case  0: System.out.println("引き分けだよ"); break;
			case -1: System.out.println(second.getName() + "の勝ちだよ"); break;
		}
		win += w;
	}
	System.out.println("\n\n通算では・・・\n\n");
	if(win > 0) System.out.println(first.getName() + "の勝ちだよ");
	else if(win == 0) System.out.println("引き分けだよ");
	else System.out.println(second.getName() + "の勝ちだよ");
}
}
class Judge{
public static final int STONE = 0;
public static final int SCISSORS = 1;
public static final int PAPER = 2;
public static final int GAME = 3;
private int time;
public int judge(int f , int s){
	if(f == STONE && s == SCISSORS ||
	   f == SCISSORS && s == PAPER ||
	   f == PAPER && s == STONE)
		return 1;
	else if(f == s)
		return 0;
	else 
		return -1;
	
}
}
class Player{
private int hand;
private String name;
private Player(){
	hand = 0;
}
public Player(String name){
	this.name = name;
}
public int getHand(){
	int i = (int)(Math.random() * 3);
	switch(i){
		case Judge.STONE:
			i = Judge.STONE;
			break;
		case Judge.SCISSORS:
			i = Judge.SCISSORS;
			break;
		case Judge.PAPER:
			i = Judge.PAPER;
			break;
	}
	return i;
}
public String getName(){
	return name;
}
}