HaniiPuppy

State alt name forms.

Sep 4th, 2017
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. public class StatePriceChecker
  2. {
  3.     Dictionary<String, int> StatePrices = new Dictionary<String, int>
  4.     {
  5.         { "alabama", 213 }, { "alaska", 523 }, { "arizona", 202 }
  6.         // etc. etc.
  7.     }
  8.  
  9.     Dictionary<String, String> StateAltNameForms = new Dictionary<String, int>
  10.     {
  11.         { "al", "alabama" }, { "alab", "alabam"}, { "albm", "alabama"}, { "alabam", "alabama" },
  12.         { "alask", "alaska" }, { "alsk", "alaska" },
  13.         { "ar", "arizona" }, { "ariz", "arizona" }, { "arzn", "arizona" }, { "arizon", "arizona" }
  14.         // etc. etc.
  15.     }
  16.  
  17.     public int GetPrice(String State)
  18.     {
  19.         State = State.ToLower();
  20.  
  21.         if(StateAltNameForms.TryGetValue(State, out String AltForm))
  22.             State = AltForm;
  23.  
  24.         if(StatePrices.TryGetValue(State, out int Price))
  25.             return Price;
  26.         else
  27.             throw new ArgumentException(State + " is not a state.");
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment