Solve task 1.2 and 1.3
This commit is contained in:
parent
d047efd8e6
commit
dbc3ae50fe
|
@ -9,13 +9,19 @@ class Account(val bank: Bank, initialBalance: Double) {
|
|||
// TODO
|
||||
// for project task 1.2: implement functions
|
||||
// for project task 1.3: change return type and update function bodies
|
||||
def withdraw(amount: Double): Unit = ???
|
||||
def deposit (amount: Double): Unit = ???
|
||||
def getBalanceAmount: Double = ???
|
||||
def withdraw(amount: Double): Either[Unit, String] = this.synchronized({
|
||||
if (amount < 0 || balance.amount < amount) return Right("OOF");
|
||||
Left({ balance.amount -= amount })
|
||||
})
|
||||
|
||||
def deposit (amount: Double): Either[Unit, String] = this.synchronized({
|
||||
if (amount < 0) return Right("OOF");
|
||||
Left({ balance.amount += amount })
|
||||
})
|
||||
|
||||
def getBalanceAmount: Double = this.synchronized(balance.amount)
|
||||
|
||||
def transferTo(account: Account, amount: Double) = {
|
||||
bank addTransactionToQueue (this, account, amount)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue