Chat-GPT-Code
commit
814e5a510a
|
@ -0,0 +1,38 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
|
@ -0,0 +1,7 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
|
@ -0,0 +1,5 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="18" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>Qualifire</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>18</maven.compiler.source>
|
||||
<maven.compiler.target>18</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,194 @@
|
|||
package org.example;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
private static final int MAX_PLAETZE = 180;
|
||||
private static final double STUNDENGEBUEHR = 1.0;
|
||||
private static final double MAX_GEBUEHR_NACHTS = 5.0;
|
||||
private static final double TAGESGEBUEHR_MAX = 15.0;
|
||||
private static final double RABATT_E_AUTO = 0.2;
|
||||
|
||||
private static final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm");
|
||||
private static final Scanner scanner = new Scanner(System.in);
|
||||
|
||||
private static List<PKW> parkendeAutos = new ArrayList<>();
|
||||
private static List<PKW> schuldenListe = new ArrayList<>();
|
||||
|
||||
public static void main(String[] args) throws ParseException {
|
||||
while (true) {
|
||||
System.out.println("Parkhaus System");
|
||||
System.out.println("1. Auto einfahren");
|
||||
System.out.println("2. Parkgebühren berechnen und bezahlen");
|
||||
System.out.println("3. Auto ausfahren");
|
||||
System.out.println("4. Beenden");
|
||||
System.out.print("Wählen Sie eine Option: ");
|
||||
int option = Integer.parseInt(scanner.nextLine());
|
||||
|
||||
switch (option) {
|
||||
case 1 -> einfahren();
|
||||
case 2 -> bezahlen();
|
||||
case 3 -> ausfahren();
|
||||
case 4 -> {
|
||||
System.out.println("Programm beendet.");
|
||||
return;
|
||||
}
|
||||
default -> System.out.println("Ungültige Option.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void einfahren() throws ParseException {
|
||||
if (parkendeAutos.size() >= MAX_PLAETZE) {
|
||||
System.out.println("Parkhaus ist voll.");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.print("Kennzeichen (leer für zufälliges Kennzeichen): ");
|
||||
String kennzeichen = scanner.nextLine();
|
||||
if (kennzeichen.isEmpty()) {
|
||||
kennzeichen = generiereZufallsKennzeichen();
|
||||
}
|
||||
|
||||
System.out.print("Zeitstempel (dd.MM.yyyy, HH:mm) (leer für aktuelle Zeit): ");
|
||||
String zeitstempelEingabe = scanner.nextLine();
|
||||
Date einfahrZeit = zeitstempelEingabe.isEmpty() ? new Date() : sdf.parse(zeitstempelEingabe);
|
||||
|
||||
PKW pkw = new PKW(kennzeichen, einfahrZeit);
|
||||
parkendeAutos.add(pkw);
|
||||
|
||||
System.out.println("Auto eingefahren: " + kennzeichen + " um " + sdf.format(einfahrZeit));
|
||||
}
|
||||
|
||||
private static void bezahlen() throws ParseException {
|
||||
System.out.print("Kennzeichen: ");
|
||||
String kennzeichen = scanner.nextLine();
|
||||
PKW pkw = findeAuto(kennzeichen);
|
||||
if (pkw == null) {
|
||||
System.out.println("Auto nicht gefunden.");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.print("Ausfahrtszeit (dd.MM.yyyy, HH:mm) (leer für aktuelle Zeit): ");
|
||||
String zeitstempelEingabe = scanner.nextLine();
|
||||
Date ausfahrZeit = zeitstempelEingabe.isEmpty() ? new Date() : sdf.parse(zeitstempelEingabe);
|
||||
|
||||
double gebuehren = berechneGebuehren(pkw, ausfahrZeit);
|
||||
System.out.println("Parkgebühren: " + gebuehren + " Euro");
|
||||
|
||||
System.out.print("Kreditkartennummer (16-stellige VISA): ");
|
||||
String kreditkarte = scanner.nextLine();
|
||||
|
||||
if (kreditkarte.matches("\\d{16}") && istVisaGueltig(kreditkarte)) {
|
||||
System.out.println("Zahlung erfolgreich.");
|
||||
parkendeAutos.remove(pkw);
|
||||
} else {
|
||||
System.out.println("Ungültige Kreditkarte. Zahlung fehlgeschlagen.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ausfahren() throws ParseException {
|
||||
System.out.print("Kennzeichen: ");
|
||||
String kennzeichen = scanner.nextLine();
|
||||
PKW pkw = findeAuto(kennzeichen);
|
||||
if (pkw == null) {
|
||||
System.out.println("Auto nicht gefunden oder hat nicht bezahlt.");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.print("Ausfahrtszeit (dd.MM.yyyy, HH:mm) (leer für aktuelle Zeit): ");
|
||||
String zeitstempelEingabe = scanner.nextLine();
|
||||
Date ausfahrZeit = zeitstempelEingabe.isEmpty() ? new Date() : sdf.parse(zeitstempelEingabe);
|
||||
|
||||
if (schuldenListe.contains(pkw)) {
|
||||
System.out.println("Auto hat noch unbezahlte Schulden!");
|
||||
schuldenListe.remove(pkw);
|
||||
} else {
|
||||
parkendeAutos.remove(pkw);
|
||||
System.out.println("Auto ausgefahren: " + kennzeichen + " um " + sdf.format(ausfahrZeit));
|
||||
}
|
||||
}
|
||||
|
||||
private static PKW findeAuto(String kennzeichen) {
|
||||
for (PKW pkw : parkendeAutos) {
|
||||
if (pkw.getKennzeichen().equals(kennzeichen)) {
|
||||
return pkw;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static double berechneGebuehren(PKW pkw, Date ausfahrZeit) {
|
||||
long diffInMillis = ausfahrZeit.getTime() - pkw.getEinfahrZeit().getTime();
|
||||
long diffInMinuten = diffInMillis / (1000 * 60);
|
||||
if (diffInMinuten <= 15) {
|
||||
return 0.0; // Erste 15 Minuten sind kostenlos
|
||||
}
|
||||
|
||||
double gebuehr = Math.ceil((diffInMinuten - 15) / 60.0) * STUNDENGEBUEHR;
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(pkw.getEinfahrZeit());
|
||||
|
||||
if (calendar.get(Calendar.HOUR_OF_DAY) >= 20 || calendar.get(Calendar.HOUR_OF_DAY) < 6) {
|
||||
gebuehr = Math.min(gebuehr, MAX_GEBUEHR_NACHTS);
|
||||
}
|
||||
|
||||
long tage = diffInMinuten / (60 * 24);
|
||||
if (tage >= 1) {
|
||||
gebuehr = Math.min(gebuehr + tage * TAGESGEBUEHR_MAX, TAGESGEBUEHR_MAX);
|
||||
}
|
||||
|
||||
if (pkw.getKennzeichen().endsWith("E")) {
|
||||
gebuehr *= (1 - RABATT_E_AUTO); // Rabatt für E-Autos
|
||||
}
|
||||
|
||||
return gebuehr;
|
||||
}
|
||||
|
||||
private static boolean istVisaGueltig(String kreditkarte) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < kreditkarte.length(); i++) {
|
||||
int ziffer = Integer.parseInt(String.valueOf(kreditkarte.charAt(i)));
|
||||
if (i % 2 == 0) {
|
||||
ziffer *= 2;
|
||||
if (ziffer > 9) ziffer -= 9;
|
||||
}
|
||||
sum += ziffer;
|
||||
}
|
||||
return sum % 10 == 0;
|
||||
}
|
||||
|
||||
private static String generiereZufallsKennzeichen() {
|
||||
String[] stadtCodes = {"MA", "ROK", "HD", "KA"};
|
||||
String[] buchstaben = {"SH", "ME", "XR", "AB"};
|
||||
|
||||
Random rand = new Random();
|
||||
String kennzeichen = stadtCodes[rand.nextInt(stadtCodes.length)] + "-" + buchstaben[rand.nextInt(buchstaben.length)] + " " + (rand.nextInt(9000) + 1000);
|
||||
|
||||
if (rand.nextBoolean()) {
|
||||
kennzeichen += "E"; // Optionale E für E-Autos
|
||||
}
|
||||
|
||||
return kennzeichen;
|
||||
}
|
||||
}
|
||||
|
||||
class PKW {
|
||||
private final String kennzeichen;
|
||||
private final Date einfahrZeit;
|
||||
|
||||
public PKW(String kennzeichen, Date einfahrZeit) {
|
||||
this.kennzeichen = kennzeichen;
|
||||
this.einfahrZeit = einfahrZeit;
|
||||
}
|
||||
|
||||
public String getKennzeichen() {
|
||||
return kennzeichen;
|
||||
}
|
||||
|
||||
public Date getEinfahrZeit() {
|
||||
return einfahrZeit;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue