• Lenguaje

    Java usando Scanner

  • Descripción

    Las autoridades de una universidad necesitan con urgencia el porcentaje de estudiantes que podrían reprobar el semestre. Existe historial donde indica que un estudiante que ha reprobado el semestre es porque trabaja mínimo 8 horas al día, vive a 2 horas de la universidad y normalmente llega tarde a clases.
    Permita calcular lo siguiente:
    - Ingreso de datos.
    - Calcular la cantidad de estudiantes que reprobaran y cantidad que no reprobaran.
    - Calcular y mostrar el porcentaje de estudiantes que reprobaran.

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
import java.util.Scanner;

public class PorcentajeDeReprobados {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int cantidad_que_aprobaran, cantidad_que_reprobaran, horas_de_la_universidad, horas_de_trabajo, llega_tarde;
        double porcentaje_que_reprobaran;
        String tecla_repetir;
        cantidad_que_aprobaran = 0;
        cantidad_que_reprobaran = 0;
        porcentaje_que_reprobaran = 0;
        do {
            System.out.print("Ingresa el valor de horas de la universidad: ");
            horas_de_la_universidad = in.nextInt();
            in.nextLine();
            System.out.print("Ingresa el valor de horas de trabajo: ");
            horas_de_trabajo = in.nextInt();
            in.nextLine();
            System.out.println("Selecciona el valor de llega tarde.");
            System.out.println("\t1.- Si");
            System.out.println("\t2.- No");
            System.out.print("\t: ");
            do {
                llega_tarde = in.nextInt();
                in.nextLine();
                if (llega_tarde<1||llega_tarde>2)
                    System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
            } while (llega_tarde<1||llega_tarde>2);
            if(horas_de_trabajo>=8&&horas_de_la_universidad>=2&&llega_tarde==1)
                cantidad_que_reprobaran=cantidad_que_reprobaran+1;
            else
                cantidad_que_aprobaran=cantidad_que_aprobaran+1;
            System.out.println();
            do {
                System.out.print("\u00BFDeseas repetir el proceso? (S/N): ");
                tecla_repetir = in.nextLine();
            } while (!tecla_repetir.equalsIgnoreCase("s") && !tecla_repetir.equalsIgnoreCase("n"));
        } while (tecla_repetir.equalsIgnoreCase("s"));
        porcentaje_que_reprobaran=100.0*cantidad_que_reprobaran/(cantidad_que_reprobaran+cantidad_que_aprobaran);
        System.out.println("Valor de cantidad que aprobaran: " + cantidad_que_aprobaran);
        System.out.println("Valor de cantidad que reprobaran: " + cantidad_que_reprobaran);
        System.out.println("Valor de porcentaje que reprobaran: " + porcentaje_que_reprobaran);
    }

}