-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathAccount.scala
More file actions
45 lines (38 loc) · 1.3 KB
/
Account.scala
File metadata and controls
45 lines (38 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.abc
import scala.collection.mutable.ListBuffer
import java.util.Date
object Account {
final val CHECKING: Int = 0
final val SAVINGS: Int = 1
final val MAXI_SAVINGS: Int = 2
}
class Account(val accountType: Int, var transactions: ListBuffer[Transaction] = ListBuffer()) {
def deposit(amount: Double) {
if (amount <= 0)
throw new IllegalArgumentException("amount must be greater than zero")
else
transactions += new Transaction(amount)
}
def withdraw(amount: Double) {
if (amount <= 0)
throw new IllegalArgumentException("amount must be greater than zero")
else
transactions += new Transaction(-amount)
}
def interestEarned: Double = {
val amount: Double = sumTransactions() + accruedInterest
accountType match {
case Account.SAVINGS =>
if (amount <= 1000) amount * 0.001/365
else 1/365 + (amount - 1000) * 0.002/365
case Account.MAXI_SAVINGS =>
if (amount <= 1000) return amount * 0.02/365
if (amount <= 2000) return 20 + (amount - 1000) * 0.05/365
70 + (amount - 2000) * 0.1/365
case _ =>
amount * 0.001
}
}
def sumTransactions(checkAllTransactions: Boolean = true): Double = transactions.map(_.amount).sum
def accumulateInterest = accruedInterest += interestEarned
}