JAVA 프로그래밍

문제

A양이 가위바위보를 선택하면 B군이 임의로 가위바위보를 선택하고 가위바위보의 승패를 출력하는 문제입니다 실행순서를 클릭하세요 
가위, 바위, 보 중 하나를 입력하세요 : 가위
A양은 가위를 냈습니다.
B군은 보를 냈습니다.
판정결과는 A양이 이겼습니다 

프로그램 코드

	import java.util.Scanner;
	import rpsGame.RockPaperScissors;
		
	public class RockPaperScissorsGame
	{
1		public static void main( String[] args ) {
2			RockPaperScissors playerA =
3			                            new RockPaperScissors();
4			RockPaperScissors playerB =
5			                            new RockPaperScissors();

6			playerA.select( new Scanner( System.in ) );
7			playerB.select();
8			System.out.println( "A양은 " +
9			                                playerA
10			                                        + "를 냈습니다." );
11			System.out.println( "B군은 " +
12			                                playerB
13			                                        + "를 냈습니다." );
		
14			if ( playerA.equals( playerB ) )
15				System.out.println( "A양과 B군이 비겼습니다" );
16			else if ( playerA.win( playerB ) )
17				System.out.println( "A양이 이겼습니다" );
18			else
19				System.out.println( "B군이 이겼습니다" );

20		}
	}

	package rpsGame;
	import java.util.Scanner;

	public class RockPaperScissors
	{
		private int player;
		private final int SCISSORS = 0;
		private final int ROCK = 1;
		private final int PAPER = 2;

R1b		public RockPaperScissors() {
			this.player = SCISSORS;
R1e		}

R2b		public void select( Scanner scan ) {
			String input = "";
			do {
				System.out.print( "가위, 바위, 보 중 하나를 입력하세요 : ");
				input = scan.next();
			} while( !input.equals( "가위" ) && !input.equals( "바위" ) && !input.equals( "보" ) );
			scan.close();
			
			if ( input.equals( "가위" ) )
				this.player = SCISSORS;
			else if ( input.equals( "바위" ) )
				this.player = ROCK;
			else
				this.player = PAPER;
R2e		}

R3b		public void select() {
			this.player = (int)( Math.random() * 3 );
R3e		}
		
R4b		public String toString() {
			if ( this.player == SCISSORS )
				return "가위";
			else if ( this.player == ROCK )
				return "바위";
			else
				return "보";
R4e		}
		
		public int toInteger() {
			return this.player;
		}
		
R5b		public boolean equals( RockPaperScissors counterpart ) {
			return this.player == counterpart.toInteger();
R5e		}
		
R6b		public boolean win( RockPaperScissors counterpart ) {
R61			return win( counterpart.toInteger() );
R6e		}

R7b		public boolean win( int counterpart ) {
			if ( ( ( this.player == SCISSORS ) && ( counterpart == PAPER ) )
					|| ( ( this.player == PAPER ) && ( counterpart == ROCK ) )
					|| ( ( this.player == ROCK ) && ( counterpart == SCISSORS ) ) )
				return true;
			else
				return false;
R7e		}
	}








 
실행 순서