1 using System; 2 using study.a; 3 using study.b; 4 using study; 5 6 namespace study { 7 8public interface IBlankAccount 9{ 10 void PlayIn(decimal amount); 11 bool Withdraw(decimal amount); 12 13 decimal Balance{ 14 15 get; 16 17 } 18} 19 20 21public interface ITransferBankAccount:IBlankAccount{ 22 23 24 bool TransaferTo(IBlankAccount BankName,decimal amcount); 25 26} 27 28 29 30 31public class MainEntry 32{ 33 static void Main(){ 34 ITransferBankAccount vensAccount=new saveCount(); 35 IBlankAccount jenAccount=new GoldAccount(); 36 vensAccount.PlayIn(400); 37 jenAccount.PlayIn(500); 38// Console.WriteLine(vensAccount.ToString()); 39 40// vensAccount.Withdraw(100); 41// vensAccount.PlayIn(800); 42// vensAccount.Withdraw(200); 43 vensAccount.TransaferTo(jenAccount,100); 44 45 Console.WriteLine(vensAccount.ToString()); 46 Console.WriteLine(jenAccount.ToString()); 47 } 48 49 50 51}} 52 53 54 55 56 namespace study.a 57 { 58 public class saveCount:ITransferBankAccount{ 59 60 private decimal balance; 61 62public void PlayIn(decimal amount) 63 64{ 65 balance+=amount; 66 67} 68 69public bool Withdraw(decimal amount) 70{ 71 72 if(balance>=amount) 73 { 74 balance-=amount; 75 76 return true; 77 } 78 Console.WriteLine("取钱失败"); 79 return false; 80 81} 82 83public decimal Balance{ 84 85 get{ 86 87 return balance; 88 } 89 90} 91 92 93public bool TransaferTo(IBlankAccount BankName,decimal amcount) 94{ 95 bool result; 96 if((result= Withdraw(amcount))==true) 97 BankName.PlayIn(amcount); 98 return result; 99}100101 102103104public override string ToString(){105 106 107 return String.Format("{0,6:c}",balance);108}109110}} 111 112 namespace study.b {113114 public class GoldAccount:ITransferBankAccount{115 116 117 private decimal balance;118119public void PlayIn(decimal amount)120121{122 balance+=amount;123124}125126public bool Withdraw(decimal amount)127{128129 if(balance>=amount)130 {131 balance-=amount;132 133 return true;134 }135 Console.WriteLine("取钱失败");136 return false;137138}139140public decimal Balance{141142 get{143 144 return balance;145 }146147}148 149 150public bool TransaferTo(IBlankAccount BankName,decimal amcount)151{152 bool result;153 if((result= Withdraw(amcount))==true)154 BankName.PlayIn(amcount);155 return result;156}157158 159160161public override string ToString(){162 163 164 return String.Format("{0,6:c}",balance);165}166 167 168 }} 169 170 171 172 173 174 175 176 177 178 179 180
转载于:https://www.cnblogs.com/hansan198703/archive/2008/05/23/1205829.html