Skip to content

Instantly share code, notes, and snippets.

@joshuastr
Created April 27, 2016 20:51
Show Gist options
  • Save joshuastr/f59b579d4a7bbe8271aed4415682f085 to your computer and use it in GitHub Desktop.
Save joshuastr/f59b579d4a7bbe8271aed4415682f085 to your computer and use it in GitHub Desktop.
@states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
}
@states[:NC] = 'North Carolina'
@states[:CO] = 'Colorado'
@cities = {
FL: ['Miami', 'Orlando'],
CA: ['LA', 'SF'],
NY: ['New York', 'Buffalo'],
MI: ['Detroit', 'Grand Rapids']
}
@state_tax = {
FL: 0.03,
CA: 0.03,
NY: 0.03,
MI: 0.03
}
def describe_state(code)
code = code.to_sym #input = string
if code.length < 2 or code.length > 2
"please input a valid state code"
elsif @states[code].nil? or @cities[code].nil?
"#{code} is not a valid State Code!"
else
"#{code} stands for #{@states[code]}. It has #{@cities[code].length} major cities: #{@cities[code].join(', ')}"
end
end
def calculate_tax(code, amount)
code = code.to_sym
"In #{@states[code]} $#{amount} after #{@state_tax[code]}% taxes are $#{(1 +@state_tax[code]) * (amount)}"
end
def find_state_for_city (city)
state = ''
@cities.each do |k,v|
if v.include? city
state = @states[k]
"#{city} is in #{state}"
end
end
end
puts describe_state('FL')
puts calculate_tax('FL',10)
puts find_state_for_city ('Miami')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment