M.4. Class Keypad

Class Keypad (Fig. M.3) represents the keypad of the ATM and is responsible for receiving all user input. Recall that we are simulating this hardware, so we use the computer’s keyboard to approximate the keypad. We use class Scanner to obtain console input from the user. A computer keyboard contains many keys not found on the ATM’s keypad. However, we assume that the user presses only the keys on the computer keyboard that also appear on the keypad—the keys numbered 0–9 and the Enter key.

Figure M.3. Class Keypad represents the ATM’s keypad.
 1  // Keypad.java
 2  // Represents the keypad of the ATM
 3  import java.util.Scanner; // program uses Scanner to obtain user input
 4
 5  public class Keypad
 6  {
 7      private Scanner input; // ...

Get Java™ How to Program, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.