lunes, 13 de febrero de 2012

Propuesta 2 Hallar el Area


ESTRUCTURAS DE SECUENCIA

ACTIVIDADES
Se desarrollan algoritmos que involucren estructuras de secuencia.

Propuesto 2.- Diseñe un algoritmo que determine el área lateral, el área total y el área de la
base de un cilindro, sabiendo que:
areabase = π x r2
arealateral = 2 x π x r x h
areatotal = 2 x areabase + arealateral
Siendo r el radio y h la altura.
Soluciòn:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Propuesto2.java
 *
 * Created on 13/02/2012, 10:50:25 AM
 */
package EstructurasDeSecuencia.Propuestos;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;

/**
 *
 * @author Gonzales
 */
public class Propuesto2 extends javax.swing.JFrame implements ActionListener {

    /** Creates new form Propuesto2 */
    public Propuesto2() {
        initComponents();
        btnProcesar.addActionListener(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                Propuesto2 nuevo=new Propuesto2();
                nuevo.setVisible(true);
                nuevo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }
        });
    }
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
    private void initComponents() {

        lblRadio = new javax.swing.JLabel();
        lblAltura = new javax.swing.JLabel();
        txtRadio = new javax.swing.JTextField();
        txtAltura = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtResultados = new javax.swing.JTextArea();
        btnProcesar = new javax.swing.JButton();
        btnLimpiar = new javax.swing.JButton();

        setTitle("PROPUESTO2");
        getContentPane().setLayout(null);

        lblRadio.setText("Radio :");
        getContentPane().add(lblRadio);
        lblRadio.setBounds(40, 20, 40, 20);

        lblAltura.setText("Altura :");
        getContentPane().add(lblAltura);
        lblAltura.setBounds(40, 60, 40, 20);
        getContentPane().add(txtRadio);
        txtRadio.setBounds(100, 20, 70, 20);
        getContentPane().add(txtAltura);
        txtAltura.setBounds(100, 60, 70, 20);

        txtResultados.setColumns(20);
        txtResultados.setRows(5);
        jScrollPane1.setViewportView(txtResultados);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(30, 110, 330, 140);

        btnProcesar.setText("Procesar");
        getContentPane().add(btnProcesar);
        btnProcesar.setBounds(250, 20, 110, 23);

        btnLimpiar.setText("Limpiar");
        getContentPane().add(btnLimpiar);
        btnLimpiar.setBounds(250, 60, 110, 23);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
    }// </editor-fold>                       
    // Variables declaration - do not modify                    
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JButton btnProcesar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblAltura;
    private javax.swing.JLabel lblRadio;
    private javax.swing.JTextField txtAltura;
    private javax.swing.JTextField txtRadio;
    private javax.swing.JTextArea txtResultados;
    // End of variables declaration                  

    public double getRadio() {
        return Double.parseDouble(txtRadio.getText());
    }

    public double getAltura() {
        return Double.parseDouble(txtAltura.getText());
    }

    public double getAreaBase() {
        return 3.14 * getRadio();
    }

    public double getAreaLateral() {

        return (2 * 3.14) * getRadio() * getAltura();
    }

    public double getAreaTotal() {

        return getAreaBase() + getAreaLateral();
    }

    public void resultados() {
        txtResultados.setText("Area de la Base :" + getAreaBase());
        txtResultados.append("\n Area Lateral :" + getAreaLateral());
        txtResultados.append("\nArea Total :" + getAreaTotal());
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == btnProcesar) {
            resultados();
        }
    }
}

Propuesto 1: Hallar Area y Perimetro


ESTRUCTURAS DE SECUENCIA

ACTIVIDADES
Se desarrollan algoritmos que involucren estructuras de secuencia.

Propuesto 1.- Diseñe un algoritmo que determine el área y el perímetro de un rectángulo,
sabiendo que:
area = b x h
perimetro = 2 x (b + h)
Siendo b la base y h la altura.
Soluciòn JAVA = NETBEANS 6.0.9:

 /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Propuesto1.java
 *
 * Created on 13/02/2012, 03:33:45 PM
 */
package EstructurasDeSecuencia.Propuestos;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;

/**
 *
 * @author OMAR
 */
public class Propuesto1 extends javax.swing.JFrame implements ActionListener {

    /** Creates new form Propuesto1 */
    public Propuesto1() {
        initComponents();
        btnProcesar.addActionListener(this);
        btnLimpiar.addActionListener(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                        
    private void initComponents() {

        lblBase = new javax.swing.JLabel();
        lblAltura = new javax.swing.JLabel();
        txtBase = new javax.swing.JTextField();
        txtAltura = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtResultados = new javax.swing.JTextArea();
        btnProcesar = new javax.swing.JButton();
        btnLimpiar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("PROPUESTO 1");
        getContentPane().setLayout(null);

        lblBase.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblBase.setText("Base :");
        getContentPane().add(lblBase);
        lblBase.setBounds(54, 30, 40, 20);

        lblAltura.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblAltura.setText("Altura :");
        getContentPane().add(lblAltura);
        lblAltura.setBounds(54, 70, 40, 20);
        getContentPane().add(txtBase);
        txtBase.setBounds(110, 30, 70, 20);
        getContentPane().add(txtAltura);
        txtAltura.setBounds(110, 70, 70, 20);

        txtResultados.setColumns(20);
        txtResultados.setRows(5);
        jScrollPane1.setViewportView(txtResultados);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(40, 110, 320, 140);

        btnProcesar.setText("Procesar");
        getContentPane().add(btnProcesar);
        btnProcesar.setBounds(250, 20, 90, 23);

        btnLimpiar.setText("Limpiar");
        getContentPane().add(btnLimpiar);
        btnLimpiar.setBounds(250, 70, 90, 23);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-408)/2, (screenSize.height-327)/2, 408, 327);
    }// </editor-fold>                      

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                Propuesto1 nuevo=new Propuesto1();
                nuevo.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                   
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JButton btnProcesar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblAltura;
    private javax.swing.JLabel lblBase;
    private javax.swing.JTextField txtAltura;
    private javax.swing.JTextField txtBase;
    private javax.swing.JTextArea txtResultados;
    // End of variables declaration                 
    //DECLARACION DE VARIABLES

//ENTRADA DE DATOS
    //OBTENER ALTURA
    public double getAltura() {
        return Double.parseDouble(txtAltura.getText());
    }
    //OBTENER BASE
    public double getBase() {
        return Double.parseDouble(txtBase.getText());
    }
    //CALCULAR AREA
    public double getArea() {
        return getBase() * getAltura();
    }
    //CALCULAR PERIMETRO
    public double getPerimetro() {
        return (2 * getAltura()) + (2 * getBase());
    }

//SALIDA DE RESULTADOS
    public void resultados() {
        txtResultados.setText("Area :" + getArea());
        txtResultados.append("\n Perimetro :" + getPerimetro());
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == btnProcesar) {
            resultados();
        }else if(e.getSource()==btnLimpiar){
            limpiar();
        }
    }

    private void limpiar() {
        txtAltura.setText("");
        txtBase.setText("");
        txtResultados.setText("");
    }
  
}