Tuesday, December 6, 2011

program bank inheritance versi 2 dalam c#



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    abstract class bank
    {
        private int amount;
        public void deposit(int amt)
        {
            amount += amt;
        }
        public void withdraw(int amt)
        {
            if (amount < amt)
            {
                Console.WriteLine("Saldo Kurang");
            }
            else
            {
                amount -= amt;
            }
        }
        public void cek_saldo()
        {
            Console.WriteLine("Jumlah Saldo Anda = {0}", amount);
        }
    }
    class BNI : bank
    {
        private int temp;
        public void a1()
        {
            base.deposit(temp);
            base.withdraw(temp);
            base.cek_saldo();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Jumlah Nasabah = ");
            int n_nasabah = int.Parse(Console.ReadLine());
            BNI[] nasabah = new BNI[n_nasabah + 1];
            for (int i = 1; i <= n_nasabah; i++)
            {
                nasabah[i] = new BNI();
            }
         
            while (true)
            {
                Console.WriteLine("Pilihan : ");
                Console.WriteLine("     1. Menabung");
                Console.WriteLine("     2. Mengambil Uang");
                Console.WriteLine("     3. Cek_Saldo");
                Console.WriteLine("     4. keluar");
                Console.Write("Pilih : ");
                int pilih = int.Parse(Console.ReadLine());
                int no_rek;
                int jumlah;
                switch (pilih)
                {
                    case 1:
                        {
                            Console.Write("Nomor Rekening Anda : ");
                            no_rek = int.Parse(Console.ReadLine());
                            Console.Write("Jumlah Uang ");
                            jumlah = int.Parse(Console.ReadLine());
                            nasabah[no_rek].deposit(jumlah);
                            break;
                        }
                    case 2:
                        {
                            Console.Write("Nomor Rekening Anda : ");
                            no_rek = int.Parse(Console.ReadLine());
                            Console.Write("Jumlah Uang ");
                            jumlah = int.Parse(Console.ReadLine());
                            nasabah[no_rek].withdraw(jumlah);
                            break;
                        }
                    case 3:
                        {
                            Console.Write("Nomor Rekening Anda : ");
                            no_rek = int.Parse(Console.ReadLine());
                            nasabah[no_rek].cek_saldo();
                            break;
                        }
                    case 4:
                        return;
                }
            }
        }
    }
}

No comments:

Post a Comment