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();
}
}
}