📄 depositcommand.java
字号:
package Commands;
import Interfaces.*;
import Sets.*;
import SystemEntities.*;
import Accounts.*;
import dslib.exception.ItemNotFoundUosException;
/** Command to carry out a deposit. The command can only be applied
to regular accounts. */
public class DepositCommand extends Command
{
/** The interface that is to be used by this command. */
StaffInterface cmdInterface;
/** The command's constructor. */
public DepositCommand(StaffInterface userInterface)
{
cmdInterface = userInterface;
}
/** Execute the command. */
public void execute()
{
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 RegularAccount)
{
RegularAccount acct = (RegularAccount) accountAccessed;
amount = cmdInterface.getAmount();
date = Clock.date();
acct.deposit(amount);
acct.logTrans(date, "deposit", amount, 0.0f);
Printer.printDeposit(acct.number(), amount, date);
}
else
cmdInterface.sendMessage("\n*****Illegal deposit: "
+ "Cannot deposit in a non-regular account."
+ "\n The account with number " + accountAccessed.number()
+ " is a " + accountAccessed.getClass().getName() + ".");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -