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
R62			       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		}
	}








 
실행 순서