Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //debajo del constructor, por fuera del mismo.
- private void calcularCondicion() {
- try {
- double n1 = Double.parseDouble(nota1.getText());
- double n2 = Double.parseDouble(nota2.getText());
- double n3 = Double.parseDouble(nota3.getText());
- String estadoTP = (String) comboTP.getSelectedItem();
- // Validar que las notas estén en el rango de 1 a 10
- if (n1 < 1 || n1 > 10 || n2 < 0 || n2 > 10 || n3 < 0 || n3 > 10) {
- JOptionPane.showMessageDialog(this, "Las notas deben estar entre 1 y 10.", "Error", JOptionPane.ERROR_MESSAGE);
- return;
- }
- double prom = (n1 + n2 + n3) / 3.0;
- String cond;
- if (estadoTP.equals("Desaprobado") || n1 < 6 || n2 < 6 || n3 < 6) {
- cond = "Libre";
- } else if (n1 >= 8 && n2 >= 8 && n3 >= 8) {
- cond = "Promocionado";
- } else {
- cond = "Regular";
- }
- txtPromedio.setText(String.format("%.2f", prom));
- txtCondicion.setText(cond);
- } catch (NumberFormatException ex) {
- JOptionPane.showMessageDialog(this, "Por favor ingresá todas las notas correctamente (números entre 1 y 10)", "Error", JOptionPane.ERROR_MESSAGE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement