我有以下枚举类:public enum banknote{
FIVE_JOD(new BigDecimal("5.0")),
TEN_JOD(new BigDecimal("10.0")),
TWENTY_JOD(new BigDecimal("20.0")),
FIFTY_JOD(new BigDecimal("50.0"));
private final BigDecimal value;
//constructor
Banknote(BigDecimal value) {
this.value = value;
}
public BigDecimal getValue() {
return value;
}
}
如何在此atm类方法中返回钞票列表:
公共类atm\u实现实现atm{
@Override
public List<Banknote> withdraw(String accountNumber, BigDecimal amount) {
int accountNumberIntegerInput = Integer.parseInt(accountNumber);
System.out.println("Enter amount ");
BankingSystemImplementation object = new BankingSystemImplementation();
BigDecimal balanceInSystem = object.getAccountBalance(accountNumber);
int equals = balanceInSystem.compareTo(amount); //compare between two bigDecimal objects
if ((equals == 0 || equals == 1)) {
object.debitAccount(accountNumber, amount); //subtact two bigdacimal objects
}
else if (equals==-1){
throw new InsufficientFundsException();
}
return null;
}
1条答案
按热度按时间tyu7yeag1#
你应该把取款金额分成钞票(如果我理解你的问题的话)。它幼稚的实现。
例如:金额=100;结果:[五十个工作日,五十个工作日]
例:金额=87;结果:[五十工,二十工,十工,五工,一工,一工]
实现(元代码):