Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ name := "abc-bank-scala"

version := "1.0"

scalaVersion := "2.11.0"
scalaVersion := "2.11.8"

libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.1.6" % "test"
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.1.6" % "test"
21 changes: 11 additions & 10 deletions src/main/scala/com/abc/Account.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.abc

import scala.collection.mutable.ListBuffer
import java.util.Date

object Account {
final val CHECKING: Int = 0
Expand All @@ -14,31 +15,31 @@ class Account(val accountType: Int, var transactions: ListBuffer[Transaction] =
if (amount <= 0)
throw new IllegalArgumentException("amount must be greater than zero")
else
transactions += Transaction(amount)
transactions += new Transaction(amount)
}

def withdraw(amount: Double) {
if (amount <= 0)
throw new IllegalArgumentException("amount must be greater than zero")
else
transactions += Transaction(-amount)
transactions += new Transaction(-amount)
}

def interestEarned: Double = {
val amount: Double = sumTransactions()
val amount: Double = sumTransactions() + accruedInterest
accountType match {
case Account.SAVINGS =>
if (amount <= 1000) amount * 0.001
else 1 + (amount - 1000) * 0.002
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
if (amount <= 2000) return 20 + (amount - 1000) * 0.05
70 + (amount - 2000) * 0.1
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
}
7 changes: 7 additions & 0 deletions src/main/scala/com/abc/AccountType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.abc

object AccountType{
case object Checkings extends AccountType
case object Savings extends AccountType
case object MaxiSavings extends AccountType
}
8 changes: 5 additions & 3 deletions src/main/scala/com/abc/Bank.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package com.abc
import scala.collection.mutable.ListBuffer

class Bank {
var customers = new ListBuffer[Customer]
private val customers = new ListBuffer.empty[Customer]

def addCustomer(customer: Customer) {
customers += customer
def addCustomer(name: String): Customer = {
val a = Customer(name)
customers += a
a
}

def customerSummary: String = {
Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/com/abc/Customer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ class Customer(val name: String, var accounts: ListBuffer[Account] = ListBuffer(

def totalInterestEarned: Double = accounts.map(_.interestEarned).sum

/**
* This method gets a statement
*/
def transfer(amount:Double, from:Account, to:Account)
}
def getStatement: String = {
//JIRA-123 Change by Joe Bloggs 29/7/1988 start
var statement: String = null //reset statement to null here
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/abc/DateProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import java.util.Calendar
import java.util.Date

object DateProvider {
def getInstance: DateProvider = {
if (instance == null) instance = new DateProvider
def getInstance: DateProvider = new DateProvider{
override def now: Date = Calendar.getInstance.getTime
instance
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/com/abc/Transaction.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.abc

case class Transaction(var amount: Double) {
val transactionDate = DateProvider.getInstance.now
case class Transaction (amount: Double)
(implicit dateProvider: DateProvider) {
val transactionDate = DateProvider.now
}

1 change: 1 addition & 0 deletions src/test/scala/com/abc/BankTest.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.abc

import org.scalatest.{Matchers, FlatSpec}
import com.abc.AccountType._

class BankTest extends FlatSpec with Matchers {

Expand Down
1 change: 1 addition & 0 deletions src/test/scala/com/abc/CustomerTest.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.abc

import org.scalatest.{Matchers, FlatSpec}
import com.abc.AccountType._

class CustomerTest extends FlatSpec with Matchers {
"Customer" should "statement" in {
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/com/abc/TransactionTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.abc
import org.scalatest.{FlatSpec, Matchers}

class TransactionTest extends FlatSpec with Matchers {
"Transaction" should "type" in {
"Transaction" when {
val t = new Transaction(5)
t.isInstanceOf[Transaction] should be(true)
}
Expand Down