Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- states = {
- OR: 'Oregon',
- FL: 'Florida',
- CA: 'California',
- NY: 'New York',
- MI: 'Michigan'
- }
- states[:VI] = "virginia"
- states[:TX] = "Texas"
- @taxes = {
- OR: 5,
- FL: 6,
- CA: 7,
- NY: 7,
- MI: 6,
- VI: 6.5,
- TX: 6.7
- }
- # add_states("VI", "virginia")
- @cities = {
- OR: ["Portland","Vancouver", "Salem"],
- FL: ["Miami", "Orlando", "Tampa"],
- CA: ["LA", "San Francisco", "San Diego"],
- NY: ["Buffalo", "New York", "Geneva"],
- MI: ["Detroit", "Grand Rapids", "Lansing"],
- VI: ["Richmond", "Norfolk", "Roanoke"],
- TX: ["Houston", "Austin", "Dallas"]
- }
- def describe_state(state_code)
- puts "The cities in #{state_code} are #{@pc[state_code].join(", ")}" if @cities.has_key?(state_code)
- @pc.each do | province_codes, cities |
- if province_codes.to_s.match(state_code.to_s)
- puts "The cities in #{state_code} are #{cities}"
- end
- end
- end
- def calculate_tax(state, tax)
- num = tax * @taxes[state] if @taxes.key?(state)
- puts sprintf("%.2f", num)
- end
- def find_state_for_city(city)
- city = city.capitalize
- @cities.each do |state, cities|
- if cities.include?(city)
- return state
- end
- end
- puts "no match"
- end
- describe_state(:CA)
- calculate_tax(:CA, 5)
- calculate_tax(:NY, 12)
- puts find_state_for_city(:NY)
- puts find_state_for_city("Tampa")
- puts find_state_for_city("portland")
- ca = describe_state(:CA)
- tx = describe_state(:TX)
- p [tx, ca]
- # takes 2 variables
- # use State to match Key in hash
- # when find the key, use the key to mulitple with Tax
- # return product. rounded
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement