Hétfői Backend óra
This commit is contained in:
41
Suli/13.b/Backend/2024. 11. 18/obj.php
Normal file
41
Suli/13.b/Backend/2024. 11. 18/obj.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
class Tanulo {
|
||||
public $nev;
|
||||
public $kor;
|
||||
public $jegyek = [];
|
||||
|
||||
public function __construct($nev, $kor) {
|
||||
$this->nev = $nev;
|
||||
$this->kor = $kor;
|
||||
}
|
||||
|
||||
public function adjegy($jegy) {
|
||||
$this->jegyek[] = $jegy;
|
||||
}
|
||||
|
||||
public function atlagkiszamit() {
|
||||
if (count($this->jegyek) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
else {
|
||||
return array_sum($this->jegyek) / count($this->jegyek);
|
||||
}
|
||||
}
|
||||
|
||||
public function adatkiir() {
|
||||
$atlag = $this->atlagkiszamit();
|
||||
echo "Név: {$this->nev}, Kor: {$this->kor}, Átlag: {$atlag}";
|
||||
}
|
||||
}
|
||||
|
||||
$tan1 = new Tanulo("Kis Péter", 15);
|
||||
$tan1->adjegy(5);
|
||||
$tan1->adjegy(1);
|
||||
$tan1->adjegy(3);
|
||||
$tan1->adjegy(2);
|
||||
$tan1->adatkiir();
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user