110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using Wrox.ProCSharp;
using Wrox.ProCSharp.VenuseBank;
using Wrox.ProCSharp.JupterBank;
namespace Wrox.ProCSharp {
public class MainEntryPoint {
public void Main (string[] args){
IBankAccount venuseAccount = new SaverAccount();
IBankAccount jupterAccount = new GoldAccount ();
venuseAccount.PayIn (200m);
venuseAccount.Withdraw (100m);
Console.WriteLine( venuseAccount.ToString() );
jupterAccount.PayIn (500m);
jupterAccount.Withdraw (600m);
jupterAccount.Withdraw (100m);
Console.WriteLine ( jupterAccount.ToString() );
}
}
}
相关与MainEntryPoint的其它类是这样的using System;
namespace Wrox.ProCSharp {
public interface IBankAccount {
void PayIn (decimal amount);
bool Withdraw (decimal amount);
decimal Balance {
get;
}
}
}
using System;
namespace Wrox.ProCSharp.VenuseBank {
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.WritLine( "Withdraw attempt failed!~" );
return false;
}
public decimal Balance {
get{ return balance; }
}
public override string ToString (){
return string.Format( "Venuse Bank Saver : Balance = {0,6:C}",balance );
}
}
}
using System;
namespace Wrox.ProCSharp.JupterBank {
public class GoldAccount : IBankAccount {
private decimal balance;
public void PayIn (decimal amount) {
balance += amount;
}
public bool Withdraw (decimal amount) {
if(balance >= amount){
balance -= amount;
return true;
}
Console.WritLine( "Withdraw attempt failed!~" );
return false;
}
public decimal Balance {
get{ return balance; }
}
public override string ToString (){
return string.Format( "Jupter Bank Gold : Balance = {0,6:C}",balance );
}
}
}
csc Main.cs GoldAccount.cs SaverAccount.cs IBankAccount.cs /main:Wrox.ProCSharp.MainEntryPoint
c:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe /out:..\WaveTang.dll /t:library /res:TreeView3Status.resources AssemblyInfo.cs automenu.cs Sizer.cs MenuToolBar.cs Watcher.cs IconDir.cs Code128.cs EAN13.cs BigNumber.cs ImagePcx.cs ChessBoard.cs TreeView3Status.cs QueueStream.cs TcpService.cs