Projektdateien hinzufügen.
This commit is contained in:
10
BeispielAggregation/BeispielAggregation.csproj
Normal file
10
BeispielAggregation/BeispielAggregation.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
44
BeispielAggregation/Class.cs
Normal file
44
BeispielAggregation/Class.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeispielAggregation
|
||||
{
|
||||
internal class Class
|
||||
{
|
||||
private string name;
|
||||
private Student[] students;
|
||||
|
||||
public Class(string name, int cnt)
|
||||
{
|
||||
this.name = name;
|
||||
this.students = new Student[cnt];
|
||||
}
|
||||
public string GetName() { return name; }
|
||||
public void AddStudent(Student student)
|
||||
{
|
||||
for (int i = 0; i < students.Length; i++)
|
||||
{
|
||||
if (students[i] == null)
|
||||
{
|
||||
students[i] = student;
|
||||
student.SetClass(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void PrintInfos()
|
||||
{
|
||||
System.Console.WriteLine($"Stundenten in der Klasse {name}:");
|
||||
foreach (Student student in students)
|
||||
{
|
||||
if (student != null)
|
||||
{
|
||||
Console.WriteLine(student.GetName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
BeispielAggregation/Program.cs
Normal file
17
BeispielAggregation/Program.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace BeispielAggregation
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Student franzi = new Student("Franzi");
|
||||
Student huihui = new Student("Huhui");
|
||||
|
||||
Class do7 = new Class("Do7", 5);
|
||||
|
||||
do7.AddStudent(franzi);
|
||||
do7.AddStudent(huihui);
|
||||
do7.PrintInfos();
|
||||
}
|
||||
}
|
||||
}
|
||||
29
BeispielAggregation/Student.cs
Normal file
29
BeispielAggregation/Student.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeispielAggregation
|
||||
{
|
||||
internal class Student
|
||||
{
|
||||
private string name;
|
||||
private Class _class;
|
||||
|
||||
public Student(string name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
public string GetName() { return this.name; }
|
||||
public void SetClass(Class _class)
|
||||
{
|
||||
this._class = _class;
|
||||
}
|
||||
public void PrintInfo()
|
||||
{
|
||||
Console.WriteLine($"Der Student {name} ist in der klasse {_class.GetName()}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user