add Programmyday form github
This commit is contained in:
22
Parkplatz2/Auto.cs
Normal file
22
Parkplatz2/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 Parkplatz2
|
||||
{
|
||||
class Auto
|
||||
{
|
||||
private string kennzeichen;
|
||||
|
||||
public Auto(string kennzeichen)
|
||||
{
|
||||
this.kennzeichen = kennzeichen;
|
||||
}
|
||||
public string GetKennzeichen()
|
||||
{
|
||||
return kennzeichen;
|
||||
}
|
||||
}
|
||||
}
|
||||
49
Parkplatz2/Parkbox.cs
Normal file
49
Parkplatz2/Parkbox.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Parkplatz2
|
||||
{
|
||||
class Parkbox
|
||||
{
|
||||
private int id;
|
||||
private Auto auto;
|
||||
|
||||
public Parkbox(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
public int GetId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
public bool IstLeer()
|
||||
{
|
||||
return auto == null;
|
||||
}
|
||||
public bool Einparken(Auto auto)
|
||||
{
|
||||
if (IstLeer())
|
||||
{
|
||||
this.auto = auto;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public Auto Ausparken(string kennzeichen)
|
||||
{
|
||||
if (!IstLeer())
|
||||
{
|
||||
if (kennzeichen == auto.GetKennzeichen())
|
||||
{
|
||||
Auto help = auto;
|
||||
auto = null;
|
||||
return help;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
76
Parkplatz2/Parkplatz.cs
Normal file
76
Parkplatz2/Parkplatz.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Parkplatz2
|
||||
{
|
||||
internal class Parkplatz
|
||||
{
|
||||
private int id;
|
||||
private Parkbox[] parkboxen;
|
||||
//private Parkschein parkschein;
|
||||
|
||||
public Parkplatz(int id, int anzahl)
|
||||
{
|
||||
this.id = id;
|
||||
this.parkboxen = new Parkbox[anzahl];
|
||||
for (int i = 0; i < this.parkboxen.Length; i++)
|
||||
{
|
||||
this.parkboxen[i] = new Parkbox(i);
|
||||
}
|
||||
}
|
||||
public int GetId()
|
||||
{ return this.id; }
|
||||
public int FreiePlätze()
|
||||
{
|
||||
int anzahl = 0;
|
||||
for (int i = 0; i < this.parkboxen.Length; i++)
|
||||
{
|
||||
if (this.parkboxen[i].IstLeer())
|
||||
{
|
||||
anzahl++;
|
||||
}
|
||||
}
|
||||
return anzahl;
|
||||
}
|
||||
public Parkschein Einparken(Auto auto)
|
||||
{
|
||||
for (int i = 0; i < this.parkboxen.Length; i++)
|
||||
{
|
||||
if (this.parkboxen[i].IstLeer())
|
||||
{
|
||||
if (this.parkboxen[i].Einparken(auto))
|
||||
{
|
||||
Parkschein ps = new Parkschein(this.id, parkboxen[i].GetId(),auto.GetKennzeichen());
|
||||
Console.WriteLine($"Das Auto wurde in {this.parkboxen[i].GetId()} eingeparkt.");
|
||||
return ps;
|
||||
}
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Das Auto konnte nicht eingeparkt werden.");
|
||||
return null;
|
||||
}
|
||||
public Auto Ausparken(Parkschein ps)
|
||||
{
|
||||
if (ps.GetParkplatzId() == this.id)
|
||||
{
|
||||
for (int i = 0; i < this.parkboxen.Length; i++)
|
||||
{
|
||||
if (ps.GetParboxId() == this.parkboxen[i].GetId())
|
||||
{
|
||||
Auto rückgabe = this.parkboxen[i].Ausparken(ps.GetKennzeichen());
|
||||
if (rückgabe != null)
|
||||
{
|
||||
Console.WriteLine($"Das Auto wurde aus PB {this.parkboxen[i].GetId()} ausgeparkt.");
|
||||
return rückgabe;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Auto konnte nicht ausgeparkt werden. Es existiert nicht");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Parkplatz2/Parkplatz2.csproj
Normal file
10
Parkplatz2/Parkplatz2.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>
|
||||
36
Parkplatz2/Parkschein.cs
Normal file
36
Parkplatz2/Parkschein.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Parkplatz2
|
||||
{
|
||||
internal class Parkschein
|
||||
{
|
||||
private int parkboxId;
|
||||
private int parkplatzId;
|
||||
private string kennzeichen;
|
||||
public Parkschein (int parkplatzId, int parkboxId, string kennzeichen)
|
||||
{
|
||||
|
||||
this.parkboxId = parkboxId;
|
||||
this.kennzeichen = kennzeichen;
|
||||
this.parkplatzId = parkplatzId;
|
||||
}
|
||||
|
||||
public string GetKennzeichen()
|
||||
{
|
||||
return this.kennzeichen;
|
||||
}
|
||||
public int GetParkplatzId()
|
||||
{
|
||||
return this.parkplatzId;
|
||||
}
|
||||
public int GetParboxId()
|
||||
{
|
||||
return this.parkboxId;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Parkplatz2/Program.cs
Normal file
32
Parkplatz2/Program.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
|
||||
namespace Parkplatz2
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Auto a1 = new Auto("UN-IT 4666");
|
||||
Auto a2 = new Auto("UN-IT 92");
|
||||
Auto a3 = new Auto("UN-IT 91");
|
||||
Auto a4 = new Auto("UN-IT 7666");
|
||||
Auto a5 = new Auto("UN-IT 6666");
|
||||
Auto a6 = new Auto("UN-IT 5666");
|
||||
|
||||
Parkplatz p1 = new Parkplatz(1, 5);
|
||||
Console.WriteLine("Freie Plätze: " + p1.FreiePlätze());
|
||||
|
||||
Parkschein ps1 = p1.Einparken(a1);
|
||||
Console.WriteLine(ps1.GetParkplatzId());
|
||||
Console.WriteLine(ps1.GetParboxId());
|
||||
Console.WriteLine(ps1.GetKennzeichen());
|
||||
Console.WriteLine();
|
||||
|
||||
a1 = null;
|
||||
|
||||
a1 = p1.Ausparken(ps1);
|
||||
Console.WriteLine(a1.GetKennzeichen());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user