Section J.3. Class Screen


J.3. Class Screen

Class Screen (Fig. J.2) represents the screen of the ATM and encapsulates all aspects of displaying output to the user. Class Screen simulates a real ATM's screen with the computer monitor and outputs text messages using standard console output methods Console.Write and Console.WriteLine. In the design portion of this case study, we endowed class Screen with one operationDisplayMessage. For greater flexibility in displaying messages to the Screen, we now declare three Screen methodsDisplayMessage, DisplayMessageLine and DisplayDollarAmount.

Method DisplayMessage (lines 57) takes a String as an argument and prints it to the screen using Console.Write. The cursor stays on the same line, making this method appropriate for displaying prompts to the user. Method DisplayMessageLine (lines 1012) does the same using Console.WriteLine, which outputs a newline to move the cursor to the next line. Finally, method DisplayDollarAmount (lines 1517) outputs a properly formatted dollar amount (e.g., $1,234.56). Line 16 uses method Console.Write to output a Decimal value formatted as currency with two decimal places and commas to increase the readability of large dollar amounts.




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