Created
October 1, 2015 04:12
-
-
Save RobertCam/c0b6a7c811b89cbc4464 to your computer and use it in GitHub Desktop.
States and Cities
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' | |
} | |
@states[:WA]="Washington" | |
@states[:TX]="Texas" | |
@cities = { | |
OR: ['Portland', 'Eugene'], | |
FL: ['Orlando', 'Miami'], | |
CA: ['Los Angelas', 'San Fransico'], | |
NY: ['New York City', 'New Jersey'], | |
MI: ['Detroit', 'Lansing'], | |
WA: ['Seatlle', 'Tacoma'], | |
TX: ['Austin', 'Houston'] | |
} | |
@taxes = { | |
OR: 0.035, | |
FL: 0.04, | |
CA: 0.055, | |
NY: 0.025, | |
MI: 0.07, | |
WA: 0.0105, | |
TX: 0.06 | |
} | |
def describe_state(statecode) | |
puts "#{statecode} is for #{@states[statecode]}. It has #{@cities[statecode].length} cities, #{@cities[statecode].join(', ')}" | |
end | |
def calculate_tax(statecode, dollar) | |
tax = @taxes[statecode] * dollar | |
tax = tax.round(2) | |
puts "The total tax for #{dollar} in #{statecode} is #{tax}" | |
end | |
def find_state_for_city(city) | |
@cities.each do |state, city1| | |
city1.each do |c| | |
if c == city | |
return puts "#{city} is in #{state}" | |
end | |
end | |
end | |
end | |
puts describe_state(:TX) | |
puts calculate_tax(:TX, 53.21) | |
puts find_state_for_city("Houston") | |
puts describe_state(:CA) | |
puts calculate_tax(:CA, 3047.48) | |
puts find_state_for_city("Los Angelas") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment