public void transferMoney(Long sourceAccountId, Long targetAccountId, BigDecimal amount) { Account source = accountDAO.getById(sourceAccountId); Account target = accountDAO.getById(targetAccountId); if (source.getBalance().compareTo(amount) < 0) { throw new NotEnoughMoneyException(); } source.decrementBalance(amount); target.incrementBalance(amount); auditDAO.insertTransaction(sourceAccountId, targetAccountId, amount); // other business logic }
int totalBalance = 0; for(Account account: accounts){ if (account instanceof Saving) { totalBalance = totalBalance + account.getBalance(); } }
public class AccountServiceImpl implements AccountService { private SessionFactory sessionFactory; public BigDecimal getBalance(Integer acountId) { // You need to know your balance // So you need to use get method to access the database Account account = (Account) sessionFactory.getCurrentSession().get(Account.class, accountId); return account.getBalance(); } }
@Override @Loggable(value = LogLevel.TRACE) @Transactional public void updateBalance(String id, BigDecimal amount) { Account acc = (Account) sessionFactory.getCurrentSession().get(Account.class, id, LockMode.UPGRADE); acc.setBalance(acc.getBalance().subtract(amount)); save(acc); }
Account temp = findAccount(accountID, 0, size, lastPos); if (temp!= null) { temp.setBalance(temp.getBalance() + adjustment); //updates temp currentBalance } else { System.out.println("No account found. "); }
Account account = (Account) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {Account.class, Serializable.class}, new ExampleInvocationHandler()); // method chaining for the win! account.deposit(5000).deposit(4000).deposit(-2500); System.out.println("Balance: " + account.getBalance());
public class TestProgram { public static void main(String[] args) throws FileNotFoundException { Date date= new Date(); Account account1 = new Account(5648, 27000, date); account1.withdraw(7500); account1.deposit(11000); System.out.println("Your current balance is" +account1.getBalance()); System.out.println("Monthly interest is"+ account1.getAnnualInterestRate()); System.out.println("The account was created on" + account1.getDateCreated()); } }
public class AvailableCreditListener { @PostLoad @PostPersist @PostUpdate public void calculateAvailableCredit(Account account) { account.setAvailableCredit( account.getBalance().add( account.getOverdraftLimit())); } }
public org.hl7.fhir.instance.model.Account convertAccount(org.hl7.fhir.dstu3.model.Account src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.instance.model.Account tgt = new org.hl7.fhir.instance.model.Account(); copyDomainResource(src, tgt); for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t)); tgt.setName(src.getName()); tgt.setType(convertCodeableConcept(src.getType())); tgt.setStatus(convertAccountStatus(src.getStatus())); tgt.setActivePeriod(convertPeriod(src.getActive())); tgt.setBalance(convertMoney(src.getBalance())); // tgt.setCoveragePeriod(convertPeriod(src.getCoveragePeriod())); tgt.setSubject(convertReference(src.getSubject())); tgt.setOwner(convertReference(src.getOwner())); tgt.setDescription(src.getDescription()); return tgt; }
counter ++; System.out.println("Account details for Account '"+counter+"' :\n"); System.out.println("Account Number : "+ acc.getAccNo() +" Balance :" + acc.getBalance() );
double wAmount = new Double(jtfWithdraw.getText().trim()).doubleValue(); double tAmount = new Double(jtfTransfer.getText().trim()).doubleValue(); double cAmount = cAcc.getBalance(); double sAmount = sAcc.getBalance();
@Override public Base makeProperty(int hash, String name) throws FHIRException { switch (hash) { case -1618432855: return addIdentifier(); case -892481550: return getStatusElement(); case 3575610: return getType(); case 3373707: return getNameElement(); case -1867885268: return getSubject(); case -991726143: return getPeriod(); case -1422950650: return getActive(); case -339185956: return getBalance(); case -351767064: return addCoverage(); case 106164915: return getOwner(); case -1724546052: return getDescriptionElement(); case -188629045: return addGuarantor(); default: return super.makeProperty(hash, name); } }
public org.hl7.fhir.instance.model.Account convertAccount(org.hl7.fhir.dstu3.model.Account src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.instance.model.Account tgt = new org.hl7.fhir.instance.model.Account(); copyDomainResource(src, tgt); for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t)); tgt.setName(src.getName()); tgt.setType(convertCodeableConcept(src.getType())); tgt.setStatus(convertAccountStatus(src.getStatus())); tgt.setActivePeriod(convertPeriod(src.getActive())); tgt.setBalance(convertMoney(src.getBalance())); // tgt.setCoveragePeriod(convertPeriod(src.getCoveragePeriod())); tgt.setSubject(convertReference(src.getSubject())); tgt.setOwner(convertReference(src.getOwner())); tgt.setDescription(src.getDescription()); return tgt; }