Design a Java Rock, Paper, and Scissors Game as follows : It has 3 options: 1. P
ID: 3767324 • Letter: D
Question
Design a Java Rock, Paper, and Scissors Game as follows : It has 3 options: 1. Play one game 2. Play five games 3. Play an infinite number of g ames When the game is finished you need to : 1. Change the winners face from a normal face to a smiley face. 2. Change the loser’s face from normal face to a sad face. Normal Face: Happy Face: Sad Face: You are welcome to use your images. W hen you move your mouse into t he smiley face area, it will p lay a hap py sound. Sad sound will be played when you move your mouse into th e sad face area. When Infinite Games is selected and completed , a text field w ill display how many times you played in total. Other options are flexible. Design it your way.
Explanation / Answer
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TRI;
import java.util.Random;
import java.util.Scanner;
/**
*
* @author anurag
*/
public class game {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws java.lang.Exception {
Scanner Sc = new Scanner(System. in );
Random rand = new Random();
int user_input;
int NUM = 1;
int choice;
//System.out.println("SC IS THE GREATEST");
System.out.println("Pick 1,2, or 3 for:");
System.out.println("1. Play one game 2. Play five games 3. Play an infinite number of games");
choice=Sc.nextInt();
if(choice==1)
NUM=1;
else if(choice==2)
NUM=5;
else
NUM=Integer.MAX_VALUE;
int count=0;
while (NUM!= 0) {
System.out.println("Pick 1,2, or 3 for:");
System.out.println("ROCK (1), PAPER(2), or SCISSOR (3)");
int Rock = 1, Paper = 2, Scissor = 3;
user_input = Sc.nextInt();
int rand_num= rand.nextInt(3 - 1 + 1) + 1;
if (rand_num== Rock) {
if (user_input == Rock) {
System.out.println("Rock Vs. Rock: Tie");
} else if (user_input == Paper) {
System.out.println("Paper Vs. Rock: You Win");
count++;
} else if (user_input == Scissor) {
System.out.println("Scissor Vs. Rock: You Lose");
}
} else if (rand_num== Paper) {
if (user_input == Rock) {
System.out.println("Rock Vs. Paper: You Lose");
} else if (user_input == Paper) {
System.out.println("Paper Vs. Paper: Tie");
} else if (user_input == Scissor) {
System.out.println("Scissor Vs. Paper: You Win");
count++;
}
} else if (rand_num== Scissor) {
if (user_input == Rock) {
System.out.println("Rock Vs. Scissor: You Win");
count++;
} else if (user_input == Paper) {
System.out.println("Paper Vs. Scissor: You Lose");
} else if (user_input == Scissor) {
System.out.println("Scissor Vs. Scissor: Tie");
}
}
NUM--;
}
if(choice==3)
System.out.println("Total number of game played "+count);
}
}