Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions bank_transaction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
class CreditCard
def initialize(bank, cust)
@bank = bank
@cust = cust
end

def bank()
@bank
end
def cust()
@cust
end
end


class BankCustomer
def initialize(name, balance)
@name = name
@balance = balance
@credit_card
end

def balance()
@balance
end

def deduct_funds(amount)
@balance -= amount
end
def add_funds(amount)
@balance += amount
end
def assign_card(card)
@credit_card = card
end

def credit_card()
@credit_card
end
def get_name()
@name
end
end


class Bank
def initialize(name)
@BankName = name
@customers = Hash.new
end

def withdraw(name, amount)
if @customers[name].balance > amount
@customers[name].deduct_funds(amount)
puts "withdraw success. new balance #{@customers[name].balance}"
return true
else
puts "insufficient funds"
return false
end
end

def deposite(amount)
@customers[name].add_funds(amount)
puts "Added #{amount} to your balance. New balance is #{@balance}"
end

def enroll_BankCustomer(name, balance)
if @customers.has_key?(name)
puts "customer already exists"
else

cust = BankCustomer.new(name, balance)
card = CreditCard.new(self, cust)
cust.assign_card(card)

@customers[name] = cust
puts "added customer!"
cust
end
end

def name()
@BankName
end
end


class Store
def initialize(name)
@name = name
end
def sell_item(cost, card)
customer=card.cust
name = customer.get_name
card.bank.withdraw(name, cost)
end
end

b = Bank.new("BofA")
anthony = b.enroll_BankCustomer('Anthony', 5000)
b.enroll_BankCustomer('john', 2000)
b.withdraw('Anthony', 2000)
b.withdraw('john', 3000)
anthony_card = anthony.credit_card
s = Store.new('store')

s.sell_item(100, anthony_card)
41 changes: 28 additions & 13 deletions http_requests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ answer the following...

1. GET /movies
Fill this in with what the page will look like in the browser:
<body>
Title: A New Hope, Year: 1977
Title: The Empire Strikes Back, Year: 1980
Title: Return of the Jedi, Year: 1983
</body>


*** They might all be on the same line since there's no <p> or <br> in the template.

2. GET /movies/1
Fill this in with what the page will look like in the browser:

<body>
Title: A New Hope, Year: 1977
</body>


3. POST /movies with params {:movie => {:title => "The Phantom Menace", :year => 1998}}
Expand All @@ -35,13 +42,13 @@ Fill in what the database should look like after a post with parameters
================================================
| id | Title | Year |
================================================
| | | |
| 1 | A New Hope | 1977 |
------------------------------------------------
| | | |
| 2 | The Empire Strikes Back | 1980 |
------------------------------------------------
| | | |
| 3 | Return of the Jedi | 1983 |
------------------------------------------------
| | | |
| 4 | The Phantom Menace | 1998 |
------------------------------------------------

4. PUT /movies/4 {:movie => {:title => "The Phantom Menace", :year => 1999}}
Expand All @@ -50,28 +57,36 @@ Fill in what the database should look like after the PUT with the parameters
================================================
| id | Title | Year |
================================================
| | | |
| 1 | A New Hope | 1977 |
------------------------------------------------
| | | |
| 2 | The Empire Strikes Back | 1980 |
------------------------------------------------
| | | |
| 3 | Return of the Jedi | 1983 |
------------------------------------------------
| | | |
| 4 | The Phantom Menace | 1999 |
------------------------------------------------

5. GET /movies
Fill in what the page should look like in the browser

<body>
Title: A New Hope, Year: 1977
Title: The Empire Strikes Back, Year: 1980
Title: Return of the Jedi, Year: 1983
Title: The Phantom Menace, Year: 1999
</body>

*** They might all be on the same line since there's no <p> or <br> in the template.

6. DELETE /movies/4
Fill in what the database should look like after the above request

================================================
| id | Title | Year |
================================================
| | | |
| 1 | A New Hope | 1977 |
------------------------------------------------
| | | |
| 2 | The Empire Strikes Back | 1980 |
------------------------------------------------
| | | |
| 3 | Return of the Jedi | 1983 |
------------------------------------------------
46 changes: 44 additions & 2 deletions interview_responses.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,51 @@
You can write your responses here!

1.
1. One.
Pick one out of the "both" box. Whichever fruit you pick, that box is filled with those fruits (lets say apples)
this means that the box labeled orange has to be the both box -- since it's not apples, and it can't be oranges (since it's labeled wrong) -- it must be both
then that means the third box is the oranges box since it's neither both -- nor oranges.

2.
referse_string(string)
array = []
i = string.lenth() -1
count = 0
for i >=0 i--
array[count] = string[i:i+1]
count += 1
return array.to_s

3.
Recursive:

4.
find_sum(array)
length = array.len
sum = 0
for i=0, i<length, i++
if array[i].type?(Array)
sum = sum + find_sum(array[i])
else
sum = sum + array[i]
return sum

No Recursion:
fund_sum(array)
sum = 0
arrays = array
while (arrays.length() >0)
temp = []
foreach item in arrays
if item.type?(Array)
temp.append(item)
else
sum = sum + item
arrays = []
foreach item in temp
size = item.length()
for i=0, i<size i++
arrays.append(item)
return sum



4. number the jars 0-9. Take the same number of pills out of each jar as its number (e.g. take 6 pills out of jar number 6, 7 pills out of jar 7, etc...). Weigh all the pills together. What you'll have is a weight that isn't divisibile by 10 (since the contaminated pills weigh less than 10 grams). the difference between what you have and the next hightest number divisibile by ten will correspond to the number of the jar that has the contaminated pills e.g. 96 grams will correspond to jar number 4 -- because it takes four pills of weight 9 grams to result in that weight.