1 package ch.hslu.exercises.sw08.ex3;
2
3 import java.util.concurrent.atomic.AtomicInteger;
4
5 public final class BankAccount {
6
7 private AtomicInteger balance;
8
9
10
11
12
13
14 public BankAccount(final int balance) {
15 this.balance = new AtomicInteger(balance);
16 }
17
18
19
20
21 public BankAccount() {
22 this(0);
23 }
24
25
26
27
28
29
30 public int getBalance() {
31 return this.balance.get();
32 }
33
34
35
36
37
38
39 public void deposite(final int amount) {
40 this.balance.addAndGet(amount);
41 }
42
43
44
45
46
47
48
49 public void transfer(final BankAccount target, final int amount) {
50 this.balance.addAndGet(-amount);
51 target.deposite(amount);
52 }
53 }