为什么我无法打印结果?

时间:2016-02-11 07:37:45

标签: java netbeans

我正在尝试打印,但结果总是在我所拥有的3个空格中为0.0,我一直在这里工作,但我找不到原因,我遇到的第一个问题是,我正在创建一个名为perimetro和superficie的新变量,所以我尝试使用我在Figura类中创建的变量,但问题仍然存在

    package pruebas;
    import figuras.*;

    public class Pruebas {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Circulo figura1 = new Circulo(1.0f);

        figura1.calculaPerimetro();
        figura1.calculaSuperficie();

        System.out.println(figura1.toString());

    }    
}

package figuras;
public abstract class Figura {    
    protected String tipo;
    protected static int contador = 0;
    protected int numSerie;
    protected float perimetro;
    protected float superficie;

    public Figura (String tipo) {
    this.tipo = tipo;

    Figura.contador++;
    numSerie = Figura.contador;
    }

    public abstract float calculaPerimetro();
    public abstract float calculaSuperficie();

    public String toSttring() {
    return this.tipo + ", " + numSerie;    
    }

}

package figuras;

public class Circulo extends Figura{

    private float radio;

    public Circulo (float radio) {

    super("Circulo");
    radio = this.radio;

    }

    @Override
    public float calculaPerimetro() {

    perimetro = (float) (2 * Math.PI * radio);
    return perimetro;

    }

    @Override
    public float calculaSuperficie() {

    superficie = (float) (Math.PI * radio * radio);
    return superficie;

    }

    @Override
    public String toString() {
        return super.toSttring() + ", " + radio + ", " + perimetro + ", "+ superficie;
    }

}

1 个答案:

答案 0 :(得分:3)

radio = this.radio;

this.radio = radio;