2024-10-21 22:35:46 +02:00
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
2024-10-21 18:52:25 +02:00
|
|
|
public class Bestellung {
|
|
|
|
private Warenkorb warenkorb;
|
|
|
|
private float versandkosten;
|
2024-10-21 22:35:46 +02:00
|
|
|
private LocalDateTime bestellDatum;
|
2024-10-21 18:52:25 +02:00
|
|
|
|
|
|
|
public Bestellung(Warenkorb warenkorb, float versandkosten) {
|
2024-10-21 22:35:46 +02:00
|
|
|
if (warenkorb == null) {
|
|
|
|
throw new IllegalArgumentException("Warenkorb darf nicht null sein.");
|
|
|
|
}
|
|
|
|
if (versandkosten < 0) {
|
|
|
|
throw new IllegalArgumentException("Versandkosten dürfen nicht negativ sein.");
|
|
|
|
}
|
2024-10-21 18:52:25 +02:00
|
|
|
this.warenkorb = warenkorb;
|
|
|
|
this.versandkosten = versandkosten;
|
2024-10-21 22:35:46 +02:00
|
|
|
this.bestellDatum = LocalDateTime.now(); // Bestelldatum setzen
|
|
|
|
}
|
|
|
|
|
|
|
|
public Warenkorb getWarenkorb() {
|
|
|
|
return warenkorb;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getVersandkosten() {
|
|
|
|
return versandkosten;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LocalDateTime getBestellDatum() {
|
|
|
|
return bestellDatum;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float berechneGesamtpreis() {
|
|
|
|
return warenkorb.berechneGesamtPreis() + versandkosten;
|
2024-10-21 18:52:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2024-10-21 22:35:46 +02:00
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss");
|
|
|
|
return String.format("Bestellung am %s:\n%sVersandkosten: %.2f Euro\nGesamtpreis: %.2f Euro",
|
|
|
|
bestellDatum.format(formatter), warenkorb.toString(), versandkosten, berechneGesamtpreis());
|
2024-10-21 18:52:25 +02:00
|
|
|
}
|
|
|
|
}
|