Skip to content

Instantly share code, notes, and snippets.

@aaronkaka
Last active August 29, 2015 14:15
Show Gist options
  • Save aaronkaka/49924464a2e98d919da1 to your computer and use it in GitHub Desktop.
Save aaronkaka/49924464a2e98d919da1 to your computer and use it in GitHub Desktop.
A Groovy way to demonstrate banking a fiat currency.
class Goldsmith {
def unitsOfGold = 0
def depositReceipts = 0
def loanReceipts = 0
def reserveFraction = 0
def deposit(goldDeposit) {
unitsOfGold += goldDeposit
depositReceipts += goldDeposit
println "Units of Gold: " + unitsOfGold
println "Deposit Receipts: " + depositReceipts
calculateBacking()
}
def issueLoans(int perCentDeposits) {
println "Issuing loans at percent of deposits: " + perCentDeposits
loanReceipts += (perCentDeposits/100)*unitsOfGold
println unitsOfGold + " units of gold for " + (depositReceipts+loanReceipts) + " receipts"
calculateBacking()
}
def calculateBacking() {
reserveFraction = unitsOfGold / (depositReceipts+loanReceipts) * 100
def roundedBacking = Math.round(reserveFraction)
println "Backing: " + roundedBacking + "%"
if (roundedBacking == 0) println "Pure FIAT money!!"
}
}
def goldsmith = new Goldsmith()
goldsmith.deposit(100)
goldsmith.deposit(100)
goldsmith.deposit(100)
goldsmith.deposit(100)
goldsmith.deposit(100)
goldsmith.issueLoans(900)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment