ReceiptPrinter.java
上传用户:ljt780218
上传日期:2022-07-30
资源大小:110k
文件大小:3k
源码类别:

金融证券系统

开发平台:

Java

  1. // <html><head><title>ATM Simulation Implementation - the Receipt Printer</title></head><body><h2>ATM Simulation Implementation - the Receipt Printer</h2><pre>
  2. /*
  3.  * Example ATM simulation - file ReceiptPrinter.java
  4.  *
  5.  * This file implements the class that manages the ATM's receipt printer
  6.  *
  7.  * Copyright (c) 1997 - Russell C. Bjork
  8.  *
  9.  */
  10. package atm.atmparts;
  11. import java.awt.*;
  12. import java.util.Date;
  13. import atm.util.Money;
  14. //</pre><hr><h3>Class ReceiptPrinter</h3><pre>
  15. public class ReceiptPrinter extends TextArea
  16.   {     
  17.     //</pre><hr><pre>
  18.     public ReceiptPrinter()
  19.       {        
  20.         super(GUILayout.PRINTABLE_LINES, GUILayout.PRINTABLE_CHARS);
  21.         setBackground(Color.white);
  22.         setForeground(Color.black);
  23.         setFont(new Font("Courier", Font.PLAIN, 12));
  24.         setEditable(false);
  25.       }
  26.       
  27.     //</pre><hr><pre>
  28.     public void printReceipt(int theATMnumber,
  29.                              String theATMlocation,
  30.                              int cardNumber,
  31.                              int serialNumber,
  32.                              String description,
  33.                              Money amount,
  34.                              Money balance,
  35.                              Money availableBalance)
  36.       { setText("");
  37.         // Set up the receipt
  38.         
  39.         String lines[] = new String[7];
  40.         int i = 0;
  41.         lines[i ++] = new Date().toString() + "n";
  42.         lines[i ++] = theATMnumber + " " + theATMlocation + "n";
  43.         lines[i ++] = "CARD " + cardNumber + " TRANS " + serialNumber + "n";
  44.         lines[i ++] = description + "n";
  45.         if (amount.equals(new Money(0)))
  46.             lines[i ++] = "n";
  47.         else
  48.             lines[i ++] = "AMOUNT:    " + amount.dollars() + "." +
  49.                 ((amount.cents() >= 10) ? "" + amount.cents() 
  50.                                         : "0" + amount.cents()) + "n";
  51.         lines[i ++] = "CURR BAL:  " + balance.dollars() + "." +
  52.            ((balance.cents() >= 10) ? "" + balance.cents() 
  53.                                     : "0" + balance.cents()) + "n";
  54.         lines[i ++] = "AVAILABLE: " + availableBalance.dollars() + "." +
  55.                 ((availableBalance.cents() >= 10) ? "" + availableBalance.cents() 
  56.                                             : "0" + availableBalance.cents()) + "n";
  57.     
  58.         // Animate it
  59.     
  60.         for (i = 0; i < 7; i ++)
  61.           { appendText(lines[i]);
  62.             try
  63.               { Thread.sleep(1 * 1000); }
  64.             catch (InterruptedException e)
  65.               { }
  66.           }    
  67.       }
  68.   }
  69. //</pre></body></html>