This commit is contained in:
2025-04-17 17:40:16 +02:00
parent c666da8ba7
commit bbc4894921
16 changed files with 370 additions and 0 deletions

15
Ubung/Auto.cs Normal file
View File

@@ -0,0 +1,15 @@
namespace Ubung;
internal abstract class Auto
{
protected Auto(int countDors)
{
this.CountDors = countDors;
}
public int CountDors { get; protected set; }
public string Color { get; set; } = "";
public string Type { get; set; } = "";
}

26
Ubung/GenTec.cs Normal file
View File

@@ -0,0 +1,26 @@
namespace Ubung;
internal class GenTec<T>
{
private T[] values;
public GenTec(int groesse)
{
values = new T[groesse];
}
public T GetValue(int index)
{
return values[index];
}
public void SetValue(int index, T value)
{
values[index] = value;
}
public string GetType()
{
return typeof(T).Name;
}
}

21
Ubung/GenTecList.cs Normal file
View File

@@ -0,0 +1,21 @@
namespace Ubung;
internal class GenTecList<T>
{
List<T> list = new List<T>();
public T GetValue(int index)
{
return list[index];
}
public void AddValue(T value)
{
list.Add(value);
}
public string GetType()
{
return typeof(T).Name;
}
}

8
Ubung/Kombi.cs Normal file
View File

@@ -0,0 +1,8 @@
namespace Ubung;
internal class Kombi : Auto
{
public Kombi() : base(5)
{
}
}

8
Ubung/Limousine.cs Normal file
View File

@@ -0,0 +1,8 @@
namespace Ubung;
internal class Limousine : Auto
{
public Limousine(int countDors) : base(countDors)
{
}
}

73
Ubung/Program.cs Normal file
View File

@@ -0,0 +1,73 @@

using Ubung;
// Übung 1
Limousine limousine = new(4);
Kombi kombi = new();
Van van = new();
// Übung 3
var gentec = new GenTec<int>(5);
gentec.SetValue(3, 245);
gentec.SetValue(2, 45);
gentec.SetValue(1, 11);
gentec.SetValue(4, 34);
gentec.SetValue(0, 56);
Console.WriteLine(gentec.GetType());
Console.WriteLine(gentec.GetValue(4));
var gen = new GenTec<double>(5);
gen.SetValue(3, 245);
gen.SetValue(2, 45);
gen.SetValue(1, 11);
gen.SetValue(4, 34.9123);
gen.SetValue(0, 56);
Console.WriteLine(gen.GetType());
Console.WriteLine(gen.GetValue(4));
var genList = new GenTecList<int>();
genList.AddValue(245);
genList.AddValue(3);
genList.AddValue(25);
genList.AddValue(24);
Console.WriteLine(genList.GetType());
Console.WriteLine(genList.GetValue(0));
var genList2 = new GenTecList<int>();
genList2.AddValue(245);
genList2.AddValue(3);
genList2.AddValue(25);
genList2.AddValue(24);
Console.WriteLine(genList2.GetType());
Console.WriteLine(genList2.GetValue(1));
// Übung 4
var rand = new Random();
List<int> list = new();
for (int i = 0; i < 100; i++)
{
list.Add(rand.Next(101));
}
var anzahl = list.Count(o => o < list.Average());
Console.WriteLine(anzahl);
var rooms = new Dictionary<string, string[]>
{
{ "618", new [] { "Tim", "Ute"} },
{ "621", new [] { "Hans", "Jakob"} },
};
Console.WriteLine(SearchStudent(rooms, "Jakob"));
string SearchStudent(Dictionary<string, string[]> studentInClasses, string student)
{
return studentInClasses.First(o => o.Value.Contains(student)).Key;
}

10
Ubung/Ubung.csproj Normal file
View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

17
Ubung/Van.cs Normal file
View File

@@ -0,0 +1,17 @@
namespace Ubung;
internal class Van : Kombi
{
private bool ladefläche = false;
public bool Ladefläche
{
get => ladefläche;
set
{
base.CountDors = value ? 2 : 5;
ladefläche = value;
}
}
}