Skip to content

Instantly share code, notes, and snippets.

@Andsbf
Created March 5, 2015 00:51
Show Gist options
  • Save Andsbf/d138182c17c5f8f8e1df to your computer and use it in GitHub Desktop.
Save Andsbf/d138182c17c5f8f8e1df to your computer and use it in GitHub Desktop.
States & Cities Exercise
# require 'pry'
@states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
}
@states[:TX] = "Texas"
@states[:OK] = "OKlahoma"
@cities = {
OR: ["Oregon_city_1","Oregon_city_2"],
FL: ["Florida_city_1","Florida_city_2"],
CA: ["California_city_1","California_city_2"],
NY: ["New york_city_1","New York_city_2"],
MI: ["Michigan_city_1","Michigan_city_2"],
TX: ["TX_city_1","TX_city_2"],
OK: ["OK_c1","OK_c2"]
}
@taxes = {
OR: 4,
FL: 5,
CA: 6,
NY: 7,
MI: 8,
TX: 9,
OK: 10
}
def describe_state(state="")
return "Empty entry" if state == ""
"#{state} is #{@states[state.to_sym]}, name of couple cities: #{@cities[state.to_sym].join(", ")}."
end
def calculate_tax(state="",dollar_amount=0)
# binding.pry
print "tax amount in #{state} is #{@taxes[state.to_sym]}% for $#{dollar_amount} it is $#{(dollar_amount* ( @taxes[state.to_sym].to_f/100 ) ).round(2)} \n"
(dollar_amount * ( @taxes[state.to_sym].to_f/100 ) ).round(2)
end
def find_state_for_city(city_name)
@cities.each do |k,v|
v.each { |value| return k if value==city_name }
end
end
#TEST DRIVE
puts calculate_tax("OR",4444)
puts find_state_for_city("California_city_1")
puts describe_state("OR")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment