+ 2

Identifier expected error

Started writing something trying to figure out the errors and learning from them https://code.sololearn.com/cD2B294qOb7X/?ref=app

18th Jun 2019, 4:33 AM
udini1
udini1 - avatar
7 Respuestas
+ 2
not entirely sure what you want to do, but this is an example of what i think you might be wanting to do: https://code.sololearn.com/c96nyN2UsFZ4/?ref=app
18th Jun 2019, 5:43 AM
Jake
Jake - avatar
+ 9
First understand the basic of java Becz your programee have a soo many erreors. https://www.sololearn.com/Course/Java/?ref=app tap on the java course and select class and object section and learn how to creat a class
18th Jun 2019, 5:23 AM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 2
the problem in your code is you’re trying to create a Player object with parameters that haven’t been defined. You need to create a constructor for the Player class. Since you’re trying to define (name, attack, defense, health) then you need to create a constructor that accepts (String, int, int, int) and assigns those values to your instance variables. Check out the bottom of my code in the player class where I created the constructor. Well thats one of the issues anyway, you’ve got a few others related to order of operations and handling classes
18th Jun 2019, 6:48 AM
Jake
Jake - avatar
+ 1
Im not good at Java but you must use getter and setter methods. https://www.w3schools.com/java/java_encapsulation.asp
18th Jun 2019, 4:39 AM
Nootnoot
Nootnoot - avatar
0
Jake that's the main idea , yes, but I specifically want to learn the errors in order to fix them myself with time and experience. I guessed that my program couldn't understand what is that Bulbasaur I'm referring to, so I received that error. I'll learn from your code. Thanks.
18th Jun 2019, 6:44 AM
udini1
udini1 - avatar
0
Jake Awesome. If i set up some constructors in a class, such as Player, I'm able to use those constructors ( or more like calling them ) in a different class. As long as I don't make that class protected or private right?
18th Jun 2019, 6:58 AM
udini1
udini1 - avatar
0
Yes, a class constructor will be automatically called any time you create an instance of that class. If it only has a single constructor, and it contains parameters such as (name, attack, defense, health), then you will need to define those values any time you create an instance of the class. https://www.sololearn.com/learn/Java/2157/
18th Jun 2019, 6:26 PM
Jake
Jake - avatar