/*
* 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