Vous êtes sur la page 1sur 5

Ejercicio Tornillos:

Disee un programa en java para obtener el grado de eficiencia de un operario de una fabrica de tornillos, de acuerdo a las siguientes condiciones, que se le imponen para un periodo de prueba: -Menos de 200 tornillos defectuosos -Mas de 10000 tornillos producidos El grado de eficiencia se determina de la siguiente manera: -Si no cumple ninguna de las condiciones, grado 5. -Si solo cumple la primera condicin, grado 6. -Si solo cumple la segunda condicin, grado 7. -Si cumple las dos condiciones , grado 8.

SENTENCIA DE JAVA import javax.swing.JOptionPane; public class programa06 extends javax.swing.JFrame {

/** Creates new form programa06 */ public programa06() { initComponents(); }

/** 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() {

jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); txtProducidos = new javax.swing.JTextField(); txtDefectuosos = new javax.swing.JTextField(); btnEvaluar = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); txtSalida = new javax.swing.JTextArea();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N jLabel1.setText("Ingrese Tornillos Producidos:"); getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 90, -1, -1));

jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel2.setForeground(new java.awt.Color(255, 51, 51)); jLabel2.setText("EVALUACION DE PERSONAL");

getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 20, 210, 20));

jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N jLabel3.setText("Ingrese Tornillos Defectuosos:"); getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 130, 1, -1)); getContentPane().add(txtProducidos, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 90, 100, -1)); getContentPane().add(txtDefectuosos, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 130, 100, -1));

btnEvaluar.setText("Evaluar"); btnEvaluar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnEvaluarActionPerformed(evt); } }); getContentPane().add(btnEvaluar, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 180, -1, -1));

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

getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 220, 400, 120));

pack(); }// </editor-fold>

private void btnEvaluarActionPerformed(java.awt.event.ActionEvent evt) { if (this.txtProducidos.getText().length()==0){ JOptionPane.showMessageDialog(this,"ingrese Tornillos\n Producidos","Tornillos Producidos",1); this.txtProducidos.requestFocus(); } else if (this.txtDefectuosos.getText().length()==0){ JOptionPane.showMessageDialog(this,"ingrese Tornillos\n Defectuosos","Tornillos Defectuosos",1); this.txtDefectuosos.requestFocus(); } else {

// declaracion de variables locales int producidos,defectuosos; String resultado=""; //captura de datos producidos=Integer.parseInt(this.txtProducidos.getText()); defectuosos=Integer.parseInt(this.txtDefectuosos.getText()); //proceso if(defectuosos>=200&&producidos<=10000) resultado="Grado 5";

else if (defectuosos<200&&producidos<=10000) resultado="Grado 6"; else if (defectuosos>=200&&producidos>10000) resultado="Grado 7"; else if (defectuosos<200&&producidos>10000) resultado="Grado 8"; //Salida this.txtSalida.setText("RESULTADO DE LA EVALUACION \n"); this.txtSalida.append("La evaluacion es de: "+resultado); } }

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

Vous aimerez peut-être aussi