public List <Instrument> search(InstrumentSpec searchSpec) { List <Instrument> matchingInstrument = new List <Instrument>(); for (int i = 0; i < inventory.Count; i++) { Instrument instrument = inventory[i]; if (instrument.getSpec().matches(searchSpec)) { matchingInstrument.Add(instrument); } } return(matchingInstrument); }
static void Main(string[] args) { Inventory inventory = new Inventory(); initializeInventory(inventory); Dictionary <string, object> properties = new Dictionary <string, object>(); properties.Add("InstrumentType", InstrumentType.Guitar); properties.Add("Builder", Builder.fender); properties.Add("Model", "Stratocastor"); properties.Add("Type", Type.eletric); properties.Add("NumString", 6); properties.Add("BackWood", Wood.alder); properties.Add("TopWood", Wood.alder); InstrumentSpec whatErinLikes = new InstrumentSpec(properties); List <Instrument> matchingInstrument = inventory.search(whatErinLikes); if (matchingInstrument.Count != 0) { Console.WriteLine("Erin, you might like these instrument:"); for (int i = 0; i < matchingInstrument.Count; i++) { Instrument instrument = matchingInstrument[i]; InstrumentSpec spec = instrument.getSpec(); Console.WriteLine(" We have a " + " " + spec.getProperty("InstrumentType") + "with the following proersties:"); string output = null; Dictionary <string, object> proersties = spec.getProperties(); foreach (string key in proersties.Keys) { output += key + " " + proersties[key] + "; "; } Console.WriteLine(output + "\n"); Console.WriteLine("You can have it for only $" + instrument.getPrice() + "!\n ----"); } } else { Console.WriteLine("Sorry, Erin, we have nothing for you."); } Console.ReadKey(); }
public bool matches(InstrumentSpec otherSpec) { Dictionary <string, object> otherProperties = otherSpec.getProperties(); foreach (string key in otherProperties.Keys) { if (this.properties.ContainsKey(key)) { if (!this.properties[key].Equals(otherProperties[key])) { return(false); } } else { return(false); } } return(true); }
private static void initializeInventory(Inventory inventory) { Dictionary <string, object> properties = new Dictionary <string, object>(); properties.Add("InstrumentType", InstrumentType.Guitar); properties.Add("Builder", Builder.fender); properties.Add("Model", "Stratocastor"); properties.Add("Type", Type.eletric); properties.Add("NumString", 6); properties.Add("BackWood", Wood.alder); properties.Add("TopWood", Wood.alder); InstrumentSpec guitarSpec = new InstrumentSpec(properties); inventory.addInstrument("V95693", 1499.95, guitarSpec); properties = new Dictionary <string, object>(); properties.Add("InstrumentType", InstrumentType.Guitar); properties.Add("Builder", Builder.gibson); properties.Add("Model", "Stratocastor"); properties.Add("Type", Type.acoustic); properties.Add("NumString", 6); properties.Add("BackWood", Wood.cocobolo); properties.Add("TopWood", Wood.alder); guitarSpec = new InstrumentSpec(properties); inventory.addInstrument("V9512", 2059.95, guitarSpec); properties = new Dictionary <string, object>(); properties.Add("InstrumentType", InstrumentType.Mandolin); properties.Add("Builder", Builder.gibson); properties.Add("Model", "Stratocastor"); properties.Add("Type", Type.acoustic); properties.Add("Style", Style.F); properties.Add("BackWood", Wood.cocobolo); properties.Add("TopWood", Wood.alder); InstrumentSpec mandolinSpec = new InstrumentSpec(properties); inventory.addInstrument("M1122", 239.95, mandolinSpec); }
public void addInstrument(string serialNumber, double price, InstrumentSpec spec) { Instrument instrument = new Instrument(serialNumber, price, spec); inventory.Add(instrument); }
public Instrument(string serialNumber, double price, InstrumentSpec spec) { this.serialNumber = serialNumber; this.price = price; this.spec = spec; }