scp2: task 1.2 + 1.3

This commit is contained in:
2025-11-07 11:31:09 +01:00
parent a90fb27d5d
commit 2a3141ed9f

View File

@@ -1,10 +1,13 @@
class Account(val code: String, val balance: Double) {
def withdraw(amount: Double): Either[String, Account] =
if (amount < 0)
Left("cannot withdraw negative amounts")
else if (amount > balance)
Left("cannot withdraw more than you have")
else Right(new Account(code, balance - amount))
// TODO
// Implement functions. Account should be immutable.
// Change return type to the appropriate one
def withdraw(amount: Double): Unit = ???
def deposit(amount: Double): Unit = ???
def deposit(amount: Double): Either[String, Account] =
if (amount < 0)
Left("cannot deposit negative amounts")
else Right(new Account(code, balance + amount))
}