changeloccommand.java

来自「国外的数据结构与算法分析用书」· Java 代码 · 共 58 行

JAVA
58
字号
package Commands;

import Interfaces.*;
import Sets.*;
import SystemEntities.*;
import Accounts.*;
import dslib.exception.ItemNotFoundUosException;

/**	Command to change the line of credit for an account.
	The command can only be applied to checking accounts. */
public class ChangeLocCommand extends Command
{
	/**	The interface that is to be used for this command. */
	protected AdminInterface cmdInterface;
	
	/**	The command's constructor. */
	public ChangeLocCommand(StaffInterface userInterface)
	{
		if (userInterface instanceof AdminInterface)
			cmdInterface = (AdminInterface) userInterface;
		else
			userInterface.sendMessage("You are not allowed to change a customer's line of credit.");
	}

	/**	Execute the change line-of-credit command. */
	public void execute()
	{
		if (cmdInterface != null)
		{
			int acctID = cmdInterface.getAcctID();
			Account accountAccessed = null;
			try
			{
				accountAccessed =  (Account) AccountSetAccess.dictionary().obtain(new Integer(acctID));
			} catch (ItemNotFoundUosException e) 
			{
				cmdInterface.sendMessage("Account number " + acctID + " was not found.");
				return;
			}
			if (accountAccessed instanceof CheckingAccount)
			{
				CheckingAccount acct = (CheckingAccount) accountAccessed;
				amount = cmdInterface.getNewLoc();
				date = Clock.date();
				acct.setLoc(amount);
				acct.logTrans(date, "change line of credit to $", 0.0f, amount);
				Printer.printChangeLoc(acct.number(), acct.lineOfCredit(), date);
			}
			else
			{
				cmdInterface.sendMessage("\n*****Illegal change of line of credit.  "
						+ "Account must be checking.  \n     The account with number " 
						+ accountAccessed.number() + " is a " + accountAccessed.getClass().getName() + ".");
			}
		}
	}
}

⌨️ 快捷键说明

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