• Lenguaje

    Java usando Applet

  • Descripción

    Un postulante a un empleo, realiza un test de capacitación, se obtuvo la siguiente información: cantidad total de preguntas que se le realizaron y la cantidad de preguntas que contestó correctamente. Se pide confeccionar un programa que ingrese los dos datos por teclado e informe el nivel del mismo según el porcentaje de respuestas correctas que ha obtenido, y sabiendo que:
    - Nivel máximo: Porcentaje >= 90%.
    - Nivel medio: Porcentaje >= 75% y < 90%.
    - Nivel regular: Porcentaje >= 50% y < 75%.
    - Fuera de nivel: Porcentaje < 50%.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class TestDeCapacitacion extends Applet implements ActionListener {

    private static final long serialVersionUID = 1L;
    private TextField field_preguntas_correctas, field_total_de_preguntas;
    private Label label_porcentaje;
    private Button button;

    @Override
    public void init() {
        field_preguntas_correctas = new TextField(4);
        field_total_de_preguntas = new TextField(4);
        label_porcentaje = new Label();
        button = new Button("Procesar");
        setLayout(new BorderLayout());
        Panel panel, subpanel;
        panel = new Panel(new BorderLayout());
        subpanel = new Panel(new GridLayout(2, 1));
        subpanel.add(new Label("Ingresa el valor de preguntas correctas:"));
        subpanel.add(new Label("Ingresa el valor de total de preguntas:"));
        panel.add(subpanel, BorderLayout.WEST);
        subpanel = new Panel(new GridLayout(2, 1));
        subpanel.add(field_preguntas_correctas);
        subpanel.add(field_total_de_preguntas);
        panel.add(subpanel);
        add(panel, BorderLayout.NORTH);
        panel = new Panel(new FlowLayout());
        panel.add(button);
        add(panel);
        panel = new Panel(new BorderLayout());
        subpanel = new Panel(new GridLayout(1, 1));
        subpanel.add(new Label("Valor de porcentaje:"));
        panel.add(subpanel, BorderLayout.WEST);
        subpanel = new Panel(new GridLayout(1, 1));
        subpanel.add(label_porcentaje);
        panel.add(subpanel);
        add(panel, BorderLayout.SOUTH);
        button.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent actionEvent) {
        double porcentaje, preguntas_correctas, total_de_preguntas;
        try {
            preguntas_correctas = Double.parseDouble(field_preguntas_correctas.getText());
            total_de_preguntas = Double.parseDouble(field_total_de_preguntas.getText());
        } catch (NumberFormatException numberFormatException) {
            return;
        }
        porcentaje=100.0*preguntas_correctas/total_de_preguntas;
        if(porcentaje>=90)
            javax.swing.JOptionPane.showMessageDialog(this, "Nivel m\u00E1ximo");
        if(porcentaje>=75&&porcentaje<90)
            javax.swing.JOptionPane.showMessageDialog(this, "Nivel medio");
        if(porcentaje>=50&&porcentaje<75)
            javax.swing.JOptionPane.showMessageDialog(this, "Nivel regular");
        if(porcentaje<50)
            javax.swing.JOptionPane.showMessageDialog(this, "Fuera de nivel");
        label_porcentaje.setText(String.valueOf(porcentaje));
    }

}