lundi 20 juillet 2020

Why does it give me an error even though I declared rand?

import java.util.Random;

class perro{
    private Float animo;
    private Float umbral;
    Random rand = new Random();
    
    public perro(){
        animo = rand.nextFloat() * (5+5)-5;
        umbral = rand.nextFloat() * (0-20);
    }
    
    public Float getAnimo(){
        return animo;
    }
    
    public Float getUmbral(){
        return umbral;
    }
    
    private void psican(persona p){
        this.animo = (rand.nextFloat() -0.5) * 10 + this.animo;
        if (p.tieneGalleta()){
            p.darGalleta();
            this.animo += (1.0 / p.getConfiabilidad()) * (rand.nextInt(2));
        }
    
    System.out.println("Mi nuevo animo es: " + this.animo);
    }

I received this error:

 "error: incompatible types: double cannot be converted to Float
            this.animo = (rand.nextFloat() -0.5) * 10 + this.animo;"

I have checked everything however, everything was stated as a float from the beginning.




Aucun commentaire:

Enregistrer un commentaire