Guest User

Banking System

a guest
Sep 20th, 2017
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.62 KB | None | 0 0
  1. namespace BankingSystem
  2. {
  3.     class Program
  4.     {
  5.  
  6.         static void Main(string[] args)
  7.         {
  8.             ShowMainMenu();
  9.         }
  10.  
  11.         public static void ShowMainMenu()
  12.         {
  13.             Console.Clear();
  14.             Console.WriteLine("Weolcome to the Bank");
  15.             Console.WriteLine("-------------------");
  16.             Console.WriteLine("1: Create customer");
  17.             Console.WriteLine("2: Show Customers");
  18.             Console.WriteLine("-----------------");
  19.             string command = Console.ReadLine();
  20.             if (command == "1")
  21.             {
  22.                 ShowCreateCustomer();
  23.             }
  24.             else if (command == "2")
  25.             {
  26.                 ShowAllCustomers();
  27.             }
  28.         }
  29.  
  30.         public static void ShowAllCustomers()
  31.         {
  32.             Console.Clear();
  33.             Console.WriteLine("-----  All Customers -----");
  34.             foreach (Customer myCustomer in Bank.AllCustomers)
  35.             {
  36.                 Console.WriteLine("ID: " + myCustomer.Id + " Name: " + myCustomer.Name + " Money: " + myCustomer.Money);
  37.             }
  38.             Console.WriteLine("-----------");
  39.             Console.WriteLine("1: Deposit, 2: Transfer, 3: Return to main");
  40.             string command = Console.ReadLine();
  41.             if (command == "1")
  42.             {
  43.                 //deposit
  44.                 //first find the customer, then deposit the amount
  45.                 Console.Write("Enter the id of the customer: ");
  46.                 string customerId = Console.ReadLine();
  47.                 Console.Write("Enter the amount to deposit: ");
  48.                 string amount = Console.ReadLine();
  49.                 //now do the magic, find the customer then increase the money
  50.                 int theCustomerId = int.Parse(customerId);
  51.                 Customer myFoundCustomer = null;
  52.                 foreach (Customer c in Bank.AllCustomers)
  53.                 {
  54.                     if (c.Id == theCustomerId)
  55.                     {
  56.                         myFoundCustomer = c;
  57.                         break;
  58.                     }
  59.                 }
  60.                 //we might have found it
  61.                 if (myFoundCustomer != null)
  62.                 {
  63.                     myFoundCustomer.Money += float.Parse(amount);
  64.                 }
  65.                 ShowAllCustomers();
  66.             }
  67.             else if (command == "2")
  68.             {
  69.                 TransferMoney();
  70.             }
  71.             else if (command == "3")
  72.             {
  73.                 ShowMainMenu();
  74.             }
  75.         }
  76.  
  77.         public static void ShowCreateCustomer()
  78.         {
  79.             Console.Clear();
  80.             Console.WriteLine("--- Create new Customer ---");
  81.             Console.Write("Please enter the name: ");
  82.             string name = Console.ReadLine();
  83.             Console.Write("Please enter the id: ");
  84.             string id = Console.ReadLine();
  85.             Customer customer = new Customer();
  86.             customer.Name = name;
  87.             customer.Id = int.Parse(id);
  88.             //add it to the bank
  89.             Bank.AllCustomers.Add(customer);
  90.             //create customer etc...
  91.             //eventually return to main menu
  92.             ShowMainMenu();
  93.         }
  94.  
  95.         public static void TransferMoney()
  96.         {
  97.             Console.Clear();
  98.             Console.WriteLine("--- Transfer Money ---");
  99.             Console.Write("Please enter your account's ID: ");
  100.             string id = Console.ReadLine();
  101.             Console.Write("Please enter the Name of the person you would like to tranfer funds to: ");
  102.             string name = Console.ReadLine();
  103.             Console.Write("Enter the amount of funds you would like to transfer: ");
  104.             string amount = Console.ReadLine();
  105.  
  106.             /*
  107.             if (id == Customer.Id()) & (name == Customer.Name())
  108.             {
  109.                 //transfer happens here
  110.             }
  111.             */
  112.             ShowAllCustomers();
  113.         }
  114.     }
  115. }
  116.  
  117. namespace BankingSystem
  118. {
  119.     public class Bank
  120.     {
  121.         private static List<Customer> customers = new List<Customer>();
  122.         public Bank()
  123.         {
  124.             customers = new List<Customer>();
  125.         }
  126.  
  127.         public static List<Customer> AllCustomers
  128.         {
  129.             get
  130.             {
  131.                 return customers;
  132.             }
  133.         }
  134.     }
  135. }
  136.  
  137. namespace BankingSystem
  138. {
  139.     public class Customer
  140.     {
  141.         public Customer()
  142.         {
  143.             Money = 50;
  144.         }
  145.         public int Id { get; set; }
  146.         public string Name { get; set; }
  147.         public float Money { get; set; }
  148.     }
  149. }
Add Comment
Please, Sign In to add comment