Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. # Wizarding Bank Challenge
  2.  
  3. ## Gringott's Wizarding Bank
  4.  
  5. Gringott's has become too big to fail, so the Ministry of Magic has decided to break up this wizarding bank.
  6.  
  7. But they need, quite literally, a programming wizard to create the software to run these banks.
  8.  
  9. ## Specification
  10.  
  11. ### Level 1
  12.  
  13. Using classes, meet the following requirements:
  14.  
  15. (Note: Assume the default unit of currency is the galleon.)
  16.  
  17. * Create a Person class to model a person. This person should have a name and a level of cash.
  18. ````
  19. person1 = Person.new("Minerva", 1000)
  20.  
  21. Minerva has been created with 1000 galleons in cash.
  22.  
  23. person2 = Person.new("Luna", 500)
  24.  
  25. Luna has been created with 500 galleons in cash.
  26. ````
  27.  
  28. * The person class should store a person's cash level, which banks they have an account with, and their balances at each bank.
  29. * Create a Bank class to create Banks with. Each bank should have a unique name.
  30.  
  31. ````
  32. chase = Bank.new("JP Morgan Chase")
  33.  
  34. JP Morgan Chase has been created.
  35.  
  36. wells_fargo = Bank.new("Wells Fargo")
  37.  
  38. Wells Fargo has been created.
  39. ````
  40.  
  41. * The bank class should have a method that allows the creation of an account that is attached to a person, by passing it a person.
  42.  
  43. ````
  44. chase.open_account(person1)
  45.  
  46. An account has been opened for Minerva with JP Morgan Chase.
  47.  
  48. ````
  49. * Banks should be able to accept deposits by passing in a person and deposit amount to the deposit method.
  50. * When accepting a deposit, the person's cash level should decrease by the deposit amount, and the bank account balance should increase by that amount.
  51. ````
  52. chase.deposit(person1, 750)
  53.  
  54. 750 galleons have been deposited into Minerva's Chase account. Balance: 750 Cash: 250
  55. ````
  56.  
  57.  
  58. * A person should not be able to deposit more than their current level of cash.
  59.  
  60. ````
  61. chase.deposit(person1, 5000)
  62.  
  63. Minerva does not have enough cash to perform this deposit.
  64.  
  65. ````
  66.  
  67. * Banks should be able to do withdrawals by passing in a person and withdrawal amount to the withdrawal method.
  68.  
  69. ````
  70. chase.withdrawal(person1, 250)
  71.  
  72. Minerva has withdrawn 250 galleons. Balance: 250
  73. ````
  74. * A person should not be able to withdraw more than they have in a bank. (No overdrafting.)
  75.  
  76. ````
  77. chase.withdrawal(person1, 25000)
  78.  
  79. Insufficient funds.
  80. ````
  81.  
  82.  
  83. * A bank should be able to transfer money to another bank. `chase.transfer(person1, wells_fargo, 250)`
  84.  
  85. ````
  86. chase.transfer(person1, wells_fargo, 250)
  87.  
  88. Minerva has transferred 250 galleons from JP Morgan Chase to Wells Fargo.
  89. ````
  90.  
  91. * Again, a person should not be able to transfer more money than their balance.
  92.  
  93. ````
  94. chase.transfer(person1, wells_fargo, 25000)
  95.  
  96. Insufficient funds.
  97. ````
  98.  
  99. * A person should not be able to transfer money to or from a bank they do not have an account with.
  100.  
  101. ````
  102. chase.transfer(person1, wells_fargo, 250)
  103.  
  104. Luna does not have an account with Wells Fargo.
  105. ````
  106.  
  107. * There should be a method that tells us the current total cash in the bank.
  108.  
  109. ````
  110. chase.total_cash
  111.  
  112. Total Cash: 750 galleons
  113. ````
  114.  
  115. ### Level 2
  116.  
  117. In this new financial climate, there are now comapnies offering wizards and witches lines of credit.
  118.  
  119. * There should be a Credit class, and each Credit should have a unique name. `amex = Credit.new("AMEX")`
  120. * When you open a line of credit, you pass it a person, a credit limit and an interest rate. `amex.open_credit(person1, 100, 0.05)`
  121. * A person should be able to spend against your credit limit. `amex.cc_spend(person1, 50)`
  122. * A person should not be able to spend more than their credit limit.
  123. * A person should be able to pay down their credit balance.
  124. * A person should not be able to pay down their credit balance with more than their cash on hand.
  125.  
  126.  
  127. ### Extensions
  128. * Use TDD to complete this
  129. * Modify your program to handle the different denominations of currency. For your reference: there are 17 silver Sickles
  130. to a gold Galleon, and 29 bronze Knuts to a Sickle.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement