Section J.10. Class BalanceInquiry


J.10. Class BalanceInquiry

Class BalanceInquiry (Fig. J.9) inherits from transaction (line 4) and represents an ATM balance inquiry transaction. BalanceInquiry does not have any attributes of its own, but it inherits transaction attributes accountNumber, screen and bankDatabase, which are accessible through transaction's Public ReadOnly properties. The BalanceInquiry constructor (lines 710) takes arguments corresponding to these attributes and simply forwards them to transaction's constructor using MyBase.New (line 9).

Figure J.9. Class BalanceInquiry represents a balance inquiry ATM transaction.

  1  ' BalanceInquiry.vb  2  ' Represents a balance inquiry ATM transaction  3  Public Class BalanceInquiry  4     Inherits Transaction  5  6     ' BalanceInquiry constructor initializes base class variables  7     Public Sub New(ByVal userAccountNumber As Integer, _  8        ByVal atmScreen As Screen, ByVal atmBankDatabase As BankDatabase)  9        MyBase . New(userAccountNumber, atmScreen, atmBankDatabase) 10     End Sub ' New 11 12     ' performs transaction; overrides Transaction's MustOverride method 13     Public Overrides Sub Execute() 14        ' get the available balance for the current user's Account 15        Dim availableBalance As Decimal = _ 16           BankDatabaseReference.GetAvailableBalance(AccountNumber) 17 18        ' get the total balance for the current user's Account 19        Dim totalBalance As Decimal = _ 20           BankDatabaseReference.GetTotalBalance(AccountNumber) 21 22        ' display the balance information on the screen 23        ScreenReference.DisplayMessageLine(vbCrLf & "Balance Information:") 24        ScreenReference.DisplayMessage(" - Available balance: ") 25        ScreenReference.DisplayDollarAmount(availableBalance) 26        ScreenReference.DisplayMessage(vbCrLf & " - Total balance: ") 27        ScreenReference.DisplayDollarAmount(totalBalance) 28        ScreenReference.DisplayMessageLine("") 29     End Sub ' Execute 30  End Class ' BalanceInquiry 

Class BalanceInquiry overrides TRansaction's MustOverride method Execute to provide a concrete implementation (lines 1329) that performs the steps involved in a balance inquiry. Lines 1516 obtain the specified Account's available balance by invoking the inherited property BankDatabaseReference's GetAvailableBalance method. Note that line 16 uses the inherited property AccountNumber is used to get the account number of the current user. Lines 1924 retrieve the specified Account's total balance. Lines 2328 display the balance information on the ATM's screen using the inherited property ScreenReference. Recall that DisplayDollarAmount takes a Decimal argument and outputs it to the screen formatted as a dollar amount. For example, if a user's available balance is 1000.5, line 25 outputs $1,000.50. Note that line 28 inserts a blank line of output to separate the balance information from subsequent output (i.e., the main menu repeated by class ATM after executing the BalanceInquiry).



Visual BasicR 2005 for Programmers. DeitelR Developer Series
Visual Basic 2005 for Programmers (2nd Edition)
ISBN: 013225140X
EAN: 2147483647
Year: 2004
Pages: 435

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net