public override bool Matches(InstrumentSpec otherSpec)
 {
     var spec = otherSpec as GuitarSpec;
     if (numStrings != spec.NumStrings)
         return false;
     return base.Matches(otherSpec);
 }
 public override bool Matches(InstrumentSpec otherSpec)
 {
     var spec = otherSpec as MandolinSpec;
     if (style != spec.Style)
         return false;
     return base.Matches(otherSpec);
 }
 public bool Matches(InstrumentSpec otherSpec)
 {
     foreach (var propertyName in otherSpec.Properties.Keys)
     {
         if (properties[propertyName] != otherSpec[propertyName])
             return false;
     }
     return true;
 }
Example #4
0
        public override bool Matches(InstrumentSpec otherSpec)
        {
            var spec = otherSpec as MandolinSpec;

            if (style != spec.Style)
            {
                return(false);
            }
            return(base.Matches(otherSpec));
        }
Example #5
0
        public override bool Matches(InstrumentSpec otherSpec)
        {
            var spec = otherSpec as GuitarSpec;

            if (numStrings != spec.NumStrings)
            {
                return(false);
            }
            return(base.Matches(otherSpec));
        }
        public List<Instrument> Search(InstrumentSpec searchSpec)
        {
            List<Instrument> matchingInstruments = new List<Instrument>();

            foreach (var instrument in instruments)
            {
                if (instrument.Spec.Matches(searchSpec))
                    matchingInstruments.Add(instrument);
            }
            return matchingInstruments;
        }
