0% found this document useful (0 votes)
26 views3 pages

Ejercicio Clase 1-03-2022 Christian David Muñoz Rodriguez 20201025154

This document defines a Trapezoid class in Java with methods to calculate the area and perimeter of a trapezoid given lengths of the bases and altitude. The class constructor calculates the length of the lateral side. The main method demonstrates getting user input for the trapezoid dimensions, creating an object, and displaying the calculated area and perimeter outputs.

Uploaded by

Christian Muñoz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Ejercicio Clase 1-03-2022 Christian David Muñoz Rodriguez 20201025154

This document defines a Trapezoid class in Java with methods to calculate the area and perimeter of a trapezoid given lengths of the bases and altitude. The class constructor calculates the length of the lateral side. The main method demonstrates getting user input for the trapezoid dimensions, creating an object, and displaying the calculated area and perimeter outputs.

Uploaded by

Christian Muñoz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Trabajo trapecio java

Brayan Nicolas Silva Vanegas 20202025088

public class Trapecio {

    private float baseMayor, baseMenor;

    private float altura, lado;

    public Trapecio(float baseMayor, float baseMenor, float altura) {

        this.baseMayor = baseMayor;

        this.baseMenor = baseMenor;

        this.altura = altura;

        this.calcularLado();

  }

    public Trapecio() {

  }

    private void calcularLado(){

        float cateto = (baseMayor-baseMenor)/2;

        lado = (float)Math.sqrt(cateto*cateto + altura*altura);

  }

    public float getBaseMayor() {

        return baseMayor;

  }
    public float getBaseMenor() {

        return baseMenor;

  }

    public float getAltura() {

        return altura;

  }

    public float getLado() {

        return lado;

  }

  

    public float area(){

        return (baseMayor+baseMenor)/2*altura;

  }

    public float perimetro(){

        return baseMayor+baseMenor+2*lado;

  }

public void print(){

JOptionPane.showMessageDialog(null, "Perímetro: \n"+perimetro());

JOptionPane.showMessageDialog(null, "Área: \n"+area());


}

    public static void main(String[] args) {

        String dato;

        float bMayor, bMenor, altura;

        dato = JOptionPane.showInputDialog("Base mayor:");

        bMayor = Float.parseFloat(dato);

        dato = JOptionPane.showInputDialog("Base menor:");

        bMenor = Float.parseFloat(dato);

        dato = JOptionPane.showInputDialog("altura:");

        altura = Float.parseFloat(dato);

        Trapecio T = new Trapecio(bMayor, bMenor, altura);

        JOptionPane.showMessageDialog(null,"Base mayor: "+T.getBaseMayor()+

                "\nBase menor: "+T.getBaseMenor()+

                "\naltura: "+T.getAltura());

        JOptionPane.showMessageDialog(null,"Área: "+T.area()+

                "\nPerímetro: "+T.perimetro());

  }

  

You might also like