Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PlanillaDeNotas {
- private int[] notas;
- private int notasTotales;
- private int alumnosConNota;
- PlanillaDeNotas(int cantidadDeAlumnos) {
- if (cantidadDeAlumnos <= 0) {
- Error faltaDeAlumnos = new Error(
- "La cantidad de alumnos no es correcta");
- throw faltaDeAlumnos;
- }
- notas = new int[cantidadDeAlumnos];
- for (int i = 0; i < cantidadDeAlumnos; i++) {
- notas[cantidadDeAlumnos - 1] = 0;
- }
- notasTotales = 0;
- }
- public void cargar(int alumno, int nota) {
- if ((alumno > notas.length) && (alumno <= 0) && (nota < 1)
- && (nota > 10)) {
- Error valorInvalido = new Error("El valor ingresado es invalido");
- throw valorInvalido;
- }
- notas[alumno - 1] = nota;
- }
- public int obtenerNota(int alumno) {
- if ((alumno > notas.length) && (alumno <= 0)) {
- Error alumnoInexistente = new Error("El alumno ingresado no existe");
- throw alumnoInexistente;
- }
- if (notas[alumno - 1] == 0) {
- Error alumnoInvalido = new Error(
- "El alumno ingresado no tiene ninguna nota asignada");
- throw alumnoInvalido;
- }
- return notas[alumno - 1];
- }
- public int contarAlumnos() {
- return notas.length;
- }
- public int calcularPromedio() {
- for (int i = 0; i < notas.length; i++) {
- if (notas[i] != 0) {
- notasTotales += notas[i];
- alumnosConNota++;
- }
- }
- int promedio = 0;
- promedio = notasTotales / alumnosConNota;
- return promedio;
- }
- public int calcularNotaMinima() {
- int notaMinima = notas[0];
- for (int i = 0; i < notas.length; i++) {
- if (notaMinima > notas[i]) {
- notaMinima = notas[i];
- }
- }
- return notaMinima;
- }
- public int calcularNotaMaxima() {
- int notaMaxima = notas[0];
- for (int i = 0; i < notas.length; i++) {
- if (notaMaxima < notas[i]) {
- notaMaxima = notas[i];
- }
- }
- return notaMaxima;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement