+ 11

Can someone shed some light on my problem?

I seem to be losing the correct values of my private variables somewhere inside my do...while loop, they keep getting zero'd out. https://code.sololearn.com/c22FNtmaFPkQ/?ref=app

4th May 2017, 4:35 AM
Mark Paramonte
Mark Paramonte - avatar
2 odpowiedzi
+ 2
the prob of your code is you declared these variables before setting up your objects(calling the class choice) int aAtk = a.getAtk(); int aDef = a.getDef(); int aHp = a.getHealth(); String aSp = a.getSpec(); int bAtk = b.getAtk(); int bDef = b.getDef(); int bHp = b.getHealth(); String bSp = b.getSpec() if you put them after giving users value to your fighter objects it would work just fine. by the way nice idea!
4th May 2017, 4:57 AM
Saeed Tafazzol
Saeed Tafazzol - avatar
+ 1
however i suggest you change the objects instead of changing these variables i saw you had a method called get damage you can use this method to actually change your private attributes of your object
4th May 2017, 5:00 AM
Saeed Tafazzol
Saeed Tafazzol - avatar