Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        public List<Instrument> search(InstrumentSpec searchSpec)
        {
            List<Instrument> matchingInstruments = new List<Instrument>();

            foreach (Instrument instrument in inventory) {
                if(instrument.Spec.matches(searchSpec)){
                    matchingInstruments.Add(instrument);
                }
            }
            return matchingInstruments;
        }
Ejemplo n.º 3
0
        public virtual bool matches(InstrumentSpec otherSpec)
        {
            Dictionary<string,object> otherProperties = otherSpec.getProperties();

            foreach (KeyValuePair<string,object> kvotherProperties in otherProperties) {
                if (properties.ContainsKey (kvotherProperties.Key)) {
                    object propertyValue = properties[kvotherProperties.Key];
                    if(kvotherProperties.Value.ToString() != propertyValue.ToString()){
                        return false;
                    }
                }
            }
            return true;
        }
Ejemplo n.º 4
0
 public Instrument(String serialNumber, double price, InstrumentSpec spec)
 {
     this.serialNumber = serialNumber;
     this.price = price;
     this.spec = spec;
 }
Ejemplo n.º 5
0
        public void addInstrument(String serialNumber, double price,
			InstrumentSpec spec)
        {
            Instrument instrument = new Instrument(serialNumber, price, spec);
            inventory.Add(instrument);
        }