scp2: task 1.2 + 1.3
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user