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("");
}
}
* 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("");
}
}
Excelente proyectos en java
ResponderEliminarExcelente proyectos Profesionales en java
ResponderEliminar