add Programmyday form github
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user