0
Help!
Guys, please check my java code. I don't know how to fix compiler errors.
8 Réponses
+ 1
What you are trying to do is called Encapsulation in Java, there is no need to inherit from another class by using the extends keyword, you can take a look at my code how it works, maybe it will help you:
https://code.sololearn.com/cpAdKz68c2j5/#java
And in your main, your Scanner class needs to be static if you wanna use it outside the main method:
static Scanner scan = new Scanner(System.in);
or just put it inside the main method..
+ 1
Yes it is because you forgot to create instance variables in your Hero class:
private int hp;
private int atk;
private int mp;
I suggest you creating the objects of Hero class inside the main instead, and also using the methods in there:
Hero Nate = new Hero();
Nate.setHP(50);
To print it out call the get methods because they return the value:
System.out.println("Nate has "+Nate.getHP()+ " hp");
And its better you naming the first objects with lowercase (nate)
0
Please link your code so we dont have to search for it.
0
Please link it like this. Then we can run it imidietly and search for errors.
https://code.sololearn.com/WE8a1Sxiwmw8/?ref=app
0
https://code.sololearn.com/c6DJm5HSAJIq/?ref=app
0
Thanks for the answer, fixed it, but there are still errors with setters and getters
0
Thank you, JavaBobbo! Fixed it again, now it works
0
You are welcome, glad to hear it works :)