In: Computer Science
Application on Android Studio.
"Rock Paper Scissor". The app should ask the user to select "Rock", "Paper" or "Scissor" ; the phone randomly selects a possible choice and then a winner is declared; if it is a tie, the game should continue till a winner emerges.
This is the core code required for your program in Android Studio you need to put three buttons in a layout and set an on-click listener on clicking rock give input to p1 as 1 and 2,3 when you click paper and scissor buttons and it works.
import java.util.*;
class newclass{
final static int rock = 1, scissor = 2, paper = 3;
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("user : Choose (1) - rock, (2) - scissors, or
(3) - paper: ");
int p1 = scan.nextInt();
Random rand=new Random();
int k=rand.nextInt(3);
int p2=k+1;
if (p1 == p2)
{
System.out.print("tie");
} else {
switch (p1){
case rock:
if (p2 == scissor)
System.out.print("user wins");
else
System.out.print("system wins");
break;
case scissor:
if (p2 == paper)
System.out.print("user wins");
else
System.out.print("system wins");
break;
case paper:
if (p2 == rock)
System.out.print("user wins");
else
System.out.print("system wins");
break;
}
}
}
}