public virtual bool Matches(InstrumentSpec otherspec) { if (_builder != otherspec._builder) { return(false); } if (((_model) != null) && (!_model.Equals("")) && (!_model.Equals(otherspec._model))) { return(false); } if (_type != otherspec._type) { return(false); } if (_backwood != otherspec._backwood) { return(false); } if (_topwood != otherspec._topwood) { return(false); } return(true); }
public bool Matches(InstrumentSpec otherspec) { foreach (KeyValuePair <string, object> property in otherspec._properties) { if (!(this._properties.Contains(property))) { return(false); } } return(true); }
public List <Instrument> Search(InstrumentSpec searchspec) { List <Instrument> Matching = new List <Instrument>(); foreach (Instrument instrument in instruments) { if (instrument.Spec.Matches(searchspec)) { Matching.Add(instrument); } } return(Matching); }
public void AddInstrument(string serialNumber, double price, InstrumentSpec spec) //Builder builder, string model, Type type, Wood backwood, Wood topwood) { Instrument instrument = null; if (spec.GetType() == typeof(GuitarSpec)) { instrument = new Guitar(serialNumber, price, (GuitarSpec)spec); } else if (spec.GetType() == typeof(MandolinSpec)) { instrument = new Mandolin(serialNumber, price, (MandolinSpec)spec); } instruments.Add(instrument); }
static void Main(string[] args) { try { EnumToString convertToString = new EnumToString(); Inventory inventory = new Inventory(); InitializeInventory(inventory); Dictionary <string, object> properties = new Dictionary <string, object>(); properties.Add("instrumentType1", InstrumentType.BASS); properties.Add("builder1", Builder.COLLINGS); properties.Add("model1", "CJ"); properties.Add("numString1", 6); properties.Add("topWood1", Wood.INDIAN_ROSEWOOD); properties.Add("backWood1", Wood.SITKA); InstrumentSpec clientSpec = new InstrumentSpec(properties); List <Instrument> matchingInstrument = inventory.Search(clientSpec); if (matchingInstrument.Count > 0) { Console.WriteLine("you might like these Instrument:"); foreach (Instrument instrument in matchingInstrument) { InstrumentSpec spec = instrument.Spec; Console.WriteLine("We have a " + spec.GetProperty("instrumentType") + " with follwing Properties "); foreach (var j in spec.Properties.Keys) { string propertyName = Convert.ToString(j); Console.WriteLine(" " + propertyName + " :" + spec.GetProperty(propertyName)); } Console.WriteLine("You can have this " + spec.GetProperty("instrumentType") + " $" + instrument.Price + "\n----"); } } else { Console.WriteLine("Sorry,we have nothing fo you"); } } catch (Exception e) { Console.WriteLine(e.Message); } }
public override bool Matches(InstrumentSpec otherspec) { if (!(base.Matches(otherspec))) { return(false); } if (!(otherspec.GetType() == typeof(GuitarSpec))) { return(false); } GuitarSpec spec = (GuitarSpec)otherspec; if (_numStrings != spec._numStrings) { return(false); } return(true); }
public override bool Matches(InstrumentSpec otherspec) { if (!(base.Matches(otherspec))) { return(false); } if (!(otherspec.GetType() == typeof(MandolinSpec))) { return(false); } MandolinSpec spec = (MandolinSpec)otherspec; if (!_style.Equals(spec._style)) { return(false); } return(true); }
public void AddInstrument(string serialNumber, double price, InstrumentSpec spec) //Builder builder, string model, Type type, Wood backwood, Wood topwood) { Instrument instrument = new Instrument(serialNumber, price, spec); instruments.Add(instrument); }
public Instrument(string serialNumber, double price, InstrumentSpec spec) { _serialNumber = serialNumber; _price = price; _spec = spec; }