1 15 16 package org.objectweb.jac.samples.bank; 17 18 import org.objectweb.jac.samples.contacts.Person; 19 20 30 31 public class Account { 32 33 34 protected double allowedDeficit = 0; 35 36 37 protected double balance; 38 39 40 protected long accountNumber; 41 42 Bank bank=null; 43 44 public void setBank(Bank bank) { 45 this.bank=bank; 46 } 47 48 49 Person owner; 50 51 public Person getOwner() { 52 return owner; 53 } 54 55 public void setOwner(Person owner) { 56 this.owner=owner; 57 if( bank != null ) { 58 bank.addUser(owner); 59 } 60 } 61 62 public void setAllowedDeficit(double allowedDeficit) { 63 this.allowedDeficit = allowedDeficit; 64 } 65 66 public double getAllowedDeficit() { 67 return allowedDeficit; 68 } 69 70 76 77 public Account(long accountNumber){ 78 this.accountNumber = accountNumber; 79 balance = 0; 80 } 81 82 86 87 public String toString() { 88 return accountNumber+" ("+balance+")"; 89 } 90 91 96 97 public void credit(double amount) { 98 if( balance + amount > allowedDeficit ) { 99 balance += amount; 100 } else { 101 throw new RuntimeException ("Allowed deficit is not sufficient for account "+this); 102 } 103 } 104 105 110 111 public void debit(double amount) { 112 if( balance - amount > allowedDeficit ) { 113 balance -= amount; 114 } else { 115 throw new RuntimeException ("Allowed deficit is not sufficient for account "+this); 116 } 117 } 118 119 123 124 public double getBalance(){ 125 return balance; 126 } 127 128 public void setBalance(double balance){ 129 this.balance=balance; 130 } 131 132 136 137 public long getAccountNumber(){ 138 return accountNumber; 139 } 140 141 public void setAccountNumber(long number) { 142 this.accountNumber = number; 143 } 144 145 } 146 | Popular Tags |