Created
August 16, 2014 11:36
-
-
Save Fhernd/335cf95882bee411c9a2 to your computer and use it in GitHub Desktop.
Representa la clase Curso.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ===++=== | |
// | |
// OrtizOL | |
// | |
// ===--=== | |
/*============================================================ | |
// | |
// Clase: Curso.cs | |
// | |
// Original en: http://goo.gl/PhL5Ju | |
// | |
// Propósito: Implementar la entidad Curso del modelo. | |
// | |
============================================================*/ | |
using System; | |
using System.Threading.Tasks; | |
namespace NotasCurso.Modelo | |
{ | |
/// <summary> | |
/// Clase que representa un Curso. | |
/// </summary> | |
public class Curso | |
{ | |
#region Campos | |
/// <summary> | |
/// Las notas de cada estudiante como un arreglo de double. | |
/// </summary> | |
private double[] notas; | |
/// <summary> | |
/// Cantidad de estudiantes en el curso. | |
/// </summary> | |
public const int TOTAL_ESTUDIANTES = 12; | |
#endregion | |
#region Constructores | |
/// <summary> | |
/// Crea una instancia de curso. | |
/// </summary> | |
public Curso () | |
{ | |
notas = new double[TOTAL_ESTUDIANTES]; | |
// Asigna un valor por defecto para cada nota: | |
for (int i = 0; i < notas.Length; i++) | |
{ | |
notas[i] = 0.0; | |
} | |
} | |
#endregion | |
#region Métodos | |
/// <summary> | |
/// Cambia la nota de un estudiante. | |
/// </summary> | |
/// <param name="numeroEstudiante">Número (1-12) del estudiante.</param> | |
/// <param name="nota">Nota del estudiante (0.0-5.0).</param> | |
public void CambiarNota(int numeroEstudiante, double nota) | |
{ | |
notas[numeroEstudiante - 1] = nota; | |
} | |
/// <summary> | |
/// Determina la cantidad de estudiantes que mantienen una nota por | |
/// encima del promedio. | |
/// </summary> | |
/// <returns>El número de estudiantes con una nota superior al promedio.</returns> | |
public int CuantosEncimaPromedio() | |
{ | |
// Calcula el promedio de todas las notas: | |
double promedio = CalcularPromedio(); | |
// Calcula el número de notas mayores al promedio: | |
int notasSuperiores = 0; | |
for (int indiceNota = 0; indiceNota < notas.Length; indiceNota++) | |
{ | |
if (notas[indiceNota] > promedio) | |
{ | |
++notasSuperiores; | |
} | |
} | |
return notasSuperiores; | |
} | |
/// <summary> | |
/// Calcula el promedio de todas las notas del curso. | |
/// </summary> | |
/// <returns>Promedio de todas las notas.</returns> | |
public double CalcularPromedio() | |
{ | |
double acumuladorNotas = 0.0; | |
for (int indiceNota = 0; indiceNota < notas.Length; indiceNota++) | |
{ | |
acumuladorNotas += notas[indiceNota]; | |
} | |
return acumuladorNotas / TOTAL_ESTUDIANTES; | |
} | |
/// <summary> | |
/// Obtiene la nota de un determinado estudiante. | |
/// </summary> | |
/// <param name="numeroEstudiante">Número (1-12) del estudiante.</param> | |
/// <returns>Nota del estudiante.</returns> | |
public double ObtenerNota(int numeroEstudiante) | |
{ | |
return notas[numeroEstudiante - 1]; | |
} | |
#endregion | |
#region Puntos de Extensión | |
/// <summary> | |
/// Punto de extensión número 1. | |
/// </summary> | |
/// <returns>Mensaje de respuesta.</returns> | |
public String PuntoExtension1() | |
{ | |
return "Respuesta 1"; | |
} | |
/// <summary> | |
/// Punto de extensión número 2. | |
/// </summary> | |
/// <returns>Mensaje de respuesta.</returns> | |
public String PuntoExtension2() | |
{ | |
return "Respuesta 2"; | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment