Answer:
import java.util.*;
class Main {
private enum RPS { Rock, Paper, Scissors };
private static RPS[] options = { RPS.Rock, RPS.Paper, RPS.Scissors };
private static String[] names = {"Rock", "Paper", "Scissors"};
// Return 1 if player 1 beats player 2, 0 otherwise
static public int rps( RPS p1, RPS p2 ) {
if (p1 == RPS.Rock && p2 == RPS.Scissors) return 1;
if (p1 == RPS.Scissors && p2 == RPS.Paper) return 1;
if (p1 == RPS.Paper && p2 == RPS.Rock) return 1;
return 0;
}
static public int playRps() {
Random rnd = new Random();
int totalPoints = 0;
for(int round = 0; round < 24; round++) {
int randomNumber = rnd.nextInt(2);
RPS player1 = options[randomNumber];
RPS player2 = options[round%3];
String name1 = names[randomNumber];
String name2 = names[round%3];
int score = rps(player1, player2);
if (player1 == player2) {
System.out.printf("%d. Both players %s. Draw.\\", round+1, name1);
} else if (score == 0) {
System.out.printf("%d. %s does not beat %s, player 1 loses.\\", round+1, name1, name2);
} else {
System.out.printf("%d. %s beats %s, player 1 wins.\\", round+1, name1, name2);
}
totalPoints += score;
}
return totalPoints;
}
public static void main(String[] args) {
System.out.println("Playing RPS.");
int total = playRps();
System.out.printf("Player 1 earned %d points.\\", total);
}
}