Last active
August 29, 2015 14:15
-
-
Save aaronkaka/49924464a2e98d919da1 to your computer and use it in GitHub Desktop.
A Groovy way to demonstrate banking a fiat currency.
This file contains hidden or 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
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