rkhaidir16

ATM Dart

Aug 26th, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.88 KB | None | 0 0
  1. import 'dart:io';
  2.  
  3. bool repeat = true;
  4.  
  5. void main() {
  6.   Atm atm_satu = Atm(123, 5000);
  7.   Atm atm_dua = Atm(456, 10000);
  8.  
  9.   do {
  10.     stdout.write("\nMasukkan PIN : ");
  11.     var pinMasuk = int.parse(stdin.readLineSync());
  12.  
  13.     if(pinMasuk == atm_satu.pin) {
  14.       atm_satu.menu();
  15.     } else if(pinMasuk == atm_dua.pin) {
  16.       atm_dua.menu();
  17.     } else {
  18.       print("Pin Salah");
  19.     }
  20.   }while(repeat == true);
  21. }
  22.  
  23. class Atm {
  24.   int pin;
  25.   int saldo;
  26.  
  27.   Atm(int pin, int saldo) {
  28.     this.pin = pin;
  29.     this.saldo = saldo;
  30.   }
  31.  
  32.   void menu() {
  33.     do {
  34.       print("Selamat datang \n1. Tarik Tunai\n2. Setor Tunai\n3. Cek Saldo\n4. Ganti Akun\n5. Keluar Aplikasi\n\n");
  35.       stdout.write('Pilih Menu : ');
  36.       var option = int.parse(stdin.readLineSync());
  37.  
  38.       switch(option) {
  39.         case 1:
  40.           stdout.write('\nTarik Tunai \nNominal : ');
  41.           int withdrawal = int.parse(stdin.readLineSync());
  42.           if(withdrawal > saldo) {
  43.             print("\nSaldo anda tidak cukup");
  44.             print("Saldo anda sekarang $saldo");
  45.           } else {
  46.             saldo -= withdrawal;
  47.             print("\nJumlah Penarikan : $withdrawal\nSaldo anda  sekarang : $saldo\n\n");
  48.           }
  49.           break;
  50.  
  51.         case 2:
  52.           stdout.write('\nSetor Tunai \nNominal :');
  53.           int deposited = int.parse(stdin.readLineSync());
  54.           saldo += deposited;
  55.           print("\nJumlah Setoran : $deposited\nSaldo anda sekarang : $saldo\n\n");
  56.           break;
  57.        
  58.         case 3:
  59.           print("\nSaldo anda sekarang $saldo\n\n");
  60.           break;
  61.        
  62.         case 4:
  63.           main();
  64.           break;
  65.  
  66.         case 5:
  67.           print("\nTerima Kasih");
  68.           exit(0);
  69.           break;
  70.        
  71.         default:
  72.           print('\nMenu yang ada pilih tidak ada\n\n');
  73.       }
  74.     } while(repeat == true);
  75.   }
  76. }
Add Comment
Please, Sign In to add comment