⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transaction.java

📁 模拟了atm机的基本功能
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   Transaction.java

package atm.transaction;

import atm.ATM;
import atm.Session;
import atm.physical.*;
import banking.*;

// Referenced classes of package atm.transaction:
//            Deposit, Inquiry, Transfer, Withdrawal

public abstract class Transaction
{
    public static class CardRetained extends Exception
    {

        public CardRetained()
        {
            super("Card retained due to too many invalid PINs");
        }
    }


    protected ATM atm;
    protected Session session;
    protected Card card;
    protected int pin;
    protected int serialNumber;
    protected Message message;
    protected Balances balances;
    private static final String TRANSACTION_TYPES_MENU[] = {
        "Withdrawal", "Deposit", "Transfer", "Balance Inquiry"
    };
    private static int nextSerialNumber = 1;
    private int state;
    private static final int GETTING_SPECIFICS_STATE = 1;
    private static final int SENDING_TO_BANK_STATE = 2;
    private static final int INVALID_PIN_STATE = 3;
    private static final int COMPLETING_TRANSACTION_STATE = 4;
    private static final int PRINTING_RECEIPT_STATE = 5;
    private static final int ASKING_DO_ANOTHER_STATE = 6;

    protected Transaction(ATM atm1, Session session1, Card card1, int i)
    {
        atm = atm1;
        session = session1;
        card = card1;
        pin = i;
        serialNumber = nextSerialNumber++;
        balances = new Balances();
        state = 1;
    }

    public static Transaction makeTransaction(ATM atm1, Session session1, Card card1, int i)
        throws atm.physical.CustomerConsole.Cancelled
    {
        int j = atm1.getCustomerConsole().readMenuChoice("Please choose transaction type", TRANSACTION_TYPES_MENU);
        switch(j)
        {
        case 0: // '\0'
            return new Withdrawal(atm1, session1, card1, i);

        case 1: // '\001'
            return new Deposit(atm1, session1, card1, i);

        case 2: // '\002'
            return new Transfer(atm1, session1, card1, i);

        case 3: // '\003'
            return new Inquiry(atm1, session1, card1, i);
        }
        return null;
    }

    public boolean performTransaction()
        throws CardRetained
    {
        String s = "";
        Object obj = null;
        Receipt receipt = null;
label0:
        do
            switch(state)
            {
            default:
                break;

            case 1: // '\001'
                try
                {
                    message = getSpecificsFromCustomer();
                    atm.getCustomerConsole().display("");
                    state = 2;
                }
                catch(atm.physical.CustomerConsole.Cancelled _ex)
                {
                    s = "Last transaction was cancelled";
                    state = 6;
                }
                break;

            case 6: // '\006'
                break label0;

            case 2: // '\002'
                Status status = atm.getNetworkToBank().sendMessage(message, balances);
                if(status.isInvalidPIN())
                    state = 3;
                else
                if(status.isSuccess())
                {
                    state = 4;
                } else
                {
                    s = status.getMessage();
                    state = 6;
                }
                break;

            case 3: // '\003'
                try
                {
                    Status status1 = performInvalidPINExtension();
                    if(status1.isSuccess())
                    {
                        state = 4;
                    } else
                    {
                        s = status1.getMessage();
                        state = 6;
                    }
                    break;
                }
                catch(atm.physical.CustomerConsole.Cancelled _ex)
                {
                    s = "Last transaction was cancelled";
                }
                state = 6;
                break;

            case 4: // '\004'
                try
                {
                    receipt = completeTransaction();
                    state = 5;
                    break;
                }
                catch(atm.physical.CustomerConsole.Cancelled _ex)
                {
                    s = "Last transaction was cancelled";
                }
                state = 6;
                break;

            case 5: // '\005'
                atm.getReceiptPrinter().printReceipt(receipt);
                state = 6;
                break;
            }
        while(true);
        if(s.length() > 0)
            s = s + "\n";
        try
        {
            String as[] = {
                "Yes", "No"
            };
            boolean flag = atm.getCustomerConsole().readMenuChoice(s + "Would you like to do another transaction?", as) == 0;
            return flag;
        }
        catch(atm.physical.CustomerConsole.Cancelled _ex)
        {
            return false;
        }
    }

    public Status performInvalidPINExtension()
        throws atm.physical.CustomerConsole.Cancelled, CardRetained
    {
        Object obj = null;
        for(int i = 0; i < 3; i++)
        {
            pin = atm.getCustomerConsole().readPIN("PIN was incorrect\nPlease re-enter your PIN\nThen press ENTER");
            atm.getCustomerConsole().display("");
            message.setPIN(pin);
            Status status = atm.getNetworkToBank().sendMessage(message, balances);
            if(!status.isInvalidPIN())
            {
                session.setPIN(pin);
                return status;
            }
        }

        atm.getCardReader().retainCard();
        atm.getCustomerConsole().display("Your card has been retained\nPlease contact the bank.");
        try
        {
            Thread.sleep(5000L);
        }
        catch(InterruptedException _ex) { }
        atm.getCustomerConsole().display("");
        throw new CardRetained();
    }

    public int getSerialNumber()
    {
        return serialNumber;
    }

    protected abstract Message getSpecificsFromCustomer()
        throws atm.physical.CustomerConsole.Cancelled;

    protected abstract Receipt completeTransaction()
        throws atm.physical.CustomerConsole.Cancelled;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -