feat: add advanced multithreading banking system skeleton
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package dev.banking.model;
|
||||
|
||||
public class BankAccount {
|
||||
|
||||
private final int accountId;
|
||||
private long balance;
|
||||
|
||||
public BankAccount(int accountId, long initialBalance) {
|
||||
this.accountId = accountId;
|
||||
this.balance = initialBalance;
|
||||
}
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO
|
||||
* Implement a thread-safe balance reader.
|
||||
*/
|
||||
public long getBalance() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO
|
||||
* Implement a thread-safe deposit operation.
|
||||
*/
|
||||
public void deposit(int amount) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO
|
||||
* Implement a thread-safe withdrawal operation.
|
||||
*/
|
||||
public void withdraw(int amount) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO
|
||||
* Implement an atomic and deadlock-free transfer.
|
||||
*/
|
||||
public void transfer(BankAccount target, int amount) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package dev.banking.model;
|
||||
|
||||
public class Transaction {
|
||||
|
||||
private final TransactionType type;
|
||||
|
||||
private final int sourceAccountId;
|
||||
private final int targetAccountId;
|
||||
|
||||
private final int amount;
|
||||
|
||||
public Transaction(
|
||||
TransactionType type,
|
||||
int sourceAccountId,
|
||||
int targetAccountId,
|
||||
int amount
|
||||
) {
|
||||
this.type = type;
|
||||
this.sourceAccountId = sourceAccountId;
|
||||
this.targetAccountId = targetAccountId;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public TransactionType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getSourceAccountId() {
|
||||
return sourceAccountId;
|
||||
}
|
||||
|
||||
public int getTargetAccountId() {
|
||||
return targetAccountId;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.banking.model;
|
||||
|
||||
public enum TransactionType {
|
||||
DEPOSIT,
|
||||
WITHDRAW,
|
||||
TRANSFER
|
||||
}
|
||||
Reference in New Issue
Block a user