Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace MyBank
  8. {
  9.     class Customer
  10.     {
  11.         private string customerName;
  12.         private long pNo;
  13.  
  14.         private const int ACCOUNT_LIMIT = 5;
  15.         private List<BankAccount> accounts;
  16.  
  17.         // Constructor
  18.         public Customer(string customerName, long pNo)
  19.         {
  20.             this.customerName = customerName;
  21.             this.pNo = pNo;
  22.  
  23.             accounts = new List<BankAccount>();
  24.         }
  25.  
  26.         // Getter/Setter
  27.         public long PNo { get => pNo;}
  28.         public string CustomerName { get => customerName; set => customerName = value; }
  29.  
  30.         // Creates a SavingsAccount
  31.         public bool CreateSavingsAccount()
  32.         {
  33.             if (accounts.Count < ACCOUNT_LIMIT)
  34.             {
  35.                 accounts.Add(new SavingsAccount(customerName));
  36.                 return true;
  37.             }
  38.             return false;
  39.         }
  40.  
  41.         // Creates CreditAccount
  42.         public bool CreateCreditAccount()
  43.         {
  44.             if (accounts.Count < ACCOUNT_LIMIT)
  45.             {
  46.                 accounts.Add(new CreditAccount(customerName));
  47.                 return true;
  48.             }
  49.             return false;
  50.         }
  51.  
  52.         // Deletes an account with accountNumber
  53.         public bool DeleteAccount(int accountNumber)
  54.         {
  55.             foreach (BankAccount account in accounts)
  56.             {
  57.                 if (accountNumber == account.AccountNumber)
  58.                 {
  59.                     accounts.Remove(account);
  60.                     return true;
  61.                 }
  62.             }
  63.             return false;
  64.         }
  65.  
  66.         // Displays account information
  67.         public string DisplayAccountInfo(int accountNumber)
  68.         {
  69.             foreach (BankAccount account in accounts)
  70.             {
  71.                 if (accountNumber == account.AccountNumber)
  72.                     return account.DisplayAccount();
  73.             }
  74.  
  75.             return "";
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement