2017-11-19 7 views
-1

는 I는 다음의 3 개 가지 종류가 있지만, 어떤 이유로 I 트랜잭션의 유형 및 양, I도 출력 할 수 없다 거래 내역program.cs에서 문자열에 전체 정보를 어떻게 표시 할 수 있습니까?

CurrentAccount의 C1 = 새로운 CurrentAccount ("234555"(1000) 234, TransactionType.Deposit을 표시 할 수없는); // 굵게 표시된 부분은 표시되지 않습니다.

아래 출력을 참조하십시오. 234545 계좌 번호 100 초과 인출. 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

[ask]를 읽고 코드의 형식을 올바르게 지정하십시오. –

답변

0

이유가 무엇인지 모르겠지만 문자열 메서드 재정의가 있습니다. 유일한 방법은 은행 계좌를 tostring 메서드로 재정의해야한다는 것입니다. 왜냐하면 은행에서 상속하기 때문입니다. 시도해보고 이것이 작동하는지 알려주세요.