JAVA 프로그래밍

문제

A양이 가위바위보를 선택하면 B군이 임의로 가위바위보를 선택하고 지는 가위바위보의 승패를 출력하는 문제입니다 이를 해결하는 프로그램의 다음 실행상태에 대해 빈칸을 채우세요 

프로그램의 실행순서 및 실행상태

1  public static void main( String[] args ) {  

3                                    new RockPaperScissors_Lose();
        player     SCISSORS     ROCK     PAPER     select(), win() ... (obj01)
        RockPaperScissors_Lose(), win()
 
                           main()                                                   
playerA            

L1b  public RockPaperScissors_Lose() {

L11   super();

R1b  public RockPaperScissors() {

R1e  }
        player SCISSORS ROCK PAPER select(), win() ... (obj01)
        RockPaperScissors_Lose(), win()
 
                           main()                                                   
playerA            
()
   this
()
   this

L1e  }

2   RockPaperScissors_Lose playerA = 
                           main()                                                   
playerA

5                                    new RockPaperScissors_Lose();
        player  0  SCISSORS  0  ROCK  1  PAPER  2  select(), win() ... (obj01)
        RockPaperScissors_Lose(), win()
        player     SCISSORS     ROCK     PAPER     select(), win() ... (obj02)
        RockPaperScissors_Lose(), win()
                           main()                                                   
playerA   (obj01)  
playerB            

L1b  public RockPaperScissors_Lose() {

L11   super();

R1b  public RockPaperScissors() {

R1e  }
        player  0  SCISSORS  0  ROCK  1  PAPER  2  select(), win() ... (obj01)
        RockPaperScissors_Lose(), win()
        player SCISSORS ROCK PAPER select(), win() ... (obj02)
        RockPaperScissors_Lose(), win()
                           main()                                                   
playerA   (obj01)  
playerB            
()
   this
()
   this

L1e  }

4   RockPaperScissors_Lose playerB = 
                           main()                                                   
playerA   (obj01)  
playerB

6   playerA.select( scan );

R2b  public void select( Scanner scan ) {

가위, 바위, 보 중 하나를 입력하세요 : 가위

R2e  }
        player SCISSORS  0  ROCK  1  PAPER  2  select(), win() ... (obj01)
        RockPaperScissors_Lose(), win()
        player  0  SCISSORS  0  ROCK  1  PAPER  2  select(), win() ... (obj02)
        RockPaperScissors_Lose(), win()
                           main()                                                   
playerA   (obj01)  
playerB   (obj02)  
  ()
   this
  input

7   playerB.select();

R3b  public void select() {

R3e  }
        player  0  SCISSORS  0  ROCK  1  PAPER  2  select(), win() ... (obj01)
        RockPaperScissors_Lose(), win()
        player SCISSORS  0  ROCK  1  PAPER  2  select(), win() ... (obj02)
        RockPaperScissors_Lose(), win()
                           main()                                                   
playerA   (obj01)  
playerB   (obj02)  
()
   this

8   System.out.println( "A양은 " + 
A양은 

9                                   playerA  

R4b  public String toString() {

R4e  }

가위를 냈습니다.

10                                           + "를 냈습니다." );

11   System.out.println( "B군은 " + 
B군은 

12                                   playerB

R4b  public String toString() {

R4e  }

보를 냈습니다.

13                                           + "를 냈습니다." );

14   if ( playerA.equals( playerB ) )

R5b  public boolean equals( RockPaperScissors counterpart ) {

R5e  }
        player  0  SCISSORS  0  ROCK  1  PAPER  2  select(), win() ... (obj01)
        RockPaperScissors_Lose(), win()
        player  2  SCISSORS  0  ROCK  1  PAPER  2  select(), win() ... (obj02)
        RockPaperScissors_Lose(), win()
                           main()                                                   
playerA   (obj01)  
playerB   (obj02)  
()
       this
counterpart
return

16   else if ( playerA.win( playerB ) )

R6b  public boolean win( RockPaperScissors counterpart ) {

R61   return win( counterpart.toInteger() );

L2b  public boolean win( int counterpart ) {

L22           super.win( counterpart );

R7b  public boolean win( int counterpart ) {

R7e  }
        player  0  SCISSORS  0  ROCK  1  PAPER  2  select(), win() ... (obj01)
        RockPaperScissors_Lose(), win()
        player  2  SCISSORS  0  ROCK  1  PAPER  2  select(), win() ... (obj02)
        RockPaperScissors_Lose(), win()
                           main()                                                   
        playerA   (obj01)  
    playerB   (obj02)  
()
       this
counterpart
     return            
()
       this
counterpart
     return            
()
       this
counterpart
     return

L21   return !

L2e  }

R6e  }

18   else 

19    System.out.println( "B군이 이겼습니다" );
B군이 이겼습니다

20  }


프로그램 코드

	import java.util.Scanner;
	import rpsGame.RockPaperScissors_Lose;
		
	public class RockPaperScissorsGame_Lose 
	{
1		public static void main( String[] args ) { 	
			Scanner scan = new Scanner( System.in );
2			RockPaperScissors_Lose playerA = 
3			                                 new RockPaperScissors_Lose();
4			RockPaperScissors_Lose playerB = 
5			                                 new RockPaperScissors_Lose();
	
6			playerA.select( scan );
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군이 이겼습니다" );
	
			scan.close();
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		}
	}

	package rpsGame;
	
	public class RockPaperScissors_Lose extends RockPaperScissors {
L1b		public RockPaperScissors_Lose() {
L11			super();
L1e		}
	
		@Override
L2b		public boolean win( int counterpart ) {
L21			return !
L22			        super.win( counterpart );
L2e		}
	}