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);
       }   
     
    }


    }
  • 相关阅读:
    Mysql case when 根据数字排序 返回 string类型问题
    .NET Core 面试题
    一个人如何完成一整个网站的开发(推荐好文,看完绝对让你回味无穷)转载
    (转)实现C#中等价于的Javascript中的Math.Random()的函数,以得到一个随机数,double类型的,大于0小于1的,17位精度的
    brew安装指定版本的软件
    服务器被植入挖矿木马的心酸过程
    我把双系统的win10抹除了现在开机只按option还是会出现双系统选择,怎么把那个win10给取消了或删除掉
    java.lang.Exception: The server rejected the connection: None of the protocols were accepted
    Linux 技巧:让进程在后台可靠运行的几种方法
    jenkins backup and migration
  • 原文地址:https://www.cnblogs.com/shihao/p/2506354.html
Copyright © 2011-2022 走看看