112 lines
2.9 KiB
Java
112 lines
2.9 KiB
Java
package QualifierTeil2;
|
|
import java.util.*;
|
|
|
|
public class Parkhaus {
|
|
private List<PKW> parkendePkws;
|
|
int kapazitaet;
|
|
int belegt;
|
|
|
|
public Parkhaus() {
|
|
this.parkendePkws = new ArrayList<>();
|
|
this.kapazitaet = randomAnzahlParkplätze();
|
|
this.belegt = 0;
|
|
}
|
|
|
|
public List<PKW> getParkendePkws() {
|
|
return parkendePkws;
|
|
}
|
|
|
|
public static int randomAnzahlParkplätze(){
|
|
return (int) (Math.random() * 200) + 1;
|
|
}
|
|
|
|
public void einfahren(PKW pkw) {
|
|
if (parkendePkws.size() < kapazitaet) {
|
|
parkendePkws.add(pkw);
|
|
this.kapazitaet--;
|
|
this.belegt++;
|
|
} else {
|
|
System.out.println("Parkhaus voll.");
|
|
|
|
}
|
|
}
|
|
|
|
// Methode zum Anzeigen der verfügbaren Plätze
|
|
public void zeigeVerfügbarePlätze() {
|
|
System.out.println("Verfügbare Plätze: " + (kapazitaet - parkendePkws.size()));
|
|
}
|
|
|
|
// Methode zum Prüfen, ob das Parkhaus voll ist
|
|
public boolean istVoll() {
|
|
return parkendePkws.size() >= kapazitaet;
|
|
}
|
|
|
|
|
|
public long berechneParkdauer(String kennzeichen, Date ausfahrt) {
|
|
long minDiff = 0;
|
|
|
|
for (PKW pkw : parkendePkws) {
|
|
if (pkw.getKennzeichen().equals(kennzeichen) && !pkw.hatBezahlt()) {
|
|
minDiff = (ausfahrt.getTime() - pkw.einfahrt.getTime()) / 60000;
|
|
}
|
|
}
|
|
return minDiff;
|
|
|
|
//Debugging mit selbst ausgewählten Zeiten
|
|
/*var sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm");
|
|
|
|
Date d1 = null;
|
|
try {
|
|
d1 = sdf.parse("01.10.2024, 9:45");
|
|
} catch (ParseException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
Date d2 = null;
|
|
try {
|
|
d2 = sdf.parse("02.10.2024, 9:45");
|
|
} catch (ParseException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
|
|
long minDiff = (d2.getTime() - d1.getTime()) / 60000;
|
|
|
|
return minDiff;*/
|
|
}
|
|
|
|
public long berechneGebuehren(String kennzeichen, Date ausfahrt){
|
|
long parkdauer = berechneParkdauer(kennzeichen, ausfahrt);;
|
|
long gebuehr = 0;
|
|
|
|
// Falls die Parkdauer 15 Minuten oder weniger beträgt, ist das Parken kostenlos
|
|
if (parkdauer <= 15) {
|
|
gebuehr = 0;
|
|
parkdauer = 0;
|
|
}
|
|
|
|
if (parkdauer == 1440){
|
|
gebuehr = 1500;
|
|
parkdauer = 0;
|
|
}
|
|
|
|
if (parkdauer > 0 && parkdauer < 1440 ){
|
|
while(parkdauer > 0){
|
|
gebuehr += 100;
|
|
parkdauer-=60;
|
|
}
|
|
}
|
|
|
|
// Prüfe, ob es sich um ein E-Auto handelt (Kennzeichen endet mit "E")
|
|
if (kennzeichen.endsWith("E")) {
|
|
gebuehr *= 0.8; // 20% Rabatt für E-Autos
|
|
}
|
|
|
|
return gebuehr;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|