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

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

            if (numStrings != spec.NumStrings)
            {
                return(false);
            }
            return(base.Matches(otherSpec));
        }
コード例 #6
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;
        }
コード例 #7
0
 public bool Matches(InstrumentSpec otherSpec)
 {
     foreach (var propertyName in otherSpec.Properties.Keys)
     {
         if (properties[propertyName] != otherSpec[propertyName])
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #8
0
        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);
        }
コード例 #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);
        }
コード例 #10
0
        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);
        }
コード例 #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");
        }
コード例 #12
0
 public Instrument(string serialNumber, double price, InstrumentSpec spec)
 {
     this.serialNumber = serialNumber;
     this.price        = price;
     this.spec         = spec;
 }
コード例 #13
0
 public void AddInstrument(string serialNumber, double price, InstrumentSpec spec)
 {
     instruments.Add(new Instrument(serialNumber, price, spec));
 }
コード例 #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");
            }
        }
コード例 #15
0
 public void AddInstrument(string serialNumber, double price, InstrumentSpec spec)
 {
     instruments.Add(new Instrument(serialNumber, price, spec));
 }
コード例 #16
0
        public void AddInstrument(string serialNumber, double price, InstrumentSpec instrumentSpec)
        {
            Instrument instrument = new Instrument(serialNumber, price, instrumentSpec);

            _instruments.Add(instrument);
        }
コード例 #17
0
 public Instrument(string serialNumber, double price, InstrumentSpec spec)
 {
     this.serialNumber = serialNumber;
     this.price = price;
     this.spec = spec;
 }
コード例 #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");
            }
        }