I need help with my code I have 4 bugs I cant seem to squash

import java.util.Scanner;

class Main {
  public static void main(String[] args) {

    //Get the users input
    Scanner in = new Scanner(System.in);
    System.out.print("Enter your move. Type in rock,paper, or scissors:");
    String myMove = in.nextLine();

    //Verify that myMove is valid
    if(!myMove.equals("rock") && !myMove.equals("paper") && !mymove.equals("scissors"))
      System.out.println("Your move isn't valid"); {
    } else {


      //Randomly generate the opponents move (0, 1, 2)
      int rand = (int)(math.random() * 3);
      String opponentMove = "";
      if(rand == 0) {
        opponentMove = "rock"
      } else if (rand == 1) {
        opponentMove = "paper";
      } else {
        opponentMove = "scissors";
      }
      System.out.println("OpponentMove: " + opponentMove);

      //Calculate if the user won, lost or tied
      if(myMove.equals(opponentMove)) {
        System.out.println("You tied!");
      } else if((myMove.equals("rock") && opponentMove.equals("scissors")) || (myMove.equals("scissors") && opponentMove.equals("paper") ||                               (myMove.equals("paper")) || (myMove.equals("paper") && opponentMove.equals ("rock"))) {
        System.out.println("You won!");
      } else {
        System.out.println("You lost!")
      }
      
    }
    
    

  }
}

is this for homework or not?

2 Likes

No Im just trying to learn Java and went through a tutorial and watched it 3 times but can’t seem to get it right

1 Like

oh I see, I will post the correct code lol

here you go

import java.util.Scanner;

class Main {
  public static void main(String[] args) {

    //Get the users input
    Scanner in = new Scanner(System.in);
    System.out.print("Enter your move. Type in rock,paper, or scissors:");
    String myMove = in.nextLine();

    //Verify that myMove is valid
    if(!myMove.equals("rock") && !myMove.equals("paper") && !myMove.equals("scissors")) {
      System.out.println("Your move isn't valid"); 
    } else {


      //Randomly generate the opponents move (0, 1, 2)
      int rand = (int)(Math.random() * 3);
      String opponentMove = "";
      if(rand == 0) {
        opponentMove = "rock";
      } else if (rand == 1) {
        opponentMove = "paper";
      } else {
        opponentMove = "scissors";
      }
      System.out.println("OpponentMove: " + opponentMove);

      //Calculate if the user won, lost or tied
      if (myMove.equals(opponentMove)) {
        System.out.println("You tied!");
      } else if ((myMove.equals("rock") &&
                  opponentMove.equals("scissors")) ||
                 (myMove.equals("scissors") &&
                  opponentMove.equals("paper")) ||
                  (myMove.equals("paper") && opponentMove.equals ("rock"))) {
        System.out.println("You won!");
      } else {
        System.out.println("You lost!");
      }
    }
  }
}

I’ve cleaned it up and basically added correct parenthesises, correct capitalization, moved some curly brackets, and added some semicolons

2 Likes