Created
January 8, 2016 17:57
-
-
Save Ebonkuab/d5332d6ae428d345f1ce to your computer and use it in GitHub Desktop.
Using ruby code to access data defined in Hashes and implementing them in Methods ( LIGHTHOUSE WEB DEV BOOTCAMP)
This file contains 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
@states = { | |
OR: 'Oregon', | |
FL: 'Florida', | |
CA: 'California', | |
NY: 'New York', | |
MI: 'Michigan', | |
TX: 'Texas', | |
AL: 'Alaska' | |
} | |
@cities = { | |
OR: ["Portland"," Eugene"], | |
FL: ['Maimi',"Orlando" ], | |
CA: ['Los Angles', "San Diego"], | |
NY: ['Albany',"Rochester"], | |
MI: ["Detroit","Flint"], | |
TX: ['Houston', "Dallas"], | |
AL: ['Anchorage', "Juneua"] | |
} | |
@taxes = { | |
OR: 7.5, | |
FL: 10, | |
CA: 12, | |
NY: 15, | |
MI: 20, | |
TX: 25, | |
AL: 30 | |
} | |
def describe_state(state_code) | |
if @states.has_key?(state_code.to_sym) == true | |
result = @states[state_code.to_sym] | |
two_result = @cities[state_code.to_sym][0] | |
third_result = @cities[state_code.to_sym][1] | |
else | |
return | |
end | |
#puts result | |
#puts two_result | |
return "#{state_code} stands for #{result} and its cities are #{two_result}, #{third_result}" | |
end | |
def calculate_tax( state_code, amt_to_be_taxed) | |
foo = state_code.to_sym # change the input from a string to a symbol | |
if @states.has_key?(foo) == true | |
return tax_paid= @taxes[foo]*amt_to_be_taxed/100 | |
else | |
return | |
end | |
end | |
def find_state_for_city(city_name) | |
@cities.each do |key, value| | |
if city_name == value[0] || city_name == value[1] | |
return key | |
else | |
#return | |
end | |
end | |
end | |
# TEST Code to test | |
describe_state("CA") | |
calculate_tax("CA", 2000) | |
find_state_for_city("Anchorage") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment