0

I cant find the error...

package ex2; import java.util.Random; public class ExpSys { private Random ran; int Level = 1; int Exp_Base = 10; int Exp = 0; int Exp_Max = 0; public ExpSys() { this.ran = new Random(); Exp_Max = (Exp_Base * Level) + (ran.nextInt((Level * 0.05)) + (Level * 0.01)); } public void gainExp() { for (int i = 0; i <= 10; i++) { System.out.println("Nivel : " + Level + "Exp necesaria : " + Exp_Max + "\nExp actual : " + Exp); int expObt = 1 + ran.nextInt((Level * 2)) + 1; Exp += expObt; System.out.println("============\nGanaste: " + expObt + "============"); Level += (Exp <= Exp_Max) ? LevelUp() : 0; } } private int LevelUp() { //grow(); System.out.println("Subiste al nivel: " + Level + 1); Exp_Max = (Exp_Base * Level) + (ran.nextInt((Level * 0.05)) + (Level * 0.01)); return 1; } } I get an error compiling the code on NetBeans...

18th Mar 2018, 5:02 PM
Pablo Horacio Escobar Vega
Pablo Horacio Escobar Vega - avatar
4 Réponses
+ 1
it seems like u r trying to convert a double to int. and by doing that there is a chance of losing accuracies
18th Mar 2018, 6:42 PM
Farshaad Heydari
Farshaad Heydari - avatar
+ 1
Can you be more specific about what kinds of compiling error? However, before that I have spotted an error by reading through your code. ran.nextInt((Level * 0.05)) cannot work as (Level * 0.05) gives float type value while nextInt() only works for integer. Try to change this first and see if the error goes away. Not to forget that you have two lines of that. Hope this helps :)
18th Mar 2018, 6:23 PM
Deddy Tandean
0
What's the error message
18th Mar 2018, 6:08 PM
Tiger Jones
Tiger Jones - avatar