The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 336 Weeks Ago, 4 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Need help adding a line of code that tells the player1 and player2 invalid input if they do not choose the correct choice, here is the code
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
while (true)
{
int Rock = 1, Paper = 2, Scissors = 3;
int player1, player2;
int player1wins = 0;
int player2wins = 0;
int ties = 0;
int count = 0;
System.out.println("First to 5!");
while (count<5)
{
System.out.println("Player 1 Enter Rock = 1, Paper = 2, or Scissors = 3:");
player1 = keyboard.nextInt();
System.out.println("Player 2 Enter Rock = 1, Paper = 2, or Scissors = 3:");
player2 = keyboard.nextInt();
if ((player1 == 1) && (player2 == 1))
{
System.out.println("Tie!");
ties++;
count++;
}
else if ((player1 == 2) && (player2 == 2))
{
System.out.println("Tie!");
ties++;
count++;
}
else if ((player1 == 3) && (player2 == 3))
{
System.out.println("Tie!");
ties++;
count++;
}
else if ((player1 == 1) && (player2 == 3))
{
System.out.println("Player 1 Wins!");
player1wins++;
count++;
}
else if ((player1 == 2) && (player2 == 1))
{
System.out.println("Player 1 Wins!");
player1wins++;
count++;
}
else if ((player1 == 3) && (player2 == 2))
{
System.out.println("Player 1 Wins!");
player1wins++;
count++;
}
else if ((player1 == 1) && (player2 == 2))
{
System.out.println("Player 2 Wins!");
player2wins++;
count++;
}
else if ((player1 == 2) && (player2 == 3))
{
System.out.println("Player 2 Wins!");
player2wins++;
count++;
}
else if ((player1 == 3) && (player2 == 1))
{
System.out.println("Player 2 Wins!");
player2wins++;
count++;
}
}
if(player1wins == 5)
{
System.out.println("Player 1 Total:" + player1wins);
System.out.println("Player 2 Total:" + player2wins);
System.out.println("Player 1 Wins!");
}
else if(player2wins == 5)
{
System.out.println("Player 1 Total:" + player1wins);
System.out.println("Player 2 Total:" + player2wins);
System.out.println("Player 2 Wins!");
}
System.out.println("Play again? "Yes" or "No"");
Scanner YN = new Scanner(System.in);
String YN_String = YN.next();
if(YN_String.equals("Yes") || YN_String.equals("yes"))
{
}
if(YN_String.equals("No") || YN_String.equals("no"))
{
System.out.println ("Goodbye!");
break;
}
}
}
}
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly