Juan Argentine Juan Argentine - 1 year ago 87
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;

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);

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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download