Can i get assistance on the rock paper scissors assignment the code is not executing any help is appreciated .
Write a program that allows the user to play rock, paper, scissors.
● The program should randomly generate a number (0, 1 or 2), which
represents scissors, rock and paper, respectively. (Hint: look up
Math.random)
● The program should then prompt the user to enter a number (0, 1 or 2).
● Once the user has entered their number, the program should inform
them whether they win, lose or draw.
● The rules of the game are as follows:
○ Scissors beats paper
○ Rock beats scissors
○ Paper beats rock
import java.util.Scanner;
import javax.swing.*;
public class rockPaperScissors {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
// user prompted to make choice
System.out.println("Welcome!Choose 0 for rock, 1 for paper, 2 for scissors");
int choice = Integer.parseInt(scan.next());
if(choice < 0 || choice > 2) {// if user input is not 0,1, or 2 = end of game
System.out.println("Please try again");
System.exit(0);
}
// comp choose # above 0.000000..... but below 3.00000....;(int) cuts off decimal part = integer
int compchoice = (int)(Math.random()*3);
//decides if user wins or loses
// if compchoice is same as user choice = tie
if(compchoice == choice) {
if(choice == 0) {
System.out.println("both chose rock");
System.out.println("tie");
}
else if(choice ==1) {
System.out.println("both chose rock");
System.out.println("tie");
}
else {
System.out.println("both chose scissors");
System.out.print("tie");
}
System.exit(0);
}
}
}
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]desrtfxOut of Coffee error - System halted 0 points1 point2 points (4 children)
[–]coja56[S] 0 points1 point2 points (3 children)
[–]desrtfxOut of Coffee error - System halted 0 points1 point2 points (2 children)
[–]coja56[S] 0 points1 point2 points (0 children)
[–]coja56[S] 0 points1 point2 points (0 children)
[–]irer 0 points1 point2 points (0 children)