Código de Java - Notas y gráfico

Imágen de perfil

Notas y gráficográfica de visualizaciones


Java

Publicado el 16 de Junio del 2018 por Victor (4 códigos)
1.697 visualizaciones desde el 16 de Junio del 2018
Tenemos las 20 notas de los alumnos de una clase (array generado de forma aleatoria). Ordenamos el array (BubbleSort) y mostramos un gráfico que indica cuántos alumnos han obtenido suspenso, aprobado, notable o execelente.

Versión 1.0

Publicado el 16 de Junio del 2018gráfica de visualizaciones de la versión: Versión 1.0
1.698 visualizaciones desde el 16 de Junio del 2018
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package calificaciones;
 
/**
 *
 * @author victor
 */
public class Calificaciones {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        //Declaramos un array de tipo double de 20 elementos
        double[] arrayNotas = new double [20];
        //Inicializamos los contadores, uno por barra
        int[]barras = new int [4];
        for (int i = 0; i < arrayNotas.length; i++) {
            /*El array se completará con 20 elementos
            tomados aleatoriamente de 0 al 10*/
            arrayNotas[i] = Math.random()*10;
        }
        System.out.print ("[  ");
        for (int i = 0; i < arrayNotas.length; i++) {
            //Método de la clase String
            System.out.print (String.format("%.2f",arrayNotas[i])+"  ");
        }
        System.out.print ("]");
        System.out.println();
        /*Ordenamos secuencia de valores: 
        algorismo de la burbuja o BubbleSort*/
        for (int i = 0; i < arrayNotas.length-1; i++) {
            for (int j = i+1; j < arrayNotas.length; j++) {
                if (arrayNotas[i] > arrayNotas[j]) {
                    double cambio = arrayNotas[i];
                    arrayNotas[i] = arrayNotas[j];
                    arrayNotas[j] = cambio;
                }
            }
        }
        System.out.print ("[  ");
        for (int i = 0; i < arrayNotas.length; i++) {
            System.out.print (String.format("%.2f",arrayNotas[i])+"  ");
        }
        System.out.print ("]");
        System.out.println();
        //Cálculo de los contadores y recorrido por las notas
        for (int i = 0; i < arrayNotas.length; i++) {
            //¿A qué rango pertenece?
            if ((arrayNotas[i] >= 0)&&(arrayNotas[i]< 5)) {
                barras[0]++;
            } else if (arrayNotas[i] < 6.5) {
                barras[1]++;
            } else if (arrayNotas[i] < 9) {
                barras[2]++;
            } else if (arrayNotas[i] <= 10) {
                barras[3]++;
            }
        }
        System.out.println();
        //Se imprime el gráfico
        for (int i = 0; i < barras.length; i++) {
            switch(i) {
                case 0:
                    System.out.print("Suspendido: ");
                    break;
                case 1:
                    System.out.print("Aprovado: ");
                    break;
                case 2:
                    System.out.print("Notable: ");
                    break;
                case 3:
                    System.out.print("Excelente: ");
                    break;
            }
            //Imprimimos tantos asteriscos como el valor del contador
            for (int j = 0; j < barras[i]; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}



Comentarios sobre la versión: Versión 1.0 (0)


No hay comentarios
 

Comentar la versión: Versión 1.0

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s4658