-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdua.php
42 lines (33 loc) · 1.05 KB
/
dua.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
require_once 'libs.php';
class Siswa
{
private string $nrp;
private string $nama;
private Nilai $daftarNilai;
public function __construct(string $nrp, string $nama, array $daftarNilai) {
$this->nrp = $nrp;
$this->nama = $nama;
$this->daftarNilai = new Nilai($daftarNilai['mapel'], $daftarNilai['nilai']);
}
}
class Nilai
{
private string $mapel;
private int $nilai;
const MAPEL = ['inggris', 'indonesia', 'jepang'];
public function __construct(string $mapel, int $nilai) {
$this->mapel = $mapel;
$this->nilai = $nilai;
}
}
$newStudent = new Siswa('123', 'ali', ['mapel' => 'inggris', 'nilai' => 100]);
var_dump($newStudent);
$students = [];
for ($i=0; $i < 10; $i++) {
$students[$i] = new Siswa($i, Libs::generateRandomString(), [
'mapel' => Nilai::MAPEL[rand(0, 2)],
'nilai' => rand(0, 100),
]);
}
var_dump($students);