Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. states = {
  2. OR: 'Oregon',
  3. FL: 'Florida',
  4. CA: 'California',
  5. NY: 'New York',
  6. MI: 'Michigan'
  7. }
  8.  
  9. states[:VI] = "virginia"
  10. states[:TX] = "Texas"
  11.  
  12.  
  13. @taxes = {
  14. OR: 5,
  15. FL: 6,
  16. CA: 7,
  17. NY: 7,
  18. MI: 6,
  19. VI: 6.5,
  20. TX: 6.7
  21. }
  22.  
  23.  
  24.  
  25.  
  26. # add_states("VI", "virginia")
  27.  
  28. @cities = {
  29. OR: ["Portland","Vancouver", "Salem"],
  30. FL: ["Miami", "Orlando", "Tampa"],
  31. CA: ["LA", "San Francisco", "San Diego"],
  32. NY: ["Buffalo", "New York", "Geneva"],
  33. MI: ["Detroit", "Grand Rapids", "Lansing"],
  34. VI: ["Richmond", "Norfolk", "Roanoke"],
  35. TX: ["Houston", "Austin", "Dallas"]
  36. }
  37.  
  38. def describe_state(state_code)
  39. puts "The cities in #{state_code} are #{@pc[state_code].join(", ")}" if @cities.has_key?(state_code)
  40.  
  41. @pc.each do | province_codes, cities |
  42. if province_codes.to_s.match(state_code.to_s)
  43. puts "The cities in #{state_code} are #{cities}"
  44. end
  45. end
  46. end
  47.  
  48. def calculate_tax(state, tax)
  49.  
  50. num = tax * @taxes[state] if @taxes.key?(state)
  51. puts sprintf("%.2f", num)
  52.  
  53. end
  54.  
  55.  
  56. def find_state_for_city(city)
  57. city = city.capitalize
  58. @cities.each do |state, cities|
  59. if cities.include?(city)
  60. return state
  61. end
  62. end
  63. puts "no match"
  64. end
  65.  
  66. describe_state(:CA)
  67.  
  68.  
  69. calculate_tax(:CA, 5)
  70. calculate_tax(:NY, 12)
  71.  
  72. puts find_state_for_city(:NY)
  73. puts find_state_for_city("Tampa")
  74. puts find_state_for_city("portland")
  75.  
  76.  
  77.  
  78.  
  79. ca = describe_state(:CA)
  80. tx = describe_state(:TX)
  81. p [tx, ca]
  82.  
  83.  
  84.  
  85. # takes 2 variables
  86. # use State to match Key in hash
  87. # when find the key, use the key to mulitple with Tax
  88. # return product. rounded
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement