Created
November 26, 2020 23:44
-
-
Save Youngestdev/e9a039ea87d340d8fbe39e6ae271b72d to your computer and use it in GitHub Desktop.
Trying to get a hang of scala.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bank | |
trait BankOperations { | |
def createAccount(accountName: String, phoneNumber: String, openingBalance: Double) | |
def depositFund(accountName: String, amount: Double) | |
def withdrawFund(accountNumber: String, amount: Double) | |
// TODO: Add update data probably later? | |
} | |
trait Banks | |
case object FirstBank extends Banks | |
case object FirstCityMonumentBank extends Banks | |
case object GuarantyTrustBank extends Banks | |
case object AccessBank extends Banks | |
class BankClass(bank: Banks) extends BankOperations { | |
private var customers = Map[Long, List[Any]]() | |
private var accountName: String = "" | |
private var phoneNumber: String = "" | |
private var accountBalance: Double = 0.0 | |
def checkAccountNumber(accno: Long): Boolean = { | |
for ((ac, _) <- customers) { | |
println(s"Account numbers?: $ac, $accno") | |
if (ac == accno) { | |
return true | |
} | |
} | |
false | |
} | |
override def createAccount(customerName: String, customerNumber: String, openingBalance: Double = 0.0): Unit = { | |
accountName = customerName | |
phoneNumber = customerNumber | |
accountBalance += openingBalance | |
val accountNumber: Long = math.round(math.random * 100000000000L) | |
customers += (accountNumber -> List(phoneNumber, accountBalance, accountName)) | |
} | |
override def depositFund(accountName: String, amount: Double): Unit = { | |
accountBalance += amount | |
} | |
override def withdrawFund(accountNumber: String, amount: Double): Unit = { | |
if (accountBalance < amount) { | |
throw new Error("You do not have insufficient funds.") | |
} | |
accountBalance -= amount | |
println(s"Your new account balance is $accountBalance") | |
} | |
} | |
object BankOperation extends App { | |
var test = new BankClass(FirstCityMonumentBank) | |
test.createAccount("Abdulazeez Abdulazeez Adeshina", "09058640982", 10000) | |
test.withdrawFund("09058640982", 1000.00) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment