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