bestellnummer
";
for($i=0; $ipostenfeld); $i++)
{
$ausgabe .= "Posten " . ($i+1) . ": "
. $this->postenfeld[$i] . "
";
$gesamt += $this->postenfeld[$i]->postenpreis();
}
$ausgabe .= "Gesamtpreis: $gesamt €
";
return $ausgabe;
}
}
class Bestellposten
{
function __construct(private $artikelname = "unbekannt",
private $anzahl = 0, private $preis = 0.0) { }
function postenpreis()
{
return $this->anzahl * $this->preis;
}
function __toString()
{
return "$this->artikelname, $this->anzahl St., "
. "$this->preis €";
}
}
/* Hauptprogramm */
$meineBestellung = new Bestellung(583,
array(new Bestellposten("Apfel", 3, 1.35),
new Bestellposten("Banane", 5, 0.85),
new Bestellposten("Mango", 2, 1.95)));
echo $meineBestellung;
?>