Tuesday, November 15, 2011

program bank dalam c#


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

namespace ConsoleApplication1
{
    public class bank
    {
        private int amount;
        private static int total;
        public void deposit(int amt)
        {
            amount += amt;
            total = total + amt;
        }
        public void withdraw(int amt)
        {
            if (amount < amt)
            {
                Console.WriteLine("Saldo Kurang");
            }
            else
            {
                amount -= amt;
                total = total - amt;
            }
        }
        public void cek_saldo()
        {
            Console.WriteLine("Jumlah Saldo Anda = {0}", amount);
        }
        public static void show_total()
        {
            Console.WriteLine("Jumlah Uang di Bank =  {0}", total);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Jumlah Nasabah = ");
            int n_nasabah = int.Parse(Console.ReadLine());
            bank[] nasabah = new bank[n_nasabah + 1];
            for (int i = 1; i <= n_nasabah; i++)
            {
                nasabah[i] = new bank();
            }

            while (true)
            {
                Console.WriteLine("Pilihan : ");
                Console.WriteLine("     1. Menabung");
                Console.WriteLine("     2. Mengambil Uang");
                Console.WriteLine("     3. Cek_Saldo");
                Console.WriteLine("     4. Cek_saldo_bank");
                Console.WriteLine("     5. 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:
                        {
                            bank.show_total();
                            Console.WriteLine();
                            break;
                        }
                    case 5:
                        return;
                }
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public class bank
    {
        private int amount;
        private static int total;
        public void deposit(int amt)
        {
            amount += amt;
            total = total + amt;
        }
        public void withdraw(int amt)
        {
            if (amount < amt)
            {
                Console.WriteLine("Saldo Kurang");
            }
            else
            {
                amount -= amt;
                total = total - amt;
            }
        }
        public void cek_saldo()
        {
            Console.WriteLine("Jumlah Saldo Anda = {0}", amount);
        }
        public static void show_total()
        {
            Console.WriteLine("Jumlah Uang di Bank =  {0}", total);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Jumlah Nasabah = ");
            int n_nasabah = int.Parse(Console.ReadLine());
            bank[] nasabah = new bank[n_nasabah + 1];
            for (int i = 1; i <= n_nasabah; i++)
            {
                nasabah[i] = new bank();
            }

            while (true)
            {
                Console.WriteLine("Pilihan : ");
                Console.WriteLine("     1. Menabung");
                Console.WriteLine("     2. Mengambil Uang");
                Console.WriteLine("     3. Cek_Saldo");
                Console.WriteLine("     4. Cek_saldo_bank");
                Console.WriteLine("     5. 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:
                        {
                            bank.show_total();
                            Console.WriteLine();
                            break;
                        }
                    case 5:
                        return;
                }
            }
        }
    }
}

No comments:

Post a Comment