Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public enum CustomerType
- {
- Individual,
- Company
- }
- public interface IRateable
- {
- double GetInterestAmount(int months);
- }
- public abstract class Account
- {
- public string CustomerFullName { get; set; }
- protected decimal Balance { get; set; }
- public CustomerType TypeOfCustomer { get; set; }
- public Account(string fullName, decimal balance, CustomerType typeCustomer)
- {
- this.CustomerFullName = fullName;
- this.Balance = balance;
- this.TypeOfCustomer = typeCustomer;
- }
- public void Deposit(decimal moneyToDeposit) { }
- }
- public class DepositAccount : Account, IRateable
- {
- public DepositAccount(string fullName, decimal balance, CustomerType typeCustomer)
- : base(fullName, balance, typeCustomer)
- { }
- public void Deposit(decimal money)
- {
- this.Balance += money;
- Console.WriteLine("Successful!");
- }
- public void WithDraw(decimal money)
- {
- if (money > this.Balance)
- {
- Console.WriteLine("Sorry! You haven't enough funds in your account! (-{0})", money - this.Balance);
- return;
- }
- else
- {
- this.Balance -= money;
- Console.WriteLine("Done.");
- }
- }
- public double GetInterestAmount(int months)
- {
- if (this.Balance >= 0 && this.Balance < 1000)
- {
- return 0;
- }
- else
- {
- return 1*months;
- }
- }
- }
- public class LoanAccount : Account, IRateable
- {
- private const int INDIVIDUAL_MONTHS_MINIMUM_REQUIRE = 3;
- private const int COMPANY_MONTHS_MINIMUM_REQUIRE = 2;
- public LoanAccount(string fullName, decimal balance, CustomerType typeCustomer)
- : base(fullName, balance, typeCustomer)
- { }
- public void Deposit(decimal money)
- {
- this.Balance += money;
- Console.WriteLine("Successful!");
- }
- public double GetInterestAmount(int months)
- {
- if (this.TypeOfCustomer == CustomerType.Individual && months <=INDIVIDUAL_MONTHS_MINIMUM_REQUIRE)
- {
- return 0;
- }
- else if (this.TypeOfCustomer == CustomerType.Individual && months > INDIVIDUAL_MONTHS_MINIMUM_REQUIRE)
- {
- return months-INDIVIDUAL_MONTHS_MINIMUM_REQUIRE;
- }
- if (this.TypeOfCustomer == CustomerType.Company && months <= COMPANY_MONTHS_MINIMUM_REQUIRE)
- {
- return 0;
- }
- else
- {
- return months - COMPANY_MONTHS_MINIMUM_REQUIRE;
- }
- }
- }
- public class MortgageAccount : Account, IRateable
- {
- private const int INDIVIDUAL_MONTHS_MINIMUM_REQUIRE = 6;
- private const int COMPANY_MONTHS_MINIMUM_REQUIRE = 12;
- private const double COMPANY_RATE = 1.5;
- public MortgageAccount(string fullName, decimal balance, CustomerType typeCustomer)
- : base(fullName, balance, typeCustomer)
- { }
- public void Deposit(decimal money)
- {
- this.Balance += money;
- Console.WriteLine("Successful!");
- }
- public double GetInterestAmount(int months)
- {
- if (this.TypeOfCustomer == CustomerType.Individual && months<=6)
- {
- return 0;
- }
- else if (this.TypeOfCustomer == CustomerType.Individual && months > 6)
- {
- return months-INDIVIDUAL_MONTHS_MINIMUM_REQUIRE;
- }
- if (this.TypeOfCustomer == CustomerType.Company && months <= 12)
- {
- return months*COMPANY_RATE;
- }
- else
- {
- return months-COMPANY_MONTHS_MINIMUM_REQUIRE;
- }
- }
- }
Add Comment
Please, Sign In to add comment