📄 changeloccommand.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -