J.10. Class BalanceInquiry

Class BalanceInquiry (Fig. J.9) inherits from TRansaction and represents an ATM balance inquiry transaction (line 3). 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 read-only properties. The BalanceInquiry constructor (lines 68) takes arguments corresponding to these attributes and forwards them to TRansaction's constructor by invoking the constructor initializer with keyword base (line 8). The body of the constructor is empty.

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

 1 // BalanceInquiry.cs
 2 // Represents a balance inquiry ATM transaction
 3 public class BalanceInquiry : Transaction
 4 {
 5 // five-parameter constructor initializes base class variables
 6 public BalanceInquiry( int userAccountNumber,
 7 Screen atmScreen, BankDatabase atmBankDatabase )
 8 : base( userAccountNumber, atmScreen, atmBankDatabase ) {}
 9
10 // performs transaction; overrides Transaction's abstract method
11 public override void Execute()
12 {
13 // get the available balance for the current user's Account
14 decimal availableBalance =
15 Database.GetAvailableBalance( AccountNumber );
16
17 // get the total balance for the current user's Account
18 decimal totalBalance = Database.GetTotalBalance( AccountNumber );
19
20 // display the balance information on the screen
21 UserScreen.DisplayMessageLine( "
Balance Information:" );
22 UserScreen.DisplayMessage( " - Available balance: " );
23 UserScreen.DisplayDollarAmount( availableBalance );
24 UserScreen.DisplayMessage( "
 - Total balance: " );
25 UserScreen.DisplayDollarAmount( totalBalance ); 26 UserScreen.DisplayMessageLine( "" ); 27 } // end method Execute 28 } // end class BalanceInquiry

Class BalanceInquiry overrides transaction's abstract method Execute to provide a concrete implementation (lines 1127) that performs the steps involved in a balance inquiry. Lines 1415 obtain the specified Account's available balance by invoking the GetAvailableBalance method of the inherited property Database. Note that line 15 uses the inherited property AccountNumber to get the account number of the current user. Line 18 retrieves the specified Account's total balance. Lines 2126 display the balance information on the ATM's screen using the inherited property UserScreen. Recall that DisplayDollarAmount takes a decimal argument and outputs it to the screen formatted as a dollar amount with a dollar sign. For example, if a user's available balance is 1000.50M, line 23 outputs $1,000.50. Note that line 26 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).

Preface

Index

    Introduction to Computers, the Internet and Visual C#

    Introduction to the Visual C# 2005 Express Edition IDE

    Introduction to C# Applications

    Introduction to Classes and Objects

    Control Statements: Part 1

    Control Statements: Part 2

    Methods: A Deeper Look

    Arrays

    Classes and Objects: A Deeper Look

    Object-Oriented Programming: Inheritance

    Polymorphism, Interfaces & Operator Overloading

    Exception Handling

    Graphical User Interface Concepts: Part 1

    Graphical User Interface Concepts: Part 2

    Multithreading

    Strings, Characters and Regular Expressions

    Graphics and Multimedia

    Files and Streams

    Extensible Markup Language (XML)

    Database, SQL and ADO.NET

    ASP.NET 2.0, Web Forms and Web Controls

    Web Services

    Networking: Streams-Based Sockets and Datagrams

    Searching and Sorting

    Data Structures

    Generics

    Collections

    Appendix A. Operator Precedence Chart

    Appendix B. Number Systems

    Appendix C. Using the Visual Studio 2005 Debugger

    Appendix D. ASCII Character Set

    Appendix E. Unicode®

    Appendix F. Introduction to XHTML: Part 1

    Appendix G. Introduction to XHTML: Part 2

    Appendix H. HTML/XHTML Special Characters

    Appendix I. HTML/XHTML Colors

    Appendix J. ATM Case Study Code

    Appendix K. UML 2: Additional Diagram Types

    Appendix L. Simple Types

    Index



    Visual C# How to Program
    Visual C# 2005 How to Program (2nd Edition)
    ISBN: 0131525239
    EAN: 2147483647
    Year: 2004
    Pages: 600

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