zoukankan      html  css  js  c++  java
  • CurrentAccounts.cs

    using System;
    using Wrox.ProCSharp;
    using Wrox.ProCSharp.VenusBank;
    using Wrox.ProCSharp.JupiterBank;

    namespace Wrox.ProCSharp
    {
       class MainEntryPoint
       {
          static void Main()
          {
            IBankAccount venusAccount = new SaverAccount();
                    ITransferBankAccount jupiterAccount = new CurrentAccount();
                    venusAccount.PayIn(200);
                    jupiterAccount.PayIn(500);
                    jupiterAccount.TransferTo(venusAccount, 100);
                    Console.WriteLine(venusAccount.ToString());
                    Console.WriteLine(jupiterAccount.ToString());
          }
       }
    }


    namespace Wrox.ProCSharp
    {
       public interface IBankAccount
       {
          void PayIn(decimal amount);
          bool Withdraw(decimal amount);
          decimal Balance
          {
             get;
          }
       }
        
        
         public interface ITransferBankAccount : IBankAccount
       {
          bool TransferTo(IBankAccount destination, decimal amount);
       }
    }

    namespace Wrox.ProCSharp.VenusBank
    {
       public class SaverAccount : IBankAccount
       {
          private decimal balance;
          public void PayIn(decimal amount)
          {
             balance += amount;
          }
          public bool Withdraw(decimal amount)
          {
             if (balance >= amount)
             {
                balance -= amount;
                return true;
             }
             Console.WriteLine("Withdrawal attempt failed.");
             return false;
          }
          public decimal Balance
          {
             get
             {
                return balance;
             }
          }
          public override string ToString()
          {
             return String.Format("Venus Bank Saver: Balance = {0,6:C}", balance);
          }
       }
    }



    namespace Wrox.ProCSharp.JupiterBank
    {
       public class CurrentAccount : ITransferBankAccount
    {
       private decimal balance;
       public void PayIn(decimal amount)
       {
          balance += amount;
       }
       public bool Withdraw(decimal amount)
       {
          if (balance >= amount)
          {
             balance -= amount;
             return true;
          }
          Console.WriteLine("Withdrawal attempt failed.");
          return false;
       }
       public decimal Balance
       {
          get
          {
             return balance;
          }
       }
       public bool TransferTo(IBankAccount destination, decimal amount)
       {
          bool result;
          if ((result = Withdraw(amount)) == true)
             destination.PayIn(amount);
          return result;
       }
       public override string ToString()
       {
          return String.Format("Jupiter Bank Current Account: Balance = {0,6:C}",
                                                                          balance);
       }   
     
    }


    }
  • 相关阅读:
    关于SVN出现 svn working copy locked的原因及解决方法
    安装SVN客户端重启电脑之后,右键未出现SVN选项的原因
    Django—工程创建以及models数据库易错点
    tornado之文件上传的几种形式form,伪ajax(iframe)
    python 收录集中实现线程池的方法
    python 多线程,进程的理解
    python之路 序列化 pickle,json
    collections模块方法详解
    python之路 socket,socketsever初探
    SQL- 约束
  • 原文地址:https://www.cnblogs.com/shihao/p/2506354.html
Copyright © 2011-2022 走看看