Created
October 13, 2025 08:53
-
-
Save 100xA/5946d8bc21569b52f9a60ccaf4ec65f4 to your computer and use it in GitHub Desktop.
Student Manager
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
| import 'dart:io'; | |
| /// Beschreibung: | |
| /// Du sollst eine kleine Konsolen-App programmieren, mit | |
| /// der man Studenten anlegen, anzeigen und auswerten kann. | |
| /// Das Programm soll: | |
| /// Einen neuen Studenten aufnehmen (Name, Alter, Note) | |
| /// Alle gespeicherten Studenten anzeigen | |
| /// Die Durchschnittsnote berechnen | |
| /// Beendet werden können | |
| class Student { | |
| String name; | |
| int age; | |
| double? grade; | |
| // positional required | |
| Student(this.name, this.age, this.grade); | |
| @override | |
| String toString() => '$name (Alter: $age, Note: $grade)'; | |
| } | |
| void main() { | |
| List<Student> students = []; | |
| while (true) { | |
| print('1. Student hinzufügen'); | |
| print('2. Alle Studenten anzeigen'); | |
| print('3. Durchschnittsnote berechnen'); | |
| print('4. Beenden'); | |
| int? input = int.tryParse(stdin.readLineSync() ?? ""); | |
| switch (input) { | |
| case 1: | |
| createStudent(students); | |
| break; | |
| case 2: | |
| showStudents(students); | |
| break; | |
| case 3: | |
| break; | |
| case 4: | |
| return; | |
| default: | |
| } | |
| } | |
| } | |
| void createStudent(List<Student> students) { | |
| stdout.write("Name: "); | |
| String? name = stdin.readLineSync(); | |
| stdout.write("Alter: "); | |
| String? age = stdin.readLineSync(); | |
| int? ageReal = int.tryParse(age ?? ""); | |
| stdout.write("Note: "); | |
| String? grade = stdin.readLineSync(); | |
| double? gradeReal = double.tryParse(grade ?? ""); | |
| if (name != null && | |
| name.trim().isNotEmpty && | |
| ageReal != null && | |
| gradeReal != null) { | |
| students.add(Student(name, ageReal, gradeReal)); | |
| print("Student hinzugefügt"); | |
| } else { | |
| print("Ungültige Eingabe"); | |
| } | |
| } | |
| void showStudents(List students) { | |
| if (students.isEmpty) { | |
| print("Keine Studenten"); | |
| } else { | |
| students.forEach(print); | |
| } | |
| } | |
| void calcAverage(List<Student> students) { | |
| double sumOfNotes = 0; | |
| for (dynamic s in students) { | |
| sumOfNotes += s.grade!; | |
| } | |
| double average = sumOfNotes / students.length; | |
| print(average); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment