public void RunSimulator() { // Guitar Customer // Setup Rick's Guitar inventory Inventory inventory = new Inventory(); inventory = initializeInventory(inventory); Dictionary <string, object> properties = new Dictionary <string, object>(); properties.Add("builder", Builder.GIBSON); properties.Add("backWood", Wood.MAPLE); InstrumentSpec clientSpec = new InstrumentSpec(properties); List <Instrument> matchingInstruments = inventory.search(clientSpec); if (matchingInstruments.Any()) { foreach (Instrument instrument in matchingInstruments) { InstrumentSpec instrumentSpec = instrument.getSpec(); Console.WriteLine("We have a {0} with the following properties:", instrumentSpec.getProperty("instrumentType")); var specProperties = instrumentSpec.getProperties(); foreach (string property in specProperties.Keys) { if (property.Equals("instrumentType")) { continue; } Console.WriteLine("{0}: {1}", property, instrumentSpec.getProperty(property)); } Console.WriteLine("You can have this {0} for ${1}", instrumentSpec.getProperty("instrumentType"), instrument.getPrice()); Console.WriteLine("---------------------------"); } } else { Console.WriteLine("Sorry customer, we don't have anything for you."); } }
public static void Main(string[] args) { Inventory inventory = new Inventory(); initializeInventory(inventory); Dictionary <string, object> properties = new Dictionary <string, object>(); properties.Add("builder", Builder.GIBSON); properties.Add("backWood", Wood.MAPLE); InstrumentSpec whatBryanLikes = new InstrumentSpec(properties); List <Instrument> matchingInstruments = inventory.search(whatBryanLikes); if (matchingInstruments.Count != 0) { Console.WriteLine("Bryan, you might like these instruments:"); foreach (Instrument instrument in matchingInstruments) { InstrumentSpec instrumentSpec = instrument.Spec; Console.WriteLine(" We have a " + instrumentSpec.getProperty("instrumentType") + " with the following properties:"); foreach (KeyValuePair <string, object> kvproperty in instrumentSpec.getProperties()) { if (kvproperty.Key == "instrumentType") { continue; } Console.WriteLine(" " + kvproperty.Key + ": " + kvproperty.Value); } Console.WriteLine(" You can have this " + instrumentSpec.getProperty("instrumentType") + " for $" + instrument.Price + "\n---"); } } else { Console.WriteLine("Sorry, Erin, we have nothing for you."); } Console.ReadKey(); }