예제 #1
0
        public List <Instrument> SearchInstrument(InstrumentSpec searchSpec)
        {
            List <Instrument> matchingInstrument = new List <Instrument>();

            foreach (Instrument instrument in inventory)
            {
                if (instrument.GetSpec().matches(searchSpec))
                {
                    matchingInstrument.Add(instrument);
                }
            }
            return(matchingInstrument);
        }
예제 #2
0
        public bool matches(InstrumentSpec otherspec)
        {
            foreach (var i in otherspec.getProperties().Keys)
            {
                string properName = (string)i;
                if (!properties[properName].Equals(otherspec.getProperty(properName)))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #3
0
        static void Main(string[] args)
        {
            Inventory inventory = new Inventory();

            InitializeInventroy(inventory);

            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add("builder", Builder.COLLINGS);
            properties.Add("backWood", Wood.SITKA);
            properties.Add("builder1", Builder.COLLINGS);
            properties.Add("backWood1", Wood.SITKA);
            InstrumentSpec clientSpec = new InstrumentSpec(properties);

            List <Instrument> matchingInstrument = inventory.SearchInstrument(clientSpec);

            if (matchingInstrument.Count > 0)
            {
                Console.WriteLine("you might like these Instrument:");

                foreach (Instrument instrument in matchingInstrument)
                {
                    InstrumentSpec spec = instrument.GetSpec();

                    Console.WriteLine("We have a " + spec.getProperty("instrumentType") + "  with follwing Properties ");
                    foreach (var j in spec.getProperties().Keys)
                    {
                        string propertyName = Convert.ToString(j);
                        if (propertyName.Equals("instrumentType"))
                        {
                            continue;
                        }
                        Console.WriteLine(" " + propertyName + " :" + spec.getProperty(propertyName));
                    }
                    Console.WriteLine("You can have this " + spec.getProperty("instrumentType") + " $" + instrument.GetPrice() + "\n----");
                }
            }
            else
            {
                Console.WriteLine("Sorry,we have nothing fo you");
            }
        }
예제 #4
0
        public void AddInstrument(string serialno, double price, InstrumentSpec spec)
        {
            Instrument instrument = new Instrument(serialno, price, spec);

            inventory.Add(instrument);
        }
예제 #5
0
 public Instrument(string serialNumber, double price, InstrumentSpec instumentSpec)
 {
     _serialNo = serialNumber;
     _price    = price;
     _spec     = instumentSpec;
 }