Question: DESCRIPTION: This program is a simulation of the Rock/Paper/Scissors game * between 2 players. [User enters moves for BOTH players]. Program plays * the game
DESCRIPTION: This program is a simulation of the Rock/Paper/Scissors game
* between 2 players. [User enters moves for BOTH players]. Program plays
* the game multiple times, based on number of games the user specifies.
* Program also reports who wins (or if it's a draw) as well as reporting
* the total number of wins for player A, wins for player B and draws.
* WINNING RULES: Rock beats Scissors; Scissors beats Paper; Paper beats Rock
* 9 possible combinations of moves for A & B: R R draw
* which is useful for decideWinner method. R P B wins
* R S A wins
* P R A wins
* P P draw
* P S B wins
* S R B wins
* S P A wins
* S S draw
* INPUT: dialog boxes for: number of games, player A move, player B move.
* ECHO input data to console (see output below).
* VALIDITY-CHECKING: None - assume user will enter:
* - a small positive integer for number of games
* - R or P or S or r or p or s when asked for a move
* PROMPTS: Enter number of games to play
* Enter R or P or S for player A move
* Enter R or P or S for player B move
* OUTPUT: console. Use EXACT format shown below. Sample output:
Rock/Paper/Scissors Tournament of 6 Games
Player A Player B Winner
1 Rock Rock >> draw
2 Scissors Paper >> A
3 Paper Rock >> A
4 Rock Paper >> B
5 Paper Scissors >> B
6 Paper Paper >> draw
Player A wins: 2
Player B wins: 2
Draws: 2
*****************************************************************************/
package ex1rockpaperscissors;
import javax.swing.JOptionPane;
public class Ex1RockPaperScissors {
public static void main(String[] args) {
String userData; // for raw input from DialogBox
int numGames; // number of games user wants to play
char aMove; // player A's move for ONE game, from user
char bMove; // player B's move for ONE game, from user
char winner; // stores winner ('A' or 'B' or 'D') once
// that's determined for ONE game
int aWins = 0; // running total
int bWins = 0; // running total
int draws = 0; // running total
userData = JOptionPane.showInputDialog("Enter number of games to play");
numGames = Integer.parseInt(userData);
// WRITE CODE HERE
}
//-------------------------------------------------------------------------
public static void printHeader(int numGames) {
System.out.println("Rock/Paper/Scissors Tournament of " + numGames +
" Games ");
System.out.println(" Player A Player B Winner");
}
//-------------------------------------------------------------------------
// Gets ONE move from user (could be for player A OR for player B)
// - an R or P or S (or r or p or s, which would need "fixing")
// - sends that back to the caller
// public static char getMove(char player) {
// String userData = JOptionPane.showInputDialog
// ("Enter R or P or S for player " + player + " move");
//
// // WRITE REST OF METHOD BODY HERE
//
//
//
// }
//-------------------------------------------------------------------------
public static void printMove(char move) {
switch (move) {
case 'R': System.out.print("Rock "); break;
case 'P': System.out.print("Paper "); break;
case 'S': System.out.print("Scissors "); break;
}
}
//-------------------------------------------------------------------------
// Returns 'A' or 'B' or 'D' (for Draw) based on who won this ONE GAME.
// Parameters are A's move and B's move ('R' or 'P' or 'S') for ONE GAME
// public static char decideWinner(char a, char b) {
// // WRITE METHOD BODY HERE
//
// }
//-------------------------------------------------------------------------
// public static void printTotals( . . .) {
//
// // ADD PARAMETERS AND WRITE METHOD BODY HERE
// }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
