60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
class Konto
|
|
{
|
|
private int $kontonummer;
|
|
private float $kontostand;
|
|
private string $inhaber;
|
|
|
|
public function __construct($kn = 000000, $ks = 000.00, $ki = "max, Mustermann")
|
|
{
|
|
$this->kontonummer = $kn;
|
|
$this->kontostand = $ks;
|
|
$this->inhaber = $ki;
|
|
|
|
echo "<p>Konto: " .$this->kontonummer ." wurde erfolgreich angelegt</p>";
|
|
echo "<p>Kontoinhaber: " .$this->inhaber ."</p>";
|
|
echo "<p>Kontostand: " .$this->kontostand ." Euro</p>";
|
|
echo "<hr><br><hr>";
|
|
}
|
|
|
|
public function einzahlung(float $wert)
|
|
{
|
|
$this->kontostand = $this->kontostand + $wert;
|
|
|
|
echo "<p>Der Betrag " .$wert ."€ wurde auf das Konto mit der Kontonummer " .$this->kontonummer ." eingezahlt. <br>";
|
|
echo "Neuer Kontostand beträgt: " .$this->kontostand ."€</p>";
|
|
echo "<hr><hr>";
|
|
}
|
|
|
|
public function abheben(float $wert)
|
|
{
|
|
if ($this->kontostand - $wert >= 0)
|
|
{
|
|
$this->kontostand = $this->kontostand - $wert;
|
|
echo "<p>Der Betrag " .$wert ."€ wurde vom Konto mit der Kontonummer " .$this->kontonummer ." ausgezahlt. <br>";
|
|
echo "Neuer Kontostand beträgt: " .$this->kontostand ."€</p>";
|
|
echo "<hr><hr>";
|
|
}
|
|
else
|
|
{
|
|
echo "<p>Nicht genug Guthaben zum Auszahlen auf dem Konto " .$this->kontonummer ."</p>";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$mayer = new Konto(123, 1000, "Meier, Hans");
|
|
|
|
$mayer->einzahlung(500.50);
|
|
|
|
$schulze = new Konto(789, 12300.5, "Schulze, Claudia");
|
|
|
|
$schulze->einzahlung(20.50);
|
|
|
|
$mayer->abheben(50.75);
|
|
|
|
$schulze->abheben(20000);
|
|
|
|
|
|
?>
|