ReceiptPrinter.java
资源名称:ATM.zip [点击查看]
上传用户:ljt780218
上传日期:2022-07-30
资源大小:110k
文件大小:3k
源码类别:
金融证券系统
开发平台:
Java
- // <html><head><title>ATM Simulation Implementation - the Receipt Printer</title></head><body><h2>ATM Simulation Implementation - the Receipt Printer</h2><pre>
- /*
- * Example ATM simulation - file ReceiptPrinter.java
- *
- * This file implements the class that manages the ATM's receipt printer
- *
- * Copyright (c) 1997 - Russell C. Bjork
- *
- */
- package atm.atmparts;
- import java.awt.*;
- import java.util.Date;
- import atm.util.Money;
- //</pre><hr><h3>Class ReceiptPrinter</h3><pre>
- public class ReceiptPrinter extends TextArea
- {
- //</pre><hr><pre>
- public ReceiptPrinter()
- {
- super(GUILayout.PRINTABLE_LINES, GUILayout.PRINTABLE_CHARS);
- setBackground(Color.white);
- setForeground(Color.black);
- setFont(new Font("Courier", Font.PLAIN, 12));
- setEditable(false);
- }
- //</pre><hr><pre>
- public void printReceipt(int theATMnumber,
- String theATMlocation,
- int cardNumber,
- int serialNumber,
- String description,
- Money amount,
- Money balance,
- Money availableBalance)
- { setText("");
- // Set up the receipt
- String lines[] = new String[7];
- int i = 0;
- lines[i ++] = new Date().toString() + "n";
- lines[i ++] = theATMnumber + " " + theATMlocation + "n";
- lines[i ++] = "CARD " + cardNumber + " TRANS " + serialNumber + "n";
- lines[i ++] = description + "n";
- if (amount.equals(new Money(0)))
- lines[i ++] = "n";
- else
- lines[i ++] = "AMOUNT: " + amount.dollars() + "." +
- ((amount.cents() >= 10) ? "" + amount.cents()
- : "0" + amount.cents()) + "n";
- lines[i ++] = "CURR BAL: " + balance.dollars() + "." +
- ((balance.cents() >= 10) ? "" + balance.cents()
- : "0" + balance.cents()) + "n";
- lines[i ++] = "AVAILABLE: " + availableBalance.dollars() + "." +
- ((availableBalance.cents() >= 10) ? "" + availableBalance.cents()
- : "0" + availableBalance.cents()) + "n";
- // Animate it
- for (i = 0; i < 7; i ++)
- { appendText(lines[i]);
- try
- { Thread.sleep(1 * 1000); }
- catch (InterruptedException e)
- { }
- }
- }
- }
- //</pre></body></html>