1 17 18 package org.objectweb.jac.samples.hibernate; 19 20 40 public class Account { 41 42 private String id; 43 private String name; 44 private double balance; 45 46 public static void main(String [] args) throws Exception { 47 48 Account bob = new Account(); 49 Account robert = new Account(); 50 51 bob.setName("Bob"); 52 robert.setName("Robert"); 53 54 double initial = (int) (Math.random()*100) * 2; 55 56 System.out.println("Set balance Bob: "+initial); 57 bob.setBalance(initial); 58 System.out.println(bob); 59 System.out.println(robert); 60 System.out.println(); 61 62 System.out.println("Transfert from Bob to Robert: "+initial/2); 63 transfert(bob,robert,initial/2); 64 System.out.println(); 65 66 System.out.println("Transfert from Bob to Robert: "+initial*2); 67 transfert(bob,robert,initial*2); 68 System.out.println(); 69 70 System.exit(1); 71 } 72 73 public void setId(String id){ this.id = id; } 74 public String getId() { return id; } 75 76 public void setName(String name){ this.name = name; } 77 public String getName() { return name; } 78 79 public void setBalance(double balance) { this.balance = balance; } 80 public double getBalance() { return balance; } 81 82 public void credit( double amount ) { 83 String name = getName(); 84 double balance = getBalance(); 85 86 System.out.print(name+": "+balance+" -> "); 87 balance += amount; 88 System.out.println(balance); 89 90 setBalance(balance); 91 } 92 93 public void withdraw( double amount ) { 94 String name = getName(); 95 double balance = getBalance(); 96 97 System.out.print(name+": "+balance+" -> "); 98 balance -= amount; 99 System.out.println(balance); 100 101 setBalance(balance); 102 } 103 104 public static void transfert( Account from, Account to, double amount ) { 105 to.credit(amount); 106 from.withdraw(amount); 107 } 108 109 public String toString() { 110 return "Account: "+getName()+", balance: "+getBalance(); 111 } 112 } 113 | Popular Tags |