You have a class BankAccount, which has three methods: addGold(), addSilver(), and addCopper(). All these methods change your balance:
class BankAccount {
var balance = 0L
fun addMoney(action: String) {
when (action) {
"1" -> addGold()
"2" -> addSilver()
else -> addCopper()
}
}
fun addGold() {
balance += 10000
}
fun addSilver() {
balance += 100
}
fun addCopper() {
balance += 1
}
}
The program reads the number of threads and creates the threads that will change your balance.
Use block synchronization to ensure the correct work of this program.