add Programmyday form github
This commit is contained in:
22
Parkplatz/Auto.cs
Normal file
22
Parkplatz/Auto.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Parkplatz
|
||||
{
|
||||
internal class Auto
|
||||
{
|
||||
private string kennzeichen;
|
||||
|
||||
public Auto(string kennzeichen)
|
||||
{
|
||||
this.kennzeichen = kennzeichen;
|
||||
}
|
||||
public string GetKennzeichen()
|
||||
{
|
||||
return kennzeichen;
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Parkplatz/Parkboxen.cs
Normal file
35
Parkplatz/Parkboxen.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Parkplatz
|
||||
{
|
||||
internal class Parkboxen
|
||||
{
|
||||
private Auto? auto;
|
||||
|
||||
public bool einparken(Auto auto)
|
||||
{
|
||||
if (this.auto == null)
|
||||
{
|
||||
this.auto = auto;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
public Auto ausparken(string kennzeichen)
|
||||
{
|
||||
if (this.auto.GetKennzeichen() == kennzeichen)
|
||||
{
|
||||
Auto h = this.auto;
|
||||
this.auto = null;
|
||||
return h;
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
public bool istleer() { return this.auto == null; }
|
||||
|
||||
}
|
||||
}
|
||||
61
Parkplatz/Parkplatz.cs
Normal file
61
Parkplatz/Parkplatz.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Parkplatz
|
||||
{
|
||||
internal class Parkplatz
|
||||
{
|
||||
private int anzahlParkboxen;
|
||||
private Parkboxen[] parkboxen;
|
||||
public Parkplatz(int anzahlParkboxen)
|
||||
{
|
||||
this.anzahlParkboxen = anzahlParkboxen;
|
||||
this.parkboxen = new Parkboxen[anzahlParkboxen];
|
||||
for (int i = 0; i < parkboxen.Length; i++)
|
||||
{
|
||||
this.parkboxen[i] = new Parkboxen();
|
||||
}
|
||||
}
|
||||
|
||||
public bool parken(Auto auto)
|
||||
{
|
||||
for (int i = 0; i < parkboxen.Length; i++)
|
||||
{
|
||||
if (parkboxen[i].einparken(auto))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public Auto ausparken(string kennzeichen)
|
||||
{
|
||||
for (int i = 0; i < anzahlParkboxen; i++)
|
||||
{
|
||||
Auto a = parkboxen[i].ausparken(kennzeichen);
|
||||
if (a != null)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void status()
|
||||
{
|
||||
Console.WriteLine("Parkplatz-Status: ");
|
||||
for (int i = 0; i < anzahlParkboxen; i++)
|
||||
{
|
||||
if (parkboxen[i].istleer())
|
||||
{
|
||||
Console.Write("[ ]");
|
||||
}
|
||||
else Console.Write("[X]");
|
||||
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Parkplatz/Parkplatz.csproj
Normal file
10
Parkplatz/Parkplatz.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>
|
||||
32
Parkplatz/Program.cs
Normal file
32
Parkplatz/Program.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
namespace Parkplatz
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Parkplatz parkplatz = new Parkplatz(100);
|
||||
|
||||
Auto auto1 = new Auto("ABC-123");
|
||||
Auto auto2 = new Auto("DEF-456");
|
||||
Auto auto3 = new Auto("GHI-789");
|
||||
Auto auto4 = new Auto("IJK-101");
|
||||
Auto auto5 = new Auto("LMN-102");
|
||||
Auto auto6 = new Auto("OPQ-103");
|
||||
Auto auto7 = new Auto("RST-104");
|
||||
Auto auto8 = new Auto("UVW-105");
|
||||
Auto auto9 = new Auto("XYZ-106");
|
||||
|
||||
parkplatz.status();
|
||||
Console.WriteLine();
|
||||
parkplatz.parken(auto1);
|
||||
parkplatz.parken(auto2);
|
||||
parkplatz.parken(auto3);
|
||||
parkplatz.parken(auto4);
|
||||
parkplatz.status();
|
||||
parkplatz.ausparken("DEF-456");
|
||||
parkplatz.status();
|
||||
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user