You are on page 1of 8

Clase Figuras Geometricas

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package figurasgeometricas;

/**
*

* @author Admin

*/

public class FigurasGeometricas {

/**

* @param args the command line arguments

*/

public static void main(String[] args)

Circulo circulo = new Circulo();

circulo.setRadio(44.55);

System.out.println("Area del circulo "+ calcularArea(circulo));

Rectangulo rectangulo = new Rectangulo();

rectangulo.setBase(30);

rectangulo.setAltura(40);

System.out.println("Area del rectangulo "+ calcularArea(rectangulo));

Triangulo triangulo = new Triangulo();

triangulo.setBase(50);

triangulo.setAltura(60);

System.out.println("Area del Triangulo "+ calcularArea(triangulo));

public static double calcularArea(Figura f) {

return f.CalcularArea();

}
Clase Figura
/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package figurasgeometricas;

/**

* @author Admin

*/

public abstract class Figura

double area;

abstract public double CalcularArea();

Clase Circulo
/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package figurasgeometricas;

/**
*

* @author Admin

*/

public class Circulo extends Figura

final double pi=3.1416;

private double radio;

@Override

public double CalcularArea()

return this.area=pi*radio*radio;

public double getRadio()

return radio;

public void setRadio(double radio)

this.radio = radio;

Clase Triangulo
/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.


*/

package figurasgeometricas;

/**

* @author Admin

*/

public class Triangulo extends Figura

private double base;

private double altura;

@Override

public double CalcularArea()

return this.area=(base*altura)/2;

public double getBase()

return base;

public void setBase(double base)

this.base = base;

public double getAltura()


{

return altura;

public void setAltura(double altura)

this.altura = altura;

Clase Rectangulo
/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package figurasgeometricas;

/**

* @author Admin

*/

public class Rectangulo extends Figura

private double base;

private double altura;

@Override
public double CalcularArea()

return this.area=(base*altura);

public double getBase()

return base;

public void setBase(double base)

this.base = base;

public double getAltura()

return altura;

public void setAltura(double altura)

this.altura = altura;

You might also like