From ac876c79793ffe57d906516a7cf8bd347a9fc738 Mon Sep 17 00:00:00 2001 From: romanschenk37 <84532681+romanschenk37@users.noreply.github.com> Date: Thu, 7 Apr 2022 14:37:54 +0200 Subject: [PATCH] solved Task AccountTransfer --- .../src/main/java/ch/zhaw/prog2/account/Account.java | 4 ++-- .../java/ch/zhaw/prog2/account/AccountTransferSimulation.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/code/AccountTransfer/src/main/java/ch/zhaw/prog2/account/Account.java b/code/AccountTransfer/src/main/java/ch/zhaw/prog2/account/Account.java index 2133347..42c7656 100644 --- a/code/AccountTransfer/src/main/java/ch/zhaw/prog2/account/Account.java +++ b/code/AccountTransfer/src/main/java/ch/zhaw/prog2/account/Account.java @@ -13,11 +13,11 @@ public class Account { return id; } - public int getBalance() { + public synchronized int getBalance() { return balance; } - public void transferAmount(int amount) { + public synchronized void transferAmount(int amount) { this.balance += amount; } } diff --git a/code/AccountTransfer/src/main/java/ch/zhaw/prog2/account/AccountTransferSimulation.java b/code/AccountTransfer/src/main/java/ch/zhaw/prog2/account/AccountTransferSimulation.java index da0addb..ac633ea 100644 --- a/code/AccountTransfer/src/main/java/ch/zhaw/prog2/account/AccountTransferSimulation.java +++ b/code/AccountTransfer/src/main/java/ch/zhaw/prog2/account/AccountTransferSimulation.java @@ -22,7 +22,8 @@ public class AccountTransferSimulation { (account1.getBalance() + account2.getBalance() + account3.getBalance())); System.out.println("Start of Transaction"); - AccountTransferTask task1 = new AccountTransferTask(account3, account1, 2); + AccountTransferTask task1 = new AccountTransferTask(account1, account3, 2); + //AccountTransferTask task1 = new AccountTransferTask(account3, account1, 2); AccountTransferTask task2 = new AccountTransferTask(account3, account2, 1); AccountTransferTask task3 = new AccountTransferTask(account2, account1, 2);