-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathBank.scala
More file actions
46 lines (36 loc) · 948 Bytes
/
Bank.scala
File metadata and controls
46 lines (36 loc) · 948 Bytes
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
package com.abc
import scala.collection.mutable.ListBuffer
class Bank {
private val customers = new ListBuffer.empty[Customer]
def addCustomer(name: String): Customer = {
val a = Customer(name)
customers += a
a
}
def customerSummary: String = {
var summary: String = "Customer Summary"
for (customer <- customers)
summary = summary + "\n - " + customer.name + " (" + format(customer.numberOfAccounts, "account") + ")"
summary
}
private def format(number: Int, word: String): String = {
number + " " + (if (number == 1) word else word + "s")
}
def totalInterestPaid: Double = {
var total: Double = 0
for (c <- customers) total += c.totalInterestEarned
return total
}
def getFirstCustomer: String = {
try {
customers = null
customers(0).name
}
catch {
case e: Exception => {
e.printStackTrace
return "Error"
}
}
}
}