Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[Java] error:can not find symbol. I don't know what the hell is happening

  1. Jul 14, 2012 #1
    Code (Text):
    import java.util.Scanner;
    import static java.lang.System.out;
    import java.util.Random;

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

    int hitpoints = 100;
    int damage = 40; //un numero cualquiera, solo para hacer una prueba
    Scanner keyboard = new Scanner(System.in);

    out.println("You have encountered a wild wolf!");
    out.println("Would you like to ATTACK or RUN?");

    String wolfSituation = keyboard.next();
    int wolfHP = 60;
    int wolfDMG = 20;  //falta añadir la probabilidad de hit del wolf 


        if (wolfSituation.equals("RUN")){  //al correr, hay que hacer que el jugador queda en la misma casilla pero sin el evento especial
            int randomnessWolfRun = new Random().nextInt(10) + 1;
                if  (randomnessWolfRun <= 5){
                    out.println("You have succesfully escaped from the wild wolf.");
                } else{
                    int remainingHitPoints = hitPoints - wolfDMG;
                    out.println("You have roughly managed to escape, but you have been hurt by the wild wolf.");
                }
       
        }

    }
    }
    on the line
    Code (Text):
    int remainingHitPoints = hitPoints - wolfDMG;
    , this error appears. Actually what I wanted to do was
    Code (Text):
    int hitPoints = hitPoints - wolfDMG;
    because this is a game (just to make the longstory short).


    Any help?
     
  2. jcsd
  3. Jul 15, 2012 #2

    Borek

    User Avatar

    Staff: Mentor

    Re: error:can not find symbol. I don't know what the hell is happening

    I don't know Java, but the obvious guess is that hitpoints and hitPoints are two different variables.
     
  4. Jul 15, 2012 #3

    jtbell

    User Avatar

    Staff: Mentor

    Re: error:can not find symbol. I don't know what the hell is happening

    Looks like a good guess. I don't know Java either, but a Google search for "java case sensitive" returns in the description for the very first hit, "When coding in Java it's important to remember that Java is case sensitive."
     
  5. Jul 15, 2012 #4

    phinds

    User Avatar
    Gold Member
    2016 Award

    Re: error:can not find symbol. I don't know what the hell is happening

    You have not defined the variable remainingHitPoints. Why would you expect the compiler to be able to find it, since it doesn't exist?

    Wait ... I see that I'm probably wrong about that. Stating it as int on the same line where you manipulate it must define it in JAVA. If that's the case, then you would have a problem saying

    int hitPoints = hitPoints - wolfDMG;

    you would need instead to say

    hitPoints = hitPoints - wolfDMG;

    otherwise you would be double-defining hitPoints (since you defined it at the top of your code)
     
  6. Jul 15, 2012 #5

    Mark44

    Staff: Mentor

    Re: error:can not find symbol. I don't know what the hell is happening

    As phinds suggests, you can't define and initialize a variable to its own value. You need to do something like this:

    int hitPoints = 0;
    .
    .
    .
    hitPoints = hitPoints - wolfDMG;

    or

    hitPoints -= wolfDMG;

    Also, as Borek and jtbell point out, hitPoints and hitpoints are different variables.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: [Java] error:can not find symbol. I don't know what the hell is happening
Loading...