Example #7
0
 public bool Matches(InstrumentSpec otherSpec)
 {
     foreach (var propertyName in otherSpec.Properties.Keys)
     {
         if (properties[propertyName] != otherSpec[propertyName])
         {
             return(false);
         }
     }
     return(true);
 }
        public bool Matches(InstrumentSpec otherSpec)
        {
            foreach (DictionaryEntry property in otherSpec.GetAllProperties())
            {
                string propertyName = (string)property.Key;
                if (!_properties[propertyName].Equals(otherSpec.GetProperty(propertyName)))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #9
0
        public List <Instrument> Search(InstrumentSpec searchSpec)
        {
            List <Instrument> matchingInstruments = new List <Instrument>();

            foreach (var instrument in instruments)
            {
                if (instrument.Spec.Matches(searchSpec))
                {
                    matchingInstruments.Add(instrument);
                }
            }
            return(matchingInstruments);
        }
        public List <Instrument> Search(InstrumentSpec searchSpec)
        {
            List <Instrument> instrumentList = new List <Instrument>();

            foreach (var instrument in _instruments)
            {
                if (instrument != null && instrument.InstrumentSpec.Matches(searchSpec))
                {
                    instrumentList.Add(instrument);
                }
            }

            return(instrumentList);
        }
Example #11
0
        static void Main(string[] args)
        {
            // Set up Rick's guitar inventory
            Inventory inventory = new Inventory();

            InitializeInventory(inventory);

            IDictionary properties = new Hashtable();

            properties.Add("builder", Builder.GIBSON);
            properties.Add("backWood", Wood.MAPLE);
            InstrumentSpec clientSpec = new InstrumentSpec(properties);

            List <Instrument> matchingInstruments = inventory.Search(clientSpec);

            if (matchingInstruments != null && matchingInstruments.Count > 0)
            {
                Console.WriteLine("---------------------------------\n");
                Console.WriteLine("Erin, you might like these instruments:\n");

                foreach (var instrument in matchingInstruments)
                {
                    InstrumentSpec spec = instrument.InstrumentSpec;

                    Console.WriteLine($"We have a {spec.GetProperty("instrumentType")} with the following properties:");

                    foreach (DictionaryEntry property in spec.GetAllProperties())
                    {
                        string propertyName = (string)property.Key;
                        if (propertyName.Equals("instrumentType"))
                        {
                            continue;
                        }
                        Console.WriteLine($"   {propertyName}: {spec.GetProperty(propertyName)}");
                    }

                    Console.WriteLine($"  You can have this {spec.GetProperty("instrumentType")} for ${instrument.Price}\n----");

                    Console.WriteLine("---------------------------------\n");
                }
            }
            else
            {
                Console.WriteLine("Sorry, Erin, we have nothing for you.");
            }

            Console.WriteLine("\n");
        }
 public Instrument(string serialNumber, double price, InstrumentSpec spec)
 {
     this.serialNumber = serialNumber;
     this.price        = price;
     this.spec         = spec;
 }
 public void AddInstrument(string serialNumber, double price, InstrumentSpec spec)
 {
     instruments.Add(new Instrument(serialNumber, price, spec));
 }
Example #14
0
        static void Main(string[] args)
        {
            Inventory inventory = new Inventory();

            InitializeInventory(inventory);

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

            properties.Add("builder", Builder.GIBSON.ToString());
            properties.Add("backWood", Wood.MAPLE.ToString());

            InstrumentSpec clientSpec = new InstrumentSpec(properties);

            #region old
            //GuitarSpec whatEveLikes = new GuitarSpec(Builder.FENDER, "Stratocastor",
            //    Type.ELECTRIC, Wood.ALDER, Wood.ALDER, 12);
            //MandolinSpec whatEveWants = new MandolinSpec(Builder.FENDER, "Major", Type.ACOUSTIC, Wood.ALDER, Wood.ALDER, Style.A);
            ////List<Guitar> guitars = inventory.Search(whatEveLikes);
            //List<Mandolin> mandolins = inventory.Search(whatEveWants);
            #endregion

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

            #region old
            //if (mandolins != null)
            //{
            //    Console.WriteLine("Mamy w magazynie odpowiedni instrument: ");
            //    foreach (var m in mandolins)
            //    {
            //        MandolinSpec spec = m.Spec;
            //        Console.WriteLine(spec.Builder + " model " + spec.Model + " "
            //            + spec.Type + " :\n " + spec.BackWood + " - tył i boki,\n " + spec.TopWood
            //            + " - góra.\nMożesz ją mieć za " + m.Price + "PLN!\n");
            //    }

            //}
            //else
            //{
            //    Console.WriteLine("Przykro mi, nie znalazlem nic dla Ciebie");
            //}
            #endregion

            if (matchingInstrument.Count > 0)
            {
                Console.WriteLine("You might like these instruments:");
                foreach (var instrument in matchingInstrument)
                {
                    InstrumentSpec spec = instrument.Spec;
                    Console.WriteLine("We have a " + spec["instrumentType"] + " with following properties:");
                    foreach (var propertyName in spec.Properties.Keys)
                    {
                        if (propertyName.Equals("instrumentType"))
                        {
                            continue;
                        }
                        Console.WriteLine(" " + propertyName + ": " + spec[propertyName]);
                    }
                    Console.WriteLine("You can have this " + spec["instrumentType"] + " for $" + instrument.Price + "\n---");
                }
            }
            else
            {
                Console.WriteLine("Sorry, we have nothing for you");
            }
        }
Example #15
0
 public void AddInstrument(string serialNumber, double price, InstrumentSpec spec)
 {
     instruments.Add(new Instrument(serialNumber, price, spec));
 }
        public void AddInstrument(string serialNumber, double price, InstrumentSpec instrumentSpec)
        {
            Instrument instrument = new Instrument(serialNumber, price, instrumentSpec);

            _instruments.Add(instrument);
        }
 public Instrument(string serialNumber, double price, InstrumentSpec spec)
 {
     this.serialNumber = serialNumber;
     this.price = price;
     this.spec = spec;
 }
Example #18
0
        static void Main(string[] args)
        {
            Inventory inventory = new Inventory();
            InitializeInventory(inventory);

            Dictionary<string, string> properties = new Dictionary<string, string>();
            properties.Add("builder", Builder.GIBSON.ToString());
            properties.Add("backWood", Wood.MAPLE.ToString());

            InstrumentSpec clientSpec = new InstrumentSpec(properties);

            #region old
            //GuitarSpec whatEveLikes = new GuitarSpec(Builder.FENDER, "Stratocastor",
            //    Type.ELECTRIC, Wood.ALDER, Wood.ALDER, 12);
            //MandolinSpec whatEveWants = new MandolinSpec(Builder.FENDER, "Major", Type.ACOUSTIC, Wood.ALDER, Wood.ALDER, Style.A);
            ////List<Guitar> guitars = inventory.Search(whatEveLikes);
            //List<Mandolin> mandolins = inventory.Search(whatEveWants);
            #endregion

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

            #region old
            //if (mandolins != null)
            //{
            //    Console.WriteLine("Mamy w magazynie odpowiedni instrument: ");
            //    foreach (var m in mandolins)
            //    {
            //        MandolinSpec spec = m.Spec;
            //        Console.WriteLine(spec.Builder + " model " + spec.Model + " "
            //            + spec.Type + " :\n " + spec.BackWood + " - tył i boki,\n " + spec.TopWood
            //            + " - góra.\nMożesz ją mieć za " + m.Price + "PLN!\n");
            //    }

            //}
            //else
            //{
            //    Console.WriteLine("Przykro mi, nie znalazlem nic dla Ciebie");
            //}
            #endregion

            if (matchingInstrument.Count > 0)
            {
                Console.WriteLine("You might like these instruments:");
                foreach (var instrument in matchingInstrument)
                {
                    InstrumentSpec spec = instrument.Spec;
                    Console.WriteLine("We have a " + spec["instrumentType"] + " with following properties:");
                    foreach (var propertyName in spec.Properties.Keys)
                    {
                        if (propertyName.Equals("instrumentType"))
                            continue;
                        Console.WriteLine(" " + propertyName + ": " + spec[propertyName]);
                    }
                    Console.WriteLine("You can have this " + spec["instrumentType"] + " for $" + instrument.Price + "\n---");
                }
            }
            else
            {
                Console.WriteLine("Sorry, we have nothing for you");
            }
        }