How do I fix my own output to match the expected output belo

How do I fix my own output to match the expected output below?
import java.util.Scanner;
import java.util.Random;

public class RockPaperScissors {

public static void main(String[] args) {
final int ROCK = 1;
final int PAPER = 2;
final int SCISSORS = 3;
final int MAX_ROUNDS = 5;

Scanner scnr = new Scanner(System.in);
Random rand = new Random(341L);
int round = 0;
String computerMaterial=\"\";
String playerMaterial=\"\";
boolean invalidChoice = true;
int playerChoice=0;
int computerChoice=0;
while (round <= MAX_ROUNDS) {
System.out.println(\"Play! Enter: 1 (rock), 2 (paper), 3 (scissors)\");
playerChoice = scnr.nextInt();
if (playerChoice==1){
playerMaterial = \"Rock\";
System.out.println(\"Your choice is \" + playerMaterial);
}
if (playerChoice==2){
playerMaterial = \"Paper\";
System.out.println(\"Your choice is \" + playerMaterial);
}
if (playerChoice==3){
playerMaterial =\"Scissors\";
System.out.println(\"Your choice is \" + playerMaterial);
}
else if (playerChoice > 4){
invalidChoice = true;
System.out.println(\"Your choice is invalid!\");
round = 0;
}
  
while (round <= MAX_ROUNDS) {
computerChoice = rand.nextInt(3)+1;
if (computerChoice == 1)
playerMaterial = \"Rock\";
if (computerChoice == 2)
playerMaterial = \"Paper\";
if (computerChoice == 3)
playerMaterial = \"Scissors\";
System.out.println(\"Round \" + round + \": computer chose \" + computerMaterial
+ \" and you chose \" + playerMaterial + \"\ \");
if (playerChoice == computerChoice) {
System.out.print(\"Tie!\ \");
}
if (playerChoice == 1 && computerChoice == 2){
System.out.print(\"Computer wins!\ \");
}
if (playerChoice == 1 && computerChoice == 3){
System.out.print(\"You win!\ \");
}
if (playerChoice == 2 && computerChoice == 1){
System.out.print(\"You win!\ \");
}
if (playerChoice == 2 && computerChoice == 3){
System.out.print(\"Computer wins!\ \");
}
if (playerChoice == 3 && computerChoice == 1){
System.out.print(\"Computer wins!\ \");
}
if (playerChoice == 3 && computerChoice ==2){
System.out.print(\"You win!\ \");
}
  
round++;
}
System.out.println(\"Game over!\");
}
}
}


Solution

Everything is fine except the wins++/loss++/tie++ in the if conditions.

They must be done when the two if conditions satisfy, you forgot to include the paranthesis (i\'ve bolded them) and hence the mistake.

It can be solved in a better way though. As you are new to programming this is just fine.

comment if you have any doubts

import java.util.Scanner;
import java.util.Random;

public class RockPaperScissors {
   public static void main(String[] args) {
       String personChoice;
       String computerChoice = \"\";
       int computerInt;
       int win = 0;
       int loss = 0;
       int tie = 0;

       Scanner scan = new Scanner(System.in);
       Random generator = new Random();

       while (true) {

           System.out
                   .println(\"Let\'s Play a Game! Please Enter in Rock, Paper, or Scissors: \");

           System.out.println();

           System.out.println(\"Enter Your Choice. Enter to Exit: \");

           personChoice = scan.next();
           personChoice = personChoice.toUpperCase();

           computerInt = generator.nextInt(3) + 1;

           if (computerInt == 1)
               computerChoice = \"ROCK\";
           else if (computerInt == 2)
               computerChoice = \"PAPER\";
           else if (computerInt == 3)
               computerChoice = \"SCISSORS\";

           if (!personChoice.equals(\"ROCK\") && !personChoice.equals(\"PAPER\")
                   && !personChoice.equals(\"SCISSORS\")) {
               System.out.println();
               System.out.println(\" Wins:\" + win + \" Losses: \" + loss
                       + \" Ties: \" + tie);
               System.out.println();
               System.out
                       .println(\"***********************************************************************************\");
               System.out.println();
               System.exit(0);

           }

           if (personChoice.equals(computerChoice)) {
               System.out.println(\"It\'s a tie! Computer\'s Choice was: \"
                       + computerChoice);
               tie++;
           }

           if (personChoice.equals(\"ROCK\")) {
               if (computerChoice.equals(\"SCISSORS\"))
                   {System.out
                           .println(\"Rock crushes scissors. You win!! Computer\'s Choice Was: \"
                                   + computerChoice);
               win++;}
           }

           if (personChoice.equals(\"ROCK\")) {
               if (computerChoice.equals(\"PAPER\"))
                   {System.out
                           .println(\"Paper covers rock. You lose!! Computer\'s Choice Was: \"
                                   + computerChoice);
               loss++;}

           }

           if (personChoice.equals(\"PAPER\")) {
               if (computerChoice.equals(\"ROCK\"))
                   {System.out
                           .println(\"Paper covers rock. You win!! Computer\'s Choice Was: \"
                                   + computerChoice);
               win++;}
           }

           if (personChoice.equals(\"PAPER\")) {
               if (computerChoice.equals(\"SCISSORS\"))
                   {System.out
                           .println(\"Scissors cuts paper. You win!! Computer\'s Choice Was: \"
                                   + computerChoice);
               win++;}
           }

           if (personChoice.equals(\"SCISSORS\")) {
               if (computerChoice.equals(\"ROCK\"))
                   {System.out
                           .println(\"Rock crushes scissors. You lose!! Computer\'s Choice Was: \"
                                   + computerChoice);
               loss++;}
           }

           if (personChoice.equals(\"SCISSORS\")) {
               if (computerChoice.equals(\"PAPER\"))
                   {System.out
                           .println(\"Paper cuts scissors. You win!! Computer\'s Choice Was: \"
                                   + computerChoice);
               win++;}
           }

           System.out.println();
           System.out
                   .println(\"******************************************************************************\");
           System.out.println();
       }
   }
}

How do I fix my own output to match the expected output below? import java.util.Scanner; import java.util.Random; public class RockPaperScissors { public static
How do I fix my own output to match the expected output below? import java.util.Scanner; import java.util.Random; public class RockPaperScissors { public static
How do I fix my own output to match the expected output below? import java.util.Scanner; import java.util.Random; public class RockPaperScissors { public static
How do I fix my own output to match the expected output below? import java.util.Scanner; import java.util.Random; public class RockPaperScissors { public static

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site