This challenge is to see how well you're able to apply Object Oriented Programming concepts to Ruby and JavaScript. During your technical interview, we'll go through your code with you.
This challenge will test your knowledge of
- Classes
- Methods
- Conditionals
- Loops
- Hashes
- Arrays
Read through all instructions before getting started!
Once you're finished, make sure you test your code against the use case and get the same results. Here is what your file should look like:
class Bank
# Your code goes here
end
class Person
# Your code goes here
end
# Test code:
chase = Bank.new("JP Morgan Chase")
wells_fargo = Bank.new("Wells Fargo")
me = Person.new("Shehzan", 500)
friend1 = Person.new("John", 1000)
chase.open_account(me)
chase.open_account(friend1)
wells_fargo.open_account(me)
wells_fargo.open_account(friend1)
chase.deposit(me, 200)
chase.deposit(friend1, 300)
chase.withdraw(me, 50)
chase.transfer(me, wells_fargo, 100)
# chase.deposit(me, 5000)
# chase.withdraw(me, 5000)
# puts chase.total_cash_in_bank
# puts wells_fargo.total_cash_in_bank
-
Put your work on gist before the interview.
-
Create a file called banking.rb
You'll be creating 2 classes in this file. The two classes interact with each other. You'll make the Person
class and the Bank
class.
A new person should have a name set and should have a certain amount of cash that the person keeps with him/her.
With the bank, you should be able to:
- open a new account using the person's name
- withdraw money from a person's account
- deposit money into a person's account
- transfer money to another bank
This extra credit is meant to be more difficult than the coding challenge alone. As much as you'll be tempted to, do not delay scheduling your interview because of any of the extra credit problems. You should only work on this if you have time before your interview.
Extra Credit (level 1): Don't let a person have negative cash. Prevent them from over-withdrawing money.
Extra Credit (level 2): Calculate how much money the bank has stored
Extra Credit (level 5): Create a credit card system for the Bank. I will leave the interface open-ended. This is to test to see your ability to design a system and implement it.
Here's an example of how one might use the two classes:
chase = Bank.new("JP Morgan Chase")
wells_fargo = Bank.new("Wells Fargo")
me = Person.new("Shehzan", 500)
friend1 = Person.new("John", 1000)
chase.open_account(me)
chase.open_account(friend1)
wells_fargo.open_account(me)
wells_fargo.open_account(friend1)
Here is what the output would look like:
JP Morgan Chase bank was just created.
Wells Fargo bank was just created.
Hi, Shehzan. You have $500!
Hi, John. You have $1000!
Shehzan, thanks for opening an account at JP Morgan Chase!
John, thanks for opening an account at JP Morgan Chase!
Shehzan, thanks for opening an account at Wells Fargo!
John, thanks for opening an account at Wells Fargo!
Code
chase.deposit(me, 200)
chase.deposit(friend1, 300)
chase.withdraw(me, 50)
Output
Shehzan deposited $200 to JP Morgan Chase. Shehzan has $300. Shehzan's acccount has $200.
John deposited $300 to JP Morgan Chase. John has $700. John's account has $300.
Shehzan withdrew $50 from JP Morgan Chase. Shehzan has $350. Shehzan's account has $150.
Code
chase.transfer(me, wells_fargo, 100)
Output
Shehzan transfered $100 from the JP Morgan Chase account to the Wells Fargo account. The JP Morgan Chase account has $50 and the Wells Fargo account has $100.
Code
chase.deposit(me, 5000)
chase.withdraw(me, 5000)
Output
Shehzan does not have enough cash to deposit $5000.
Shehzan does not have enough money in the account to withdraw $5000.
Code
puts chase.total_cash_in_bank
puts wells_fargo.total_cash_in_bank
Output
JP Morgan has $350 in the bank.
Wells Fargo has $100 in the bank.
For this open-ended problem, you should create your own test cases and add it to the bottom of your solution