a java program where the user designates how many games they would like to play (for example user inputs 10 games) then they play the game, if lets say there is a tie after 10 games the game continues until either the user of the computer wins by 2
This is what I have so far
import java.util.Random;
import java.util.Scanner;
public class RockPaperScissors
{
public static void main (String[] args)
{
int Computer=0,Player=0,tie=0,compic,pscore;
String str="y";
Random generate= new Random();
Scanner scan=new Scanner(System.in);
while (str.equals("y"))
{
compic=generate.nextInt(3)+1;
System.out.println ("Enter 1 for Rock, 2 for Paper, and 3 for Scissors");
pscore=scan.nextInt();
if (compic==pscore)
{
System.out.println("Tie No Winner");
tie++;
}
else
{
switch (pscore)
{
case 1:
{
if (compic==2)
{
System.out.println ("Paper beats Rock");
System.out.println ("Computer wins");
Computer++;
}
else
{
System.out.println ("Rock beats Scissors");
System.out.println ("Player wins!");
Player++;
}
break;
}
case 2:
{
if (compic==1)
{
System.out.println ("Paper beats Rock");
System.out.println ("Player wins!");
Player++;
}
else
{
System.out.println ("Scissors beat Paper");
System.out.println ("Computer wins!");
Computer++;
}
break;
}
case 3:
{
if (compic==1)
{
System.out.println ("Rock beats Scissors");
System.out.println ("Computer wins");
Computer++;
}
else
{
System.out.println ("Scissors beat Paper");
System.out.println ("Player wins");
Player++;
}
break;
}
default:
{
System.out.println("Enter 1 2 or 3");
break;
}
}
}
System.out.println ("Ties= "+tie+" Wins= "+Player+" Losses= "+Computer);
Scanner play = new Scanner (System.in);
System.out.println ("Play again? y/n");
str = play.nextLine();
if(!(str.equals("y")))
{
System.out.println ("Scores:");
System.out.println ("Ties= "+tie+" Wins= "+Player+" Losses= "+Computer);
}
else
{
System.out.println ("playing again");
}
}
}
}