I have to questions according to instances and input using System.in.
First the instances:
I have created an instance variable, named woodenSword
, with:
Sword woodenSword=new Sword("Wooden Sword", 2);
public Sword(String nameSword, int damageSword){
this.nameSword=nameSword;
this.damageSword=damageSword;
numberOfSwords++;
}
Now, I want to access the damageSword, but how do I do this? I tried woodenSword.damageSword, but apparently that doesn't work... I thought that that was because I made the variables private
, but I don't want to change that, because I read somewhere that it's better to keep variables private
. (And a side question: why is it better to keep variables private?)
And another question: how can I get input with System.in
? Does it have to be done with System.in.toString()
?
Should I use a function for this? To get the private variables from the class, and put that function in the class? I thought about this function:
public static int getSwordStats(String nameSword){
damageSword=nameSword.damageSword;
}
But, I'm getting an error on nameSword.damageSword
, I think it doesn't understand it's a variable... How can I fix this?
Hope you can help me!