0

Help!

Guys, please check my java code. I don't know how to fix compiler errors.

17th Aug 2020, 3:49 PM
Master Yoda
Master Yoda - avatar
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..
17th Aug 2020, 5:08 PM
JavaBobbo
JavaBobbo - avatar
+ 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)
17th Aug 2020, 5:59 PM
JavaBobbo
JavaBobbo - avatar
0
Please link your code so we dont have to search for it.
17th Aug 2020, 3:51 PM
Dragonxiv
Dragonxiv - avatar
0
Please link it like this. Then we can run it imidietly and search for errors. https://code.sololearn.com/WE8a1Sxiwmw8/?ref=app
17th Aug 2020, 3:56 PM
Dragonxiv
Dragonxiv - avatar
0
https://code.sololearn.com/c6DJm5HSAJIq/?ref=app
17th Aug 2020, 3:58 PM
Master Yoda
Master Yoda - avatar
0
Thanks for the answer, fixed it, but there are still errors with setters and getters
17th Aug 2020, 5:33 PM
Master Yoda
Master Yoda - avatar
0
Thank you, JavaBobbo! Fixed it again, now it works
17th Aug 2020, 6:16 PM
Master Yoda
Master Yoda - avatar
0
You are welcome, glad to hear it works :)
17th Aug 2020, 6:21 PM
JavaBobbo
JavaBobbo - avatar