Created
February 14, 2017 05:07
-
-
Save DanyEscobar/50c037363c1ff0df72057e6e9761ae47 to your computer and use it in GitHub Desktop.
Usando el paradigma de la programación estructurada
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package prueba; | |
| import java.util.Scanner; | |
| import javax.swing.JOptionPane; | |
| public class prueba { | |
| static double b,a, aR, pR;//Variables del Rectangulo | |
| static double r, aC, pC;//Variables del Circulo | |
| static double pi=3.14; | |
| static double bt,at, aT, pT, h;//Variables del Triangulo Rectangulo | |
| static double l, aE, pE, H;///Variables del triangulo equilatero | |
| //RECTANGULO | |
| public static double areaR(double b, double a){ | |
| aR=b*a; | |
| return aR; | |
| } | |
| public static double perimetroR(double b, double a){ | |
| pR= (b*2)+(a*2); | |
| return pR; | |
| } | |
| //CIRCULO | |
| public static double areaC(double r){ | |
| aC= pi*Math.pow(r, 2); | |
| return aC; | |
| } | |
| public static double perimetroC(double r){ | |
| pC= 2*pi*r; | |
| return pC; | |
| } | |
| //TRIANGULO RECTANGULO | |
| public static double areaTR(double bt, double at){ | |
| aT= (bt*at)/2; | |
| h= Math.sqrt( Math.pow(bt, 2)+Math.pow(at, 2)); | |
| return aT; | |
| } | |
| public static double perimetroTR(double bt, double at){ | |
| pT= h+bt+at; | |
| return pT; | |
| } | |
| //TRIANGULO EQUILATERO | |
| public static double areaTE(double l){ | |
| H= (Math.sqrt(3*l))/2; | |
| aE=(l*H)/2; | |
| return aE; | |
| } | |
| public static double perimetroTE(double l){ | |
| pE=3*l; | |
| return pE; | |
| } | |
| public static void main(String[] args) { | |
| String op; | |
| Scanner leer=new Scanner(System.in); | |
| int opciones=0; | |
| while (opciones!=5 && opciones <=5){ | |
| op= JOptionPane.showInputDialog(null,"Calcular Areas y Perimetros \n 1. Rectangulo \n 2. Circulo \n 3. Triangulo Rectangulo \n 4. Triangulo Equilatero \n 5. Exit \n Ingrese La opcion a realizar"); | |
| opciones=Integer.parseInt(op); | |
| switch(opciones){ | |
| case 1: | |
| op= JOptionPane.showInputDialog(null, "Digite la base del rectangulo"); | |
| b=Integer.parseInt(op); | |
| op= JOptionPane.showInputDialog(null,"Digite la altura del rectangulo"); | |
| a=Integer.parseInt(op); | |
| areaR(b, a); | |
| perimetroR(b,a); | |
| JOptionPane.showMessageDialog(null,"Area del rectangulo: " + aR + "\n"+ "Perimetro del rectangulo: " + pR); | |
| break; | |
| case 2: | |
| op= JOptionPane.showInputDialog(null,"Digite el radio del circulo"); | |
| r=Integer.parseInt(op); | |
| areaC(r); | |
| perimetroC(r); | |
| JOptionPane.showMessageDialog(null,"Area del circulo: " + aC + "\n"+ "Perimetro del circulo: " + pC); | |
| break; | |
| case 3: | |
| op= JOptionPane.showInputDialog(null,"Digite la base del triangulo rectangulo"); | |
| bt=Integer.parseInt(op); | |
| op= JOptionPane.showInputDialog(null,"Digite la altura del triangulo rectangulo"); | |
| at=Integer.parseInt(op); | |
| areaTR(bt, at); | |
| perimetroTR(bt, at); | |
| JOptionPane.showMessageDialog(null,"Area del triangulo rectangulo: " + aT + "\n"+ "Perimetro del triangulo rectangulo: " + pT); | |
| break; | |
| case 4: | |
| op= JOptionPane.showInputDialog(null,"Digite el lado del triangulo equilatero"); | |
| l=Integer.parseInt(op); | |
| areaTE(l); | |
| perimetroTE(l); | |
| JOptionPane.showMessageDialog(null, "Area del triangulo equilatero: " + aE + "\n"+ "Perimetro del triangulo equilatero: " + pE); | |
| break; | |
| case 5: | |
| JOptionPane.showMessageDialog(null, "Saliste"); | |
| break; | |
| default: JOptionPane.showMessageDialog(null,"Esta opcion no esxiste"); | |
| } | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment