Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/repetition/
hemligheter.php
repetition.php
repetition1.php
repetition2.php
repetition3.php
repetition3_medel.php
repetition4.php
repetition5.php
repetition6.php
repetition7.php
repetition8.php
repetition6.php
107 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Repetition</title>
</head>
<body>
<?php
class Boll {
private $radie;
protected $typ;
static $antal = 0;
private function setRadie($radie) {
$this->radie = $radie."cm";
}
public function getRadie() {
return $this->radie;
}
public function __construct($radie){
$this::setRadie($radie);
$this->typ = "Bollen";
$this::$antal++;
}
static function getAntal() {
return Boll::$antal;
}
public function info() {
echo "<br>$this->typ har radien ".$this->getRadie().". ";
}
}
class Fotboll extends Boll {
private $mönster;
protected $typ;
private function setMönster($mönster) {
$this->mönster = $mönster;
}
private function getMönster() {
return $this->mönster;
}
public function __construct($radie, $mönster) {
parent::__construct($radie);
$this::setMönster($mönster);
$this->typ = "Fotbollen";
}
public function info() {
parent::info();
echo "Den är ".$this::getMönster().".";
}
}
class Bowlingingklot extends Boll {
private $massa;
protected $typ;
private function setMassa($massa) {
$this->massa = $massa;
}
private function getMassa() {
return $this->massa."kg";
}
public function __construct($radie, $massa) {
parent::__construct($radie);
$this::setMassa($massa);
$this->typ = "Bowlingklotet";
}
public function info() {
parent::info();
echo "Den väger ".$this::getMassa().".";
}
}
$bollar = [
new Fotboll(50, "rutig"),
new Boll(180),
new Bowlingingklot(20, 10)
];
foreach($bollar as $boll) {
$boll->info();
}
echo "<br><br>Det finns ".Boll::$antal." bollar.";
?>
</body>
</html>