Created with <3 with dartpad.dev.
Created
October 31, 2023 02:46
-
-
Save leonus96/9c99e81cf455e930385908692e5f1794 to your computer and use it in GitHub Desktop.
6. Promedio-estudiantes
This file contains hidden or 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
/// Ejercicio 5: Clase de Estudiantes | |
/// Crea una clase llamada Estudiante | |
/// con propiedades como nombre, edad y calificaciones. | |
/// Luego, crea una función que calcule el | |
/// promedio de calificaciones de un grupo de estudiantes. | |
class Estudiante { | |
String nombre; | |
int edad; | |
int calificacion; | |
Estudiante({ | |
required this.nombre, | |
required this.edad, | |
required this.calificacion, | |
}); | |
} | |
void main() { | |
final List<Estudiante> estudiantes = [ | |
Estudiante( | |
nombre: 'Alexander', | |
edad: 22, | |
calificacion: 12, | |
), | |
Estudiante( | |
nombre: 'Rosa', | |
edad: 22, | |
calificacion: 15, | |
), | |
Estudiante( | |
nombre: 'Katerin', | |
edad: 32, | |
calificacion: 18, | |
), | |
Estudiante( | |
nombre: 'Luis', | |
edad: 25, | |
calificacion: 12, | |
), | |
Estudiante( | |
nombre: 'Claudia', | |
edad: 24, | |
calificacion: 14, | |
), | |
]; | |
int sumaCalificaciones = 0; | |
for (Estudiante estudiante in estudiantes) { | |
sumaCalificaciones = sumaCalificaciones + estudiante.calificacion; | |
} | |
print('El promedio de las calificaciones es: ${sumaCalificaciones/estudiantes.length}'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment