Skip to content

Instantly share code, notes, and snippets.

@asbp
Created November 12, 2019 15:15
Show Gist options
  • Save asbp/a5c2919798af383f35e0c9a4ebd0368c to your computer and use it in GitHub Desktop.
Save asbp/a5c2919798af383f35e0c9a4ebd0368c to your computer and use it in GitHub Desktop.
Aplikasi ATM sederhana pisan
import 'dart:io';
class User {
String nama, pin;
int saldo;
User(String nama, String pin, int saldo) {
this.nama = nama;
this.pin = pin;
this.saldo = saldo;
}
}
List<User> listUser = new List();
bool ketemu =false;
int uid;
void main(List<String> args) {
listUser.add(new User("Fulan", "2345", 14500));
listUser.add(new User("Doe", "5678", 90000));
print("Selamat datang di Bank Dart.\n");
welcome();
}
void welcome() {
ketemu = false;
stdout.write("Masukkan PIN: ");
int i = 0;
var pin = stdin.readLineSync();
for(User u in listUser) {
i++;
if(pin==u.pin) {
ketemu = true;
uid = i;
print("");
print("");
home(u);
}
}
if(!ketemu) welcome();
}
void home(User log) {
print("Selamat datang, "+log.nama+".");
print("Saldo Anda: Rp"+log.saldo.toString());
print("");
print("1. Setor tunai");
print("2. Tarik tunai");
print("3. Ganti akun");
print("4. Keluar");
print("");
stdout.write("Silakan pilih: ");
var p = stdin.readLineSync();
switch (p) {
case "1":
setor(log);
break;
case "2":
tarik(log);
break;
case "3":
ganti_akun(log);
break;
default:
}
}
void setor(User log) {
stdout.write("Mau menyetor berapa? ");
int uang;
try {
uang = int.parse(stdin.readLineSync());
} on Exception catch (_) {
print('Mohon maaf, nominal penyetoran harus dalam bentuk angka.');
print("");
setor(log);
} finally {
print('Setoran Anda sebesar $uang berhasil.');
print("");
log.saldo += uang;
home(log);
}
}
void tarik(User log) {
stdout.write("Mau menarik berapa? ");
int uang;
try {
uang = int.parse(stdin.readLineSync());
} on Exception catch (_) {
print('Mohon maaf, nominal penarikan harus dalam bentuk angka.');
print("");
setor(log);
} finally {
if(uang >= log.saldo) {
print('Penarikan Anda sebesar $uang gagal karena saldo tidak mencukupi.');
print("");
} else {
print('Penarikan Anda sebesar $uang berhasil.');
print("");
log.saldo -= uang;
}
home(log);
}
}
void ganti_akun(User log) {
listUser[uid-1].saldo = log.saldo;
welcome();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment