コード例 #1
0
        public void addInstrument(String serialNumber, double price,
                                  InstrumentSpec spec)
        {
            Instrument instrument = new Instrument(serialNumber, price, spec);

            inventory.Add(instrument);
        }
        private static Inventory initializeInventory(Inventory inventory)
        {
            string[] keys = { "instrumentType", "builder", "model", "type", "numStrings", "topWood", "backWood" };

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

            properties.Add("instrumentType", InstrumentType.GUITAR);
            properties.Add("builder", Builder.COLLINGS);
            properties.Add("model", "CJ");
            properties.Add("type", PlayType.ACOUSTIC);
            properties.Add("numStrings", 6);
            properties.Add("topWood", Wood.INDIAN_ROSEWOOD);
            properties.Add("backWood", Wood.SITKA);
            InstrumentSpec instrumentSpec = new InstrumentSpec(properties);

            inventory.addInstrument("11277", 3999.95, instrumentSpec);

            properties["builder"]  = Builder.MARTIN;
            properties["model"]    = "D-18";
            properties["topWood"]  = Wood.MAHOGANY;
            properties["backWood"] = Wood.ADIRONDACK;
            inventory.addInstrument("122784", 5495.95, new InstrumentSpec(properties));

            properties["builder"]  = Builder.FENDER;
            properties["model"]    = "Stratocastor";
            properties["type"]     = PlayType.ELECTRIC;
            properties["topWood"]  = Wood.ALDER;
            properties["backWood"] = Wood.ALDER;

            inventory.addInstrument("V95693", 1499.95, new InstrumentSpec(properties));
            inventory.addInstrument("V9512", 1549.95, new InstrumentSpec(properties));

            properties["builder"]  = Builder.GIBSON;
            properties["model"]    = "Les Paul";
            properties["topWood"]  = Wood.MAPLE;
            properties["backWood"] = Wood.MAPLE;
            inventory.addInstrument("70108276", 2295.95, new InstrumentSpec(properties));

            properties["model"]    = "SG '61 Reissue";
            properties["topWood"]  = Wood.MAHOGANY;
            properties["backWood"] = Wood.MAHOGANY;
            inventory.addInstrument("82765501", 1890.95, new InstrumentSpec(properties));

            properties["instrumentType"] = InstrumentType.MANDOLIN;
            properties["type"]           = PlayType.ACOUSTIC;
            properties["model"]          = "F-5G";
            properties["backWood"]       = Wood.MAPLE;
            properties["topWood"]        = Wood.MAPLE;
            properties.Remove("numStrings");
            inventory.addInstrument("9019920", 5495.99, new InstrumentSpec(properties));

            properties["instrumentType"] = InstrumentType.BANJO;
            properties["model"]          = "RB-3 Wreath";
            properties.Remove("topWood");
            properties.Add("numStrings", 5);
            inventory.addInstrument("8900231", 2945.95, new InstrumentSpec(properties));

            return(inventory);
        }
コード例 #3
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);
        }
コード例 #4
0
        public void MatchResultsIncudeTwoTypesOfInstruments()
        {
            InstrumentSpec searchSpec = new InstrumentSpec();

            searchSpec[SpecProps.TopWood]  = Wood.Cocobolo;
            searchSpec[SpecProps.BackWood] = Wood.Cocobolo;

            var matchingIntruments = new List <Instrument>(sampleInventory.Search(searchSpec));

            Assert.AreEqual(2, (matchingIntruments as List <Instrument>).Count);

            Assert.AreNotEqual(matchingIntruments[0].Spec[SpecProps.InstrumentType], matchingIntruments[1].Spec[SpecProps.InstrumentType]);
        }
        public List <Instrument> SearchInstrument(InstrumentSpec searchedSpec)
        {
            var matchingInstrument = new List <Instrument>();

            foreach (var instrument in _inventory)
            {
                if (instrument.Spec.CompareSpecWith(searchedSpec))
                {
                    matchingInstrument.Add(instrument);
                }
            }
            return(matchingInstrument);
        }
コード例 #6
0
        public List <Instrument> search(InstrumentSpec searchSpec)
        {
            List <Instrument> toRet = new List <Instrument>();

            foreach (Instrument instrument in this.instruments)
            {
                if (searchSpec.Equals(instrument.getSpec()))
                {
                    toRet.Add(instrument);
                }
            }
            return(toRet);
        }
コード例 #7
0
        public List <Guitar> search(GuitarSpec searchGuitar)
        {
            List <Guitar> matches = new List <Guitar>();

            foreach (Instrument guitar in this.instruments)
            {
                InstrumentSpec spec = guitar.getSpec();
                if (searchGuitar.Equals(spec))
                {
                    matches.Add((Guitar)guitar);
                }
            }
            return(matches);
        }
コード例 #8
0
        public List <Mandolin> search(MandolinSpec searchGuitar)
        {
            List <Mandolin> matches = new List <Mandolin>();

            foreach (Instrument mandolin in this.instruments)
            {
                InstrumentSpec spec = mandolin.getSpec();
                if (searchGuitar.Equals(spec))
                {
                    matches.Add((Mandolin)mandolin);
                }
            }
            return(matches);
        }
        // The search method compares each property of the Guitar object it's passed in to each Guitar object in Rick's inventory
        // Returns a list of guitars that match the customers specifications of the instrument.
        public List <Instrument> search(InstrumentSpec searchSpec)
        {
            // Delegate responsibility to compare the specifications of instruments
            List <Instrument> matchingInstruments = new List <Instrument>();

            foreach (Instrument instrument in inventory)
            {
                if (instrument.getSpec().matches(searchSpec))
                {
                    matchingInstruments.Add(instrument);
                }
            }
            return(matchingInstruments);
        }
コード例 #10
0
        public void AddInstrument(string serialNumber, double price, InstrumentSpec spec)
        {
            Instrument instrument = null;

            if (spec is GuitarSpec)
            {
                instrument = new Guitar(serialNumber, price, (GuitarSpec)spec);
            }
            else if (spec is MandolinSpec)
            {
                instrument = new Mandolin(serialNumber, price, (MandolinSpec)spec);
            }

            inventory.Add(instrument);
        }
コード例 #11
0
ファイル: GuitarSpec.cs プロジェクト: glenn222/OOADPractice
        // matches() uses the superclass's matches() and then performs additional checks to make sure the spec is the right type
        // and matches the guitar-specific properties
        public override bool matches(InstrumentSpec searchInstrumentSpec)
        {
            if (!base.matches(searchInstrumentSpec))
            {
                return(false);
            }
            if (!(searchInstrumentSpec is GuitarSpec))
            {
                return(false);
            }
            GuitarSpec spec = (GuitarSpec)searchInstrumentSpec;

            if (numStrings != spec.numStrings)
            {
                return(false);
            }
            return(true);
        }
        public void RunSimulator()
        {
            // Guitar Customer
            // Setup Rick's Guitar inventory
            Inventory inventory = new Inventory();

            inventory = initializeInventory(inventory);

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

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

            InstrumentSpec clientSpec = new InstrumentSpec(properties);

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

            if (matchingInstruments.Any())
            {
                foreach (Instrument instrument in matchingInstruments)
                {
                    InstrumentSpec instrumentSpec = instrument.getSpec();
                    Console.WriteLine("We have a {0} with the following properties:", instrumentSpec.getProperty("instrumentType"));

                    var specProperties = instrumentSpec.getProperties();
                    foreach (string property in specProperties.Keys)
                    {
                        if (property.Equals("instrumentType"))
                        {
                            continue;
                        }
                        Console.WriteLine("{0}: {1}", property, instrumentSpec.getProperty(property));
                    }
                    Console.WriteLine("You can have this {0} for ${1}", instrumentSpec.getProperty("instrumentType"), instrument.getPrice());
                    Console.WriteLine("---------------------------");
                }
            }
            else
            {
                Console.WriteLine("Sorry customer, we don't have anything for you.");
            }
        }
コード例 #13
0
        public override bool IsMatch(InstrumentSpec searchSpec)
        {
            if (!base.IsMatch(searchSpec))
            {
                return(false);
            }
            if (!(searchSpec is MandolinSpec))
            {
                return(false);
            }

            MandolinSpec spec = searchSpec as MandolinSpec;

            if (Style != spec.Style)
            {
                return(false);
            }

            return(true);
        }
コード例 #14
0
        public override bool IsMatch(InstrumentSpec searchSpec)
        {
            if (!base.IsMatch(searchSpec))
            {
                return(false);
            }
            if (!(searchSpec is GuitarSpec))
            {
                return(false);
            }

            GuitarSpec spec = searchSpec as GuitarSpec;

            if (NumString != spec.NumString)
            {
                return(false);
            }

            return(true);
        }
コード例 #15
0
        static void Main(string[] args)
        {
            Inventory inventory = new Inventory();

            initializeInventory(inventory);

            Hashtable properties = new Hashtable();

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

            InstrumentSpec instrumentSpec = new InstrumentSpec(properties);

            ArrayList matchingInstruments = inventory.Search(instrumentSpec);

            if (matchingInstruments.Count != 0)
            {
                Console.WriteLine("Bryan, you might like these instruments: ");
                foreach (var item in matchingInstruments)
                {
                    Instrument     instrument = (Instrument)item;
                    InstrumentSpec spec       = instrument.Spec;

                    Console.WriteLine("We have a " + spec.GetProperty("instrumentType") + " with the following properties:");
                    foreach (var itemType in spec.GetProperties.Keys)
                    {
                        String propertyName = (String)itemType;
                        if (propertyName.Equals("instrumentType"))
                        {
                            continue;
                        }
                        Console.WriteLine("    " + propertyName + ": " + spec.GetProperty(propertyName));
                    }
                    Console.WriteLine("  You can have this " + spec.GetProperty("instrumentType") + " for $" + instrument.Price + "\n---");
                }
            }
            else
            {
                Console.WriteLine("Sorry, Bryan, we have nothing for you.");
            }
        }
        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();
        }
コード例 #17
0
        public void TwoMatchesForErin()
        {
            InstrumentSpec searchSpec = new InstrumentSpec();

            searchSpec[SpecProps.Builder]   = Builder.Fender;
            searchSpec[SpecProps.ModelName] = "Stratocaster";
            searchSpec[SpecProps.Type]      = GuitarType.Electric;
            searchSpec[SpecProps.TopWood]   = Wood.Alder;
            searchSpec[SpecProps.BackWood]  = Wood.Alder;

            var matchingIntruments = sampleInventory.Search(searchSpec);

            Assert.AreEqual(2, (matchingIntruments as List <Instrument>).Count);

            foreach (Instrument match in matchingIntruments)
            {
                Assert.AreEqual(match.Spec[SpecProps.Builder], searchSpec[SpecProps.Builder]);
                Assert.IsTrue((match.Spec[SpecProps.ModelName] as String).Equals(searchSpec[SpecProps.ModelName] as String, StringComparison.OrdinalIgnoreCase));
                Assert.AreEqual(match.Spec[SpecProps.Type], searchSpec[SpecProps.Type]);
                Assert.AreEqual(match.Spec[SpecProps.TopWood], searchSpec[SpecProps.TopWood]);
                Assert.AreEqual(match.Spec[SpecProps.BackWood], searchSpec[SpecProps.BackWood]);
            }
        }
コード例 #18
0
 public Instrument(string serialNumber, double price, InstrumentSpec instrumentSpec)
 {
     SerialNumber   = serialNumber;
     Price          = price;
     InstrumentSpec = instrumentSpec;
 }
コード例 #19
0
 public Instrument(string serialNumber, double price, InstrumentSpec spec)
 {
     this.SerialNumber = serialNumber;
     this.Price        = price;
     this.Spec         = spec;
 }