private void processSell(Value value) { Integer shares = (int) Math.floor(sellAmount / value.getCurrent()); if (endShares < shares) { throw new FinanceException("NotEnoughShares"); } endShares -= shares; endMoney += shares * value.getCurrent(); }
private void processBuy(Value value) { if (endMoney < buyAmount) { throw new FinanceException("NotEnoughMoney"); } Integer shares = (int) Math.floor(buyAmount / value.getCurrent()); endShares += shares; endMoney -= shares * value.getCurrent(); }