-
Notifications
You must be signed in to change notification settings - Fork 0
/
atm.php
56 lines (44 loc) · 1.19 KB
/
atm.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
class ATM
{
private $saldo;
public function __construct($saldoAwal)
{
$this->saldo = $saldoAwal;
}
public function cekSaldo()
{
echo "Saldo saat ini: Rp " . number_format($this->saldo, 0, ',', '.') . PHP_EOL;
}
public function tarikTunai($jumlah)
{
if($jumlah <= 0) {
echo "Jumlah penarikan tidak valid" . PHP_EOL;
return;
}
if ($jumlah > $this->saldo) {
echo "Saldo tidak mencukupi" . PHP_EOL;
return;
}
$this->saldo -= $jumlah;
echo "Penarikan tunai berhasil. Saldo Anda Sekarang: Rp " . number_format($this->saldo, 0, ',', '.') . PHP_EOL;
}
public function setorTunai($jumlah)
{
if ($jumlah <= 0) {
echo "Jumlah penyetoran tidak valid" . PHP_EOL;
return;
}
$this->saldo += $jumlah;
echo "Setoran tunai berhasil. Saldo Anda Sekarang: Rp " . number_format($this->saldo, 0, ',', '.') . PHP_EOL;
}
}
$atm = new Atm(1000000);
$atm->cekSaldo();
$atm->tarikTunai(500000);
$atm->cekSaldo();
$atm->setorTunai(200000);
$atm->cekSaldo();
$atm->setorTunai(1000000);
$atm->cekSaldo();
?>