Advertisement
julibar

Ej2 - Parte 4

Apr 25th, 2025 (edited)
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. //debajo del constructor, por fuera del mismo.
  2.  
  3. private void calcularCondicion() {
  4.         try {
  5.             double n1 = Double.parseDouble(nota1.getText());
  6.             double n2 = Double.parseDouble(nota2.getText());
  7.             double n3 = Double.parseDouble(nota3.getText());
  8.             String estadoTP = (String) comboTP.getSelectedItem();
  9.            
  10.             // Validar que las notas estén en el rango de 1 a 10
  11.             if (n1 < 1 || n1 > 10 || n2 < 0 || n2 > 10 || n3 < 0 || n3 > 10) {
  12.                 JOptionPane.showMessageDialog(this, "Las notas deben estar entre 1 y 10.", "Error", JOptionPane.ERROR_MESSAGE);
  13.                 return;
  14.             }
  15.  
  16.             double prom = (n1 + n2 + n3) / 3.0;
  17.             String cond;
  18.  
  19.             if (estadoTP.equals("Desaprobado") || n1 < 6 || n2 < 6 || n3 < 6) {
  20.                 cond = "Libre";
  21.             } else if (n1 >= 8 && n2 >= 8 && n3 >= 8) {
  22.                 cond = "Promocionado";
  23.             } else {
  24.                 cond = "Regular";
  25.             }
  26.            
  27.             txtPromedio.setText(String.format("%.2f", prom));
  28.             txtCondicion.setText(cond);
  29.  
  30.         } catch (NumberFormatException ex) {
  31.             JOptionPane.showMessageDialog(this, "Por favor ingresá todas las notas correctamente (números entre 1 y 10)", "Error", JOptionPane.ERROR_MESSAGE);
  32.         }
  33.     }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement