Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. public class PlanillaDeNotas {
  2.  
  3. private int[] notas;
  4. private int notasTotales;
  5. private int alumnosConNota;
  6.  
  7. PlanillaDeNotas(int cantidadDeAlumnos) {
  8.  
  9. if (cantidadDeAlumnos <= 0) {
  10.  
  11. Error faltaDeAlumnos = new Error(
  12. "La cantidad de alumnos no es correcta");
  13.  
  14. throw faltaDeAlumnos;
  15.  
  16. }
  17.  
  18. notas = new int[cantidadDeAlumnos];
  19.  
  20. for (int i = 0; i < cantidadDeAlumnos; i++) {
  21.  
  22. notas[cantidadDeAlumnos - 1] = 0;
  23.  
  24. }
  25.  
  26. notasTotales = 0;
  27.  
  28. }
  29.  
  30. public void cargar(int alumno, int nota) {
  31.  
  32. if ((alumno > notas.length) && (alumno <= 0) && (nota < 1)
  33. && (nota > 10)) {
  34.  
  35. Error valorInvalido = new Error("El valor ingresado es invalido");
  36.  
  37. throw valorInvalido;
  38.  
  39. }
  40.  
  41. notas[alumno - 1] = nota;
  42.  
  43. }
  44.  
  45. public int obtenerNota(int alumno) {
  46.  
  47. if ((alumno > notas.length) && (alumno <= 0)) {
  48.  
  49. Error alumnoInexistente = new Error("El alumno ingresado no existe");
  50.  
  51. throw alumnoInexistente;
  52.  
  53. }
  54.  
  55. if (notas[alumno - 1] == 0) {
  56.  
  57. Error alumnoInvalido = new Error(
  58. "El alumno ingresado no tiene ninguna nota asignada");
  59.  
  60. throw alumnoInvalido;
  61.  
  62. }
  63.  
  64. return notas[alumno - 1];
  65.  
  66. }
  67.  
  68. public int contarAlumnos() {
  69.  
  70. return notas.length;
  71. }
  72.  
  73. public int calcularPromedio() {
  74.  
  75. for (int i = 0; i < notas.length; i++) {
  76.  
  77. if (notas[i] != 0) {
  78.  
  79. notasTotales += notas[i];
  80. alumnosConNota++;
  81.  
  82. }
  83.  
  84. }
  85.  
  86. int promedio = 0;
  87.  
  88. promedio = notasTotales / alumnosConNota;
  89.  
  90. return promedio;
  91. }
  92.  
  93. public int calcularNotaMinima() {
  94.  
  95. int notaMinima = notas[0];
  96.  
  97. for (int i = 0; i < notas.length; i++) {
  98.  
  99. if (notaMinima > notas[i]) {
  100.  
  101. notaMinima = notas[i];
  102. }
  103.  
  104. }
  105.  
  106. return notaMinima;
  107. }
  108.  
  109. public int calcularNotaMaxima() {
  110.  
  111. int notaMaxima = notas[0];
  112.  
  113. for (int i = 0; i < notas.length; i++) {
  114.  
  115. if (notaMaxima < notas[i]) {
  116.  
  117. notaMaxima = notas[i];
  118. }
  119.  
  120. }
  121.  
  122. return notaMaxima;
  123. }
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement