TodorMitev

BankAccounts

Mar 14th, 2012
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.10 KB | None | 0 0
  1. public enum CustomerType
  2.     {
  3.         Individual,
  4.         Company
  5.     }
  6.     public interface IRateable
  7.     {
  8.         double GetInterestAmount(int months);
  9.     }
  10.     public abstract class Account
  11.     {
  12.         public string CustomerFullName { get; set; }
  13.         protected decimal Balance { get; set; }
  14.         public CustomerType TypeOfCustomer { get; set; }
  15.  
  16.         public Account(string fullName, decimal balance, CustomerType typeCustomer)
  17.         {
  18.             this.CustomerFullName = fullName;
  19.             this.Balance = balance;
  20.             this.TypeOfCustomer = typeCustomer;
  21.         }
  22.  
  23.         public void Deposit(decimal moneyToDeposit) { }
  24.     }
  25.     public class DepositAccount : Account, IRateable
  26.     {
  27.         public DepositAccount(string fullName, decimal balance, CustomerType typeCustomer)
  28.             : base(fullName, balance, typeCustomer)
  29.         { }
  30.  
  31.         public void Deposit(decimal money)
  32.         {
  33.             this.Balance += money;
  34.             Console.WriteLine("Successful!");
  35.         }
  36.  
  37.         public void WithDraw(decimal money)
  38.         {
  39.             if (money > this.Balance)
  40.             {
  41.                 Console.WriteLine("Sorry! You haven't enough funds in your account! (-{0})", money - this.Balance);
  42.                 return;
  43.             }
  44.             else
  45.             {
  46.                 this.Balance -= money;
  47.                 Console.WriteLine("Done.");
  48.             }
  49.         }
  50.  
  51.         public double GetInterestAmount(int months)
  52.         {
  53.             if (this.Balance >= 0 && this.Balance < 1000)
  54.             {
  55.                 return 0;
  56.             }
  57.             else
  58.             {
  59.                 return 1*months;
  60.             }
  61.         }
  62.     }
  63.     public class LoanAccount : Account, IRateable
  64.     {
  65.        private const int INDIVIDUAL_MONTHS_MINIMUM_REQUIRE = 3;
  66.        private const int COMPANY_MONTHS_MINIMUM_REQUIRE = 2;
  67.  
  68.         public LoanAccount(string fullName, decimal balance, CustomerType typeCustomer)
  69.             : base(fullName, balance, typeCustomer)
  70.         { }
  71.  
  72.         public void Deposit(decimal money)
  73.         {
  74.             this.Balance += money;
  75.             Console.WriteLine("Successful!");
  76.         }
  77.  
  78.         public double GetInterestAmount(int months)
  79.         {
  80.             if (this.TypeOfCustomer == CustomerType.Individual && months <=INDIVIDUAL_MONTHS_MINIMUM_REQUIRE)
  81.             {
  82.                 return 0;
  83.             }
  84.             else if (this.TypeOfCustomer == CustomerType.Individual && months > INDIVIDUAL_MONTHS_MINIMUM_REQUIRE)
  85.             {
  86.                 return months-INDIVIDUAL_MONTHS_MINIMUM_REQUIRE;
  87.             }
  88.             if (this.TypeOfCustomer == CustomerType.Company && months <= COMPANY_MONTHS_MINIMUM_REQUIRE)
  89.             {
  90.                 return 0;
  91.             }
  92.             else
  93.             {
  94.                 return months - COMPANY_MONTHS_MINIMUM_REQUIRE;
  95.             }
  96.         }
  97.     }
  98.     public class MortgageAccount : Account, IRateable
  99.     {
  100.         private const int INDIVIDUAL_MONTHS_MINIMUM_REQUIRE = 6;
  101.         private const int COMPANY_MONTHS_MINIMUM_REQUIRE = 12;
  102.  
  103.         private const double COMPANY_RATE = 1.5;
  104.  
  105.         public MortgageAccount(string fullName, decimal balance, CustomerType typeCustomer)
  106.             : base(fullName, balance, typeCustomer)
  107.         { }
  108.  
  109.         public void Deposit(decimal money)
  110.         {
  111.             this.Balance += money;
  112.             Console.WriteLine("Successful!");
  113.         }
  114.  
  115.         public double GetInterestAmount(int months)
  116.         {
  117.             if (this.TypeOfCustomer == CustomerType.Individual && months<=6)
  118.             {
  119.                 return 0;
  120.             }
  121.             else if (this.TypeOfCustomer == CustomerType.Individual && months > 6)
  122.             {
  123.                 return months-INDIVIDUAL_MONTHS_MINIMUM_REQUIRE;
  124.             }
  125.             if (this.TypeOfCustomer == CustomerType.Company && months <= 12)
  126.             {
  127.                 return months*COMPANY_RATE;
  128.             }
  129.             else
  130.             {
  131.                 return months-COMPANY_MONTHS_MINIMUM_REQUIRE;
  132.             }
  133.         }
  134.     }
Add Comment
Please, Sign In to add comment