2017-11-19 13 views
-1

は、私は下の3つのクラスを持っていますが、何らかの理由で私は、取引の種類と量、私も出力できません取引履歴program.csの文字列に完全な情報をどのように表示できますか?

CurrentAccountのC1 =新CurrentAccount(「234555」、1000年、234、TransactionType.Depositを表示することができません); //太字の部分は表示されません

以下の出力を参照してください。 234545口座番号100 overdraft。 System.Collections.ArrayListトランザクション履歴。

トランザクション履歴を正しく表示するためにクラスを修正するにはどうすればよいですか? 234555口座番号1000年overdraft.System.Collections.ArrayListトランザクション履歴:

フルクラスの下のコンソールから

abstract class BankAccount 
{ 
    protected string AccountNumber { get; } // read property 
    protected double Balance { get; set; } //read and write property 

    public BankAccount(string _accountNumber) 
    { 
     this.AccountNumber = _accountNumber; 
     this.Balance = 0; 
    } 

    public virtual void MakeDeposit(double amount) 
    { 
     Balance = Balance + amount; 
    } 
    public virtual void MakeWithdraw(double amount) 
    { 
     Balance = Balance - amount; 
    } 

    } 
} 


class CurrentAccount : BankAccount 
{ 
    private double OverdraftLimit { get; } // read only property  

    public ArrayList TransactionHistory = new ArrayList(); 

    public CurrentAccount(string AccountNumber, double OverdraftLimit, double amount, TransactionType type) : base(AccountNumber) 
    { 
     this.OverdraftLimit = OverdraftLimit; 

     TransactionHistory.Add(new AccountTransaction(type, amount));   
    } 

    public override void MakeDeposit(double amount) // override method 
    { 
     Balance += amount; 
     TransactionHistory.Add(new AccountTransaction(TransactionType.Deposit, amount)); 
    } 
    public override void MakeWithdraw(double amount) 
    {    
     if (Balance + OverdraftLimit > 0) 
     { 
      Balance -= amount; 
      TransactionHistory.Add(new AccountTransaction(TransactionType.Withdrawal, amount)); 
     } 

     else 
     { 
      throw new Exception("Insufficient Funds"); 
     } 
    } 
    public override string ToString() 
    { 
     // print the transaction history too 
     return AccountNumber + " account number " + OverdraftLimit + " overdraft." + TransactionHistory + " Transaction history."; 
    } 
} 
} 

{ 
enum TransactionType 
{ 
    Deposit, Withdrawal 
} 


class AccountTransaction 
{ 
    public TransactionType type { get; private set; }  // deposit/withdrawal 
    private double Amount { get; set; } 

    public AccountTransaction (TransactionType type, double _amount) 
    { 
     this.type = type; 
     this.Amount = _amount; 
    } 



    public override string ToString() 
    { 
     return "type" + type + "amount" + Amount; 
    } 

} 
} 

class Program 
{ 
    static void Main(string[] args) 
    { 
     CurrentAccount c1 = new CurrentAccount("234555",1000, 234, **TransactionType.Deposit)**; // this part is not displayed 
     CurrentAccount c2 = new CurrentAccount("234534", 12000, 345, **TransactionType.Withdrawal)**; // this part is not displayed 
     CurrentAccount c3 = new CurrentAccount("234545", 100, 456, **TransactionType.Withdrawal)**; // this part is not displayed 
     Console.WriteLine(c1); 
     Console.WriteLine(c2); 
     Console.WriteLine(c3); 

    } 
} 
} 

出力を参照してくださいしてください。 234534アカウント番号12000 overdraft.System.Collections.ArrayListトランザクション履歴。 234545アカウント番号100 overdraft.System.Collections.ArrayListトランザクション履歴。

正しい情報を出力するのを手伝ってください。

+2

[質問]をよく読んで、コードを正しくフォーマットしてください。 –

答えて

0

私はなぜこれが起こっているのか分からないのですが、文字列メソッドのオーバーライドがあるためです。私は唯一のことは、あなたが銀行から継承しているので、銀行クラスのtostringメソッドをオーバーライドする必要があることです。試してみてください。

関連する問題