Advertisement
ItsNoah

arbeit

Mar 23rd, 2023
807
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1. Klassen:
  2.  
  3. =============================================================================================
  4.  
  5. abstract class Certificate (wenn bei Umlet Diagramm Klassenname kursiv geschrieben ist dann ist die Klasse abstract)
  6.  
  7. private DateTime date;
  8. private List<Subject> subjectList;
  9.  
  10. public void addSubject(Subject subject) { subjectList.Add(subject); }
  11.  
  12. public double calculateAverage() {
  13.     double sum = 0;
  14.     foreach(Subject subject in subjectList) {
  15.         sum += subject.getMark();
  16.     }
  17.     if (subjectList.Count == 0) return 0;
  18.     return sum / subjectList.Count;
  19. }
  20.  
  21. public void AusgabeSubjectList() {
  22.     subjectList.ForEach(Console.WriteLine);
  23. }
  24.  
  25. public abstract void printCertificate();
  26.  
  27. =============================================================================================
  28.  
  29. class CollegeCertificate : Certificate
  30.  
  31. public CollegeCertificate() : base(parameter für Constructor von Unterklasse Certificate) {
  32.    
  33. }
  34.  
  35. public void insertData() {
  36.     Console.Write($"Schüler: {pupilName}");
  37.     string eingabe = "";
  38.     do {
  39.         Subject subject = new Subject();
  40.         Console.Write("Name des Faches: ");
  41.         eingabe = Console.ReadLine();
  42.         subject.SetName(eingabe);
  43.  
  44.         Console.Write("Note in diesem Fach: ");
  45.         eingabe = Console.ReadLine();
  46.         subject.SetMark(Convert.ToDouble(eingabe));
  47.  
  48.         Console.Write("Neues Fach hinzufügen? (ja/nein): ");
  49.         eingabe = Console.ReadLine();
  50.     } while(eingabe.Equals("ja"));
  51. }
  52.  
  53. public override void printCertificate() {
  54.     Console.Write(name);
  55.     Console.Write(abschluss);
  56.     Console.Write(name der schule);
  57.     Console.Write(Datum);
  58.     AusgabeSubjectlist();
  59.     Console.Write(CalcAverage());
  60.     Console.Write(remarks);
  61. }
  62.  
  63. =============================================================================================
  64.  
  65. class Subject
  66. private string name;
  67. private double mark;
  68.  
  69. public override string ToString() {
  70.     return $"Fach: {name}   Note: {mark}";
  71. }
  72.  
  73. =============================================================================================
  74.  
  75. Main() {
  76.     CollegeCertificate mycertificate = new CollegeCertificate("Abschlusszeugnis", "GDS blub", "SChülername", ...)
  77.  
  78.     mycertificate.insertData();
  79.  
  80.     Console.Clear();
  81.  
  82.     mycertificate.printCertificate();
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement