Example #1
0
  public static void main(String[] args) {
    try {
      Context ctx = new InitialContext();
      Object objref = ctx.lookup(JNDI_NAME);

      SavingsAccountHome home =
          (SavingsAccountHome) PortableRemoteObject.narrow(objref, SavingsAccountHome.class);

      BigDecimal zeroAmount = new BigDecimal("0.00");
      SavingsAccount John = home.create("100", "John", "Smith", zeroAmount);

      System.out.println("Account Name: " + John.getFirstName());
      System.out.println("Credit: 88.50");

      John.credit(new BigDecimal("88.50"));
      System.out.println("Debit: 20.25");

      John.debit(new BigDecimal("20.25"));
      BigDecimal balance = John.getBalance();
      System.out.println("Balance = " + balance);
      // John.remove();
      System.exit(0);
    } catch (InsufficientBalanceException ex) {
      System.err.println("Caught an InsufficientBalanceException: " + ex.getMessage());
    } catch (Exception ex) {
      System.err.println("Caught an exception.");
      ex.printStackTrace();
    }
  }