Juan Argentine Juan Argentine - 28 days ago 22
Java Question

(Java Noob) Having trouble with a double type

I'm doing an exercise and i have to create certain object with some values.
I have a class "Comprador"

public class Comprador extends Persona {

double presupuesto;

public Comprador(String nombre, String apellido, String numeroDocumento, double presupuesto) {
super(nombre, apellido, numeroDocumento);
this.presupuesto = 00;
}

public double getPresupuesto() {
return presupuesto;
}

public void setPresupuesto(double presupuesto) {
this.presupuesto = presupuesto;
}


@Override
public String toString() {
return "nombre=" + nombre + ", apellido=" + apellido + ", numeroDocumento=" + numeroDocumento + "Comprador{" + "presupuesto=" + presupuesto + '}';
}


The idea is to build a "Comprador" object and then inform those values, but when it comes to the double I always get "0.0".

Comprador Monica = new Comprador("Monica","Robes","304", 3532.2);
System.out.println(Monica.toString());


I tried initializing the double, but no results there, i know that it probably is something stupid but i can't figure it out. Thankss

ncw ncw
Answer

It's the line this.presupuesto = 00; in your constructor, which causes your problem.

Replace it with

this.presupuesto = presupuesto;

and you will be fine.

Comments