1 27 28 package savingsaccountclient; 29 30 import bank.SavingsAccountRemote; 31 import bank.SavingsAccountRemoteHome; 32 import java.math.BigDecimal ; 33 import java.util.Collection ; 34 import java.util.Iterator ; 35 import javax.naming.Context ; 36 import javax.naming.InitialContext ; 37 import javax.rmi.PortableRemoteObject ; 38 39 43 public class Main { 44 45 46 public Main() { 47 } 48 49 52 public static void main(String [] args) { 53 try{ 55 Context initial = new InitialContext (); 56 Object objref = 57 initial.lookup("ejb/SavingsAccountBean"); 58 59 SavingsAccountRemoteHome home = 60 (SavingsAccountRemoteHome) PortableRemoteObject.narrow(objref, 61 SavingsAccountRemoteHome.class); 62 63 BigDecimal zeroAmount = new BigDecimal ("0.00"); 64 SavingsAccountRemote duke = 65 home.create("123", "Duke", "Earl", zeroAmount); 66 67 duke.credit(new BigDecimal ("88.50")); 68 duke.debit(new BigDecimal ("20.25")); 69 70 BigDecimal balance = duke.getBalance(); 71 System.out.println("balance = " + balance); 72 duke.remove(); 73 74 SavingsAccountRemote joe = home.create("836", "Joe", "Jones", zeroAmount); 75 76 joe.credit(new BigDecimal ("34.55")); 77 78 SavingsAccountRemote jones = home.findByPrimaryKey("836"); 79 80 jones.debit(new BigDecimal ("2.00")); 81 balance = jones.getBalance(); 82 System.out.println("balance = " + balance); 83 84 SavingsAccountRemote pat = home.create("456", "Pat", "Smith", zeroAmount); 85 86 pat.credit(new BigDecimal ("44.77")); 87 88 SavingsAccountRemote john = 89 home.create("730", "John", "Smith", zeroAmount); 90 91 john.credit(new BigDecimal ("19.54")); 92 93 SavingsAccountRemote mary = 94 home.create("268", "Mary", "Smith", zeroAmount); 95 96 mary.credit(new BigDecimal ("100.07")); 97 98 Collection c = home.findByLastName("Smith"); 99 Iterator i = c.iterator(); 100 101 while (i.hasNext()) { 102 SavingsAccountRemote account = (SavingsAccountRemote) i.next(); 103 String id = (String ) account.getPrimaryKey(); 104 BigDecimal amount = account.getBalance(); 105 106 System.out.println(id + ": " + amount); 107 } 108 109 c = home.findInRange(new BigDecimal ("20.00"), 110 new BigDecimal ("99.00")); 111 i = c.iterator(); 112 113 while (i.hasNext()) { 114 SavingsAccountRemote account = (SavingsAccountRemote) i.next(); 115 String id = (String ) account.getPrimaryKey(); 116 BigDecimal amount = account.getBalance(); 117 System.out.println(id + ": " + amount); 118 } 119 120 SavingsAccountRemote pete = 121 home.create("904", "Pete", "Carlson", new BigDecimal ("5.00")); 122 SavingsAccountRemote sally = 123 home.create("905", "Sally", "Fortney", new BigDecimal ("8.00")); 124 125 home.ChargeForLowBalance(new BigDecimal ("10.00"), 126 new BigDecimal ("1.00")); 127 128 BigDecimal reducedAmount = pete.getBalance(); 129 130 System.out.println(reducedAmount); 131 reducedAmount = sally.getBalance(); 132 System.out.println(reducedAmount); 133 134 System.exit(0); 135 136 }catch(Exception ex){ 137 System.err.println("Exception is caught: " + ex.getMessage()); 138 ex.printStackTrace(); 139 } 140 } 141 142 } 143 | Popular Tags |