main
Sebastian Schüler 2024-07-22 11:20:25 +02:00
parent d296453096
commit 7f5fedfe16
4 changed files with 124 additions and 0 deletions

View File

@ -0,0 +1,45 @@
namespace Exercises_C_Sharp.E42_Interfaces
{
//Sie sehen unten drei verschiedene Klassen aus drei Subsystemen Ihrer Firma. Diese verlangt jetzt von Ihnen, dass alle Namen auf der Konsole ausgegeben werden sollen. Schreiben Sie dafür ein Interface und implementieren Sie dieses bei den Klassen.
//Vergessen Sie nicht, den Typen dynamic auf den Namen Ihres Interfaces zu ändern.
class Exercise_1
{
public static void Start()
{
List<dynamic> NamesList = new(){ new Person("Matteo"), new Customer("Emilia"), new Human("Noah"), new Person("Emma"), new Customer("Finn"), new Human("Hannah"), new Person("Luca"), new Customer("Sophia"), new Human("Leon"), new Person("Mia"), new Customer("Henry"), new Human("Lina"), new Person("Elias"), new Customer("Ella"), new Human("Paul") };
foreach(var element in NamesList)
element.PrintName();
}
}
//Code START
//Code ENDE
class Person{
string _personName;
public Person(string name)
{
_personName = name;
}
}
class Customer{
string _customerName;
public Customer(string name)
{
_customerName = name;
}
}
class Human{
string _humanName;
public Human(string name)
{
_humanName = name;
}
}
}

View File

@ -0,0 +1,40 @@
namespace Exercises_C_Sharp.E42_Interfaces
{
//Sie sollen für einen Sondmixer die Klassen Drums, Guitar und Keyboard erstellen. Alle drei sollen von ISound ableiten. Um die Applikation zu testen, geben Sie bei der implementierten Methoden ein zufälliges Byte-Array zurück. Erstellen Sie dann die drei Objekte der jeweiligen Klassen und übergeben diese der Methode MergeSound().
class Exercise_2
{
public static void Start()
{
//Code START
//Code ENDE
}
public static void MergeSound(List<ISound> sounds)
{
List<byte> byteList = new();
foreach(var element in sounds)
{
byte[] bytes = element.MakeSound();
for(int i = 0; i < bytes.Length; i++)
{
if(byteList.Count <= i)
byteList.Add(bytes[i]);
else
byteList[i] = (byte)(byteList[i] | bytes[i]);
}
}
//ToDo!!!!
}
}
interface ISound{
byte[] MakeSound();
}
//Code START
//Code ENDE
}

View File

@ -0,0 +1,10 @@
namespace Exercises_C_Sharp.E42_Interfaces
{
class Exercise_3
{
public static void Start()
{
//ToDo!!!!
}
}
}

View File

@ -598,6 +598,33 @@ namespace Exercises_C_Sharp
} }
}; };
//************************ //************************
//******* Vererbung ******
//************************
ExerciseGroup vererbungElements = new()
{
Name = "40. Vererbung",
ElementList = new List<ExerciseElement>()
{
new(){Name = "Aufgabe 1", Method = Exercises_C_Sharp.E40_Vererbung.Exercise_1.Start},
new(){Name = "Aufgabe 2", Method = Exercises_C_Sharp.E40_Vererbung.Exercise_2.Start},
new(){Name = "Aufgabe 3", Method = Exercises_C_Sharp.E40_Vererbung.Exercise_3.Start},
new(){Name = "Aufgabe 3", Method = Exercises_C_Sharp.E40_Vererbung.Exercise_4.Start}
}
};
//************************
//******* Interfaces *****
//************************
ExerciseGroup interfaceElements = new()
{
Name = "42. Interfaces",
ElementList = new List<ExerciseElement>()
{
new(){Name = "Aufgabe 1", Method = Exercises_C_Sharp.E42_Interfaces.Exercise_1.Start},
new(){Name = "Aufgabe 2", Method = Exercises_C_Sharp.E42_Interfaces.Exercise_2.Start},
new(){Name = "Aufgabe 3", Method = Exercises_C_Sharp.E42_Interfaces.Exercise_3.Start}
}
};
//************************
//******* Kapselung ****** //******* Kapselung ******
//************************ //************************
ExerciseGroup kapselungElements = new() ExerciseGroup kapselungElements = new()
@ -734,6 +761,8 @@ namespace Exercises_C_Sharp
fileformatsElements, fileformatsElements,
serializeElements, serializeElements,
mysqlElements, mysqlElements,
vererbungElements,
interfaceElements,
kapselungElements, kapselungElements,
patternElements, patternElements,