document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace ATM
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         int saldo, jumlah;
  16.         Tabungan tabungan = new Tabungan(0);
  17.  
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.        
  23.         private void button1_Click(object sender, EventArgs e)
  24.         {
  25.             saldo = tabungan.cekSaldo();
  26.             label3.Text = "Rp. " + saldo;
  27.         }
  28.  
  29.         private void button2_Click(object sender, EventArgs e)
  30.         {
  31.             jumlah = Convert.ToInt32(textBox1.Text);
  32.             tabungan.simpanUang(jumlah);
  33.         }
  34.        
  35.         private void button3_Click_1(object sender, EventArgs e)
  36.         {
  37.             jumlah = Convert.ToInt32(textBox1.Text);
  38.             if (tabungan.ambilRupiah(jumlah))
  39.             {
  40.                 label6.Text = "Transaksi berhasil!";
  41.             }
  42.             else
  43.             {
  44.                 label6.Text = "Transaksi gagal, Saldo Anda tidak mencukupi!";
  45.             }
  46.         }
  47.     }
  48.     class Tabungan
  49.     {
  50.         int saldo;
  51.         public Tabungan(int initial_saldo)
  52.         {
  53.             saldo = initial_saldo;
  54.         }
  55.         public int cekSaldo()
  56.         {
  57.             return saldo;
  58.         }
  59.         public void simpanUang(int jumlah)
  60.         {
  61.             int cek = (saldo + jumlah);
  62.             if (cek >= 0)
  63.             {
  64.                 saldo += jumlah;
  65.             }
  66.         }
  67.        
  68.         public Boolean ambilRupiah(int jumlah)
  69.         {
  70.             int cek = saldo - jumlah;
  71.             if (cek >= 0)
  72.             {
  73.                 saldo -= jumlah;
  74.                 return true;
  75.             }
  76.             return false;
  77.         }
  78.  
  79.     }
  80. }
  81.  
');