A양이 가위바위보를 선택하면 B군이 임의로 가위바위보를 선택하고 지는 가위바위보의 승패를 출력하는 문제입니다 이를 해결하는 다음 프로그램에 대해 빈칸을 채우세요
가위, 바위, 보 중 하나를 입력하세요 : 가위
A양은 가위를 냈습니다.
B군은 보를 냈습니다.
판정결과는 B군이 이겼습니다
가위, 바위, 보 중 하나를 입력하세요 : 바위
A양은 바위를 냈습니다.
B군은 보를 냈습니다.
판정결과는 A양이 이겼습니다
가위, 바위, 보 중 하나를 입력하세요 : 보
A양은 보를 냈습니다.
B군은 가위를 냈습니다.
판정결과는 A양이 이겼습니다
java.util.Scanner;
rpsGame.RockPaperScissors_Lose;
RockPaperScissorsGame_Lose
{
public static void main( String[] args ) {
Scanner scan = Scanner( System.in );
RockPaperScissors_Lose playerA =
RockPaperScissors_Lose();
RockPaperScissors_Lose playerB =
RockPaperScissors_Lose();
playerA.select( scan );
playerB.select();
System.out.println( "A양은 " +
playerA
+ "를 냈습니다." );
System.out.println( "B군은 " +
playerB
+ "를 냈습니다." );
( playerA.( playerB ) )
System.out.println( "A양과 B군이 비겼습니다" );
( playerA.win( playerB ) )
System.out.println( "A양이 이겼습니다" );
System.out.println( "B군이 이겼습니다" );
scan.close();
}
}
rpsGame;
java.util.Scanner;
RockPaperScissors
{
int player;
final int SCISSORS = 0;
final int ROCK = 1;
final int PAPER = 2;
RockPaperScissors() {
.player = SCISSORS;
}
void select( Scanner scan ) {
String input = "";
{
System.out.print( "가위, 바위, 보 중 하나를 입력하세요 : ");
input = scan.next();
} ( !input.( "가위" ) && !input.( "바위" ) && !input.( "보" ) );
scan.close();
( input.( "가위" ) )
.player = SCISSORS;
( input.( "바위" ) )
.player = ROCK;
.player = PAPER;
}
void select() {
.player = (int)( Math.random() * 3 );
}
String () {
( .player SCISSORS )
"가위";
( .player ROCK )
"바위";
"보";
}
int toInteger() {
.player;
}
boolean ( RockPaperScissors counterpart ) {
.player counterpart.toInteger();
}
boolean win( RockPaperScissors counterpart ) {
win( counterpart.toInteger() );
}
boolean win( int counterpart ) {
( ( ( .player SCISSORS ) && ( counterpart PAPER ) )
|| ( ( .player PAPER ) && ( counterpart ROCK ) )
|| ( ( .player ROCK ) && ( counterpart SCISSORS ) ) )
true;
false;
}
}
rpsGame;
RockPaperScissors_Lose RockPaperScissors {
RockPaperScissors_Lose() {
();
}
@Override
boolean win( int counterpart ) {
!
.win( counterpart );
}
}