private static void findInstrument(string name, InstrumentSpec instrumentSpec, Inventory inventory)
        {
            string            choiceInstrument = "";
            List <Instrument> instruments      = new List <Instrument>();

            if (instrumentSpec is GuitarSpec)
            {
                List <Guitar> guitars = inventory.search((GuitarSpec)instrumentSpec);
                instruments      = new List <Instrument>(guitars);
                choiceInstrument = "guitar";
            }
            else if (instrumentSpec is MandolinSpec)
            {
                List <Mandolin> mandolins = inventory.search((MandolinSpec)instrumentSpec);
                instruments      = new List <Instrument>(mandolins);
                choiceInstrument = "mandolin";
            }

            if (instruments.Count > 0)
            {
                try
                {
                    string msgSuccess = string.Format("{0}, you might like these {1}s: ", name, choiceInstrument);
                    foreach (Instrument instrument in instruments)
                    {
                        InstrumentSpec spec = null;
                        if (instrumentSpec is GuitarSpec)
                        {
                            Guitar guitar = (Guitar)instrument;
                            spec = guitar.spec;
                        }
                        else if (instrumentSpec is MandolinSpec)
                        {
                            Mandolin mandolin = (Mandolin)instrument;
                            spec = mandolin.spec;
                        }
                        if (spec == null)
                        {
                            messageFail(name);
                        }

                        msgSuccess += "\nWe have a " +
                                      Enumerations.GetEnumDescription(spec.builder) + " " + spec.model + " " +
                                      Enumerations.GetEnumDescription(spec.type) + " " + choiceInstrument + ":\n    " +
                                      Enumerations.GetEnumDescription(spec.backWood) + " back and sides,\n    " +
                                      Enumerations.GetEnumDescription(spec.topWood) + " top.\nYou can have it for only $" +
                                      instrument.price + "!\n  ----";
                    }
                    Console.WriteLine(msgSuccess);
                    Console.ReadKey();

                    return;
                }
                catch (Exception)
                {
                    // No action taken. Default fail message will be triggered at end of method.
                }
            }
            messageFail(name);
        }
Example #2
0
 public void addInstrument(string serialNumber,
                           double price,
                           InstrumentSpec spec)
 {
     Instrument instrument = new Instrument(serialNumber, price, spec);
     _inventory.Add(instrument);
 }
        public virtual bool matches(InstrumentSpec spec)
        {
            // Ignore serial # since that's unique
            // Ignore price since that's unique

            // Check if matches fail
            if (builder != spec.builder)
            {
                return(false);
            }
            if (type != spec.type)
            {
                return(false);
            }
            if (backWood != spec.backWood)
            {
                return(false);
            }
            if (topWood != spec.topWood)
            {
                return(false);
            }

            return(true);
        }
        public void addInstrument(string serialNumber,
                                  double price,
                                  InstrumentSpec spec)
        {
            Instrument instrument = new Instrument(serialNumber, price, spec);

            _inventory.Add(instrument);
        }
Example #5
0
 public Instrument(string serialNumber,
                   double price,
                   InstrumentSpec spec)
 {
     this.serialNumber = serialNumber;
     this.price = price;
     this.spec = spec;
 }
Example #6
0
 public Instrument(string serialNumber,
                   double price,
                   InstrumentSpec spec)
 {
     this.serialNumber = serialNumber;
     this.price        = price;
     this.spec         = spec;
 }
Example #7
0
 public override bool matches(InstrumentSpec spec)
 {
     if (!base.matches(spec)) { return false; }
     if (!(spec is GuitarSpec))  { return false; }
     GuitarSpec guitarSpec = (GuitarSpec)spec;
     if (!stringsMatch(model, guitarSpec.model)) { return false; }
     
     return true;
 }
Example #8
0
 private InstrumentType getInstrumentType(InstrumentSpec spec)
 {
     object instrumentType = spec.getProperty("instrumentType");
     if (instrumentType is InstrumentType)
     {
         return (InstrumentType)instrumentType;
     }
     return InstrumentType.Unspecified;
 }
        public override bool matches(InstrumentSpec spec)
        {
            if (!base.matches(spec)) { return false; }
            if (!(spec is MandolinSpec)) { return false; }
            MandolinSpec mandolinSpec = (MandolinSpec)spec;
            if (style != mandolinSpec.style) { return false; }

            return true;
        }
        private static void findInstrument(string name, InstrumentSpec instrumentSpec, Inventory inventory)
        {
            string choiceInstrument = "";
            List<Instrument> instruments = new List<Instrument>();
            if (instrumentSpec is GuitarSpec)
            {
                List<Guitar> guitars = inventory.search((GuitarSpec)instrumentSpec);
                instruments = new List<Instrument>(guitars);
                choiceInstrument = "guitar";
            }
            else if (instrumentSpec is MandolinSpec)
            {
                List<Mandolin> mandolins = inventory.search((MandolinSpec)instrumentSpec);
                instruments = new List<Instrument>(mandolins);
                choiceInstrument = "mandolin";
            }
            
            if (instruments.Count > 0)
            {
                try
                {
                    string msgSuccess = string.Format("{0}, you might like these {1}s: ", name, choiceInstrument);
                    foreach (Instrument instrument in instruments)
                    {
                        InstrumentSpec spec = null;
                        if (instrumentSpec is GuitarSpec)
                        {
                            Guitar guitar = (Guitar)instrument;
                            spec = guitar.spec;
                        }
                        else if (instrumentSpec is MandolinSpec)
                        {
                            Mandolin mandolin = (Mandolin)instrument;
                            spec = mandolin.spec;
                        }
                        if (spec == null) { messageFail(name); }

                        msgSuccess += "\nWe have a " +
                            Enumerations.GetEnumDescription(spec.builder) + " " + spec.model + " " +
                            Enumerations.GetEnumDescription(spec.type) + " " + choiceInstrument +":\n    " +
                            Enumerations.GetEnumDescription(spec.backWood) + " back and sides,\n    " +
                            Enumerations.GetEnumDescription(spec.topWood) + " top.\nYou can have it for only $" +
                            instrument.price + "!\n  ----";
                    }
                    Console.WriteLine(msgSuccess);
                    Console.ReadKey();

                    return;
                }
                catch (Exception)
                {
                    // No action taken. Default fail message will be triggered at end of method.
                }
            }
            messageFail(name);
        }
        private InstrumentType getInstrumentType(InstrumentSpec spec)
        {
            object instrumentType = spec.getProperty("instrumentType");

            if (instrumentType is InstrumentType)
            {
                return((InstrumentType)instrumentType);
            }
            return(InstrumentType.Unspecified);
        }
 private InstrumentType getInstrumentType(InstrumentSpec spec)
 {
     if (spec is GuitarSpec)
     {
         return(InstrumentType.Guitar);
     }
     else if (spec is MandolinSpec)
     {
         return(InstrumentType.Mandolin);
     }
     return(InstrumentType.Unknown);
 }
Example #13
0
 private InstrumentType getInstrumentType(InstrumentSpec spec)
 {
     if (spec is GuitarSpec)
     {
         return InstrumentType.Guitar;
     }
     else if (spec is MandolinSpec)
     {
         return InstrumentType.Mandolin; 
     }
     return InstrumentType.Unknown;
 }
        public virtual bool matches(InstrumentSpec spec)
        {
            // Ignore serial # since that's unique
            // Ignore price since that's unique

            // Check if matches fail
            if (builder != spec.builder) { return false; }
            if (type != spec.type) { return false; }
            if (backWood != spec.backWood) { return false; }
            if (topWood != spec.topWood) { return false; }

            return true;
        }
        public List <Instrument> search(InstrumentSpec searchSpec)
        {
            List <Instrument> matchingInstruments = new List <Instrument>();

            for (int i = 0; i < _inventory.Count; i++)
            {
                Instrument instrument = _inventory[i];
                if (instrument.spec.matches(searchSpec))
                {
                    matchingInstruments.Add(instrument);
                }
            }
            return(matchingInstruments);
        }
Example #16
0
 public List<Instrument> search(InstrumentSpec searchSpec)
 {
     List<Instrument> matchingInstruments = new List<Instrument>();
     for (int i = 0; i < _inventory.Count; i++)
     {
         Instrument instrument = _inventory[i];
         if (instrument.spec.matches(searchSpec))
         {
             matchingInstruments.Add(instrument);
         }
         
     }
     return matchingInstruments;
 }
Example #17
0
        public bool matches(InstrumentSpec spec)
        {
            // Ignore serial # since that's unique
            // Ignore price since that's unique

            // Check if matches fail
            foreach (string propertyName in spec.properties.Keys)
            {
                if (!properties[propertyName].Equals(spec.getProperty(propertyName)))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #18
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);
 }
        public bool matches(InstrumentSpec spec)
        {
            // Ignore serial # since that's unique
            // Ignore price since that's unique

            // Check if matches fail
            foreach (string propertyName in spec.properties.Keys)
            {
                if (!properties[propertyName].Equals(spec.getProperty(propertyName)))
                {
                    return false;
                }
            }

            return true;
        }
        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);
        }
        private static void findInstrument(string name, InstrumentSpec instrumentSpec, Inventory inventory)
        {
            List <Instrument> instruments = inventory.search(instrumentSpec);

            if (instruments.Count > 0)
            {
                try
                {
                    string msgSuccess = string.Format("{0}, you might like these instruments: ", name);
                    foreach (Instrument instrument in instruments)
                    {
                        InstrumentSpec spec = instrument.spec;
                        if (spec == null)
                        {
                            messageFail(name);
                        }

                        string instrumentType = Enumerations.GetEnumDescription((InstrumentType)spec.getProperty("instrumentType"));

                        msgSuccess += "\nWe have a " + instrumentType +
                                      " with the following properties: ";

                        foreach (string propertyName in spec.properties.Keys)
                        {
                            if (propertyName.CompareTo("instrumentType") == 0)
                            {
                                continue;
                            }
                            msgSuccess += "\n    " + propertyName + ": " + spec.getProperty(propertyName);
                        }
                        msgSuccess += "\nYou can have this " + instrumentType + " for $" +
                                      instrument.price + "!\n  ----";
                    }
                    Console.WriteLine(msgSuccess);
                    Console.ReadKey();

                    return;
                }
                catch (Exception)
                {
                    // No action taken. Default fail message will be triggered at end of method.
                }
            }
            messageFail(name);
        }
Example #22
0
        public override bool matches(InstrumentSpec spec)
        {
            if (!base.matches(spec))
            {
                return(false);
            }
            if (!(spec is MandolinSpec))
            {
                return(false);
            }
            MandolinSpec mandolinSpec = (MandolinSpec)spec;

            if (style != mandolinSpec.style)
            {
                return(false);
            }

            return(true);
        }
Example #23
0
        public override bool matches(InstrumentSpec spec)
        {
            if (!base.matches(spec))
            {
                return(false);
            }
            if (!(spec is GuitarSpec))
            {
                return(false);
            }
            GuitarSpec guitarSpec = (GuitarSpec)spec;

            if (!stringsMatch(model, guitarSpec.model))
            {
                return(false);
            }

            return(true);
        }
        public static void testInstrumentSearch()
        {
            // Set up Rick's instrument inventory
            Inventory inventory = new Inventory();

            initializeInventory(inventory);

            Dictionary <string, object> guitarSpec = new Dictionary <string, object> {
                { "instrumentType", InstrumentType.Guitar },
                { "builder", Builder.Fender },
                { "model", "Stratocastor" },
                { "type", Type.electric },
                { "topWood", Wood.Alder },
                { "backWood", Wood.Adirondack },
                { "numStrings", 6 }
            };
            InstrumentSpec whatErinLikes = new InstrumentSpec(guitarSpec);

            findInstrument("Erin", whatErinLikes, inventory);


            Dictionary <string, object> mandolinSpec = new Dictionary <string, object> {
                { "instrumentType", InstrumentType.Mandolin },
                { "builder", Builder.Fender },
                { "model", "Stratocastor" },
                { "type", Type.acoustic },
                { "topWood", Wood.Alder },
                { "backWood", Wood.Alder },
                { "style", Style.A }
            };
            InstrumentSpec whatPhilLikes = new InstrumentSpec(mandolinSpec);

            findInstrument("Phil", whatPhilLikes, inventory);

            Dictionary <string, object> multiInstrumentSpec = new Dictionary <string, object> {
                { "builder", Builder.Gibson },
                { "backWood", Wood.Maple },
            };
            InstrumentSpec whatSallyLikes = new InstrumentSpec(multiInstrumentSpec);

            findInstrument("Sally", whatSallyLikes, inventory);
        }
Example #25
0
        private static void findInstrument(string name, InstrumentSpec instrumentSpec, Inventory inventory)
        {
            List <Instrument> instruments      = inventory.search(instrumentSpec);
            string            choiceInstrument = "";

            if (instruments.Count > 0)
            {
                try
                {
                    string msgSuccess = string.Format("{0}, you might like these instruments: ", name);
                    foreach (Instrument instrument in instruments)
                    {
                        InstrumentSpec spec = instrument.spec;
                        //choiceInstrument = guitar.ToString().ToLower();

                        if (spec == null)
                        {
                            messageFail(name);
                        }

                        msgSuccess += "\nWe have a " +
                                      Enumerations.GetEnumDescription(spec.builder) + " " + spec.model + " " +
                                      Enumerations.GetEnumDescription(spec.type) + " " + choiceInstrument + ":\n    " +
                                      Enumerations.GetEnumDescription(spec.backWood) + " back and sides,\n    " +
                                      Enumerations.GetEnumDescription(spec.topWood) + " top.\nYou can have it for only $" +
                                      instrument.price + "!\n  ----";
                    }
                    Console.WriteLine(msgSuccess);
                    Console.ReadKey();

                    return;
                }
                catch (Exception)
                {
                    // No action taken. Default fail message will be triggered at end of method.
                }
            }
            messageFail(name);
        }
        private static void findInstrument(string name, InstrumentSpec instrumentSpec, Inventory inventory)
        {
            List<Instrument> instruments = inventory.search(instrumentSpec);

            if (instruments.Count > 0)
            {
                try
                {
                    string msgSuccess = string.Format("{0}, you might like these instruments: ", name);
                    foreach (Instrument instrument in instruments)
                    {
                        InstrumentSpec spec = instrument.spec;
                        if (spec == null) { messageFail(name); }

                        string instrumentType = Enumerations.GetEnumDescription((InstrumentType)spec.getProperty("instrumentType"));

                        msgSuccess += "\nWe have a " + instrumentType +
                            " with the following properties: ";

                        foreach (string propertyName in spec.properties.Keys)
                        {
                            if (propertyName.CompareTo("instrumentType") == 0) { continue; }
                            msgSuccess += "\n    " + propertyName + ": " + spec.getProperty(propertyName);
                        }
                        msgSuccess += "\nYou can have this " + instrumentType + " for $" +
                            instrument.price + "!\n  ----";
                    }
                    Console.WriteLine(msgSuccess);
                    Console.ReadKey();

                    return;
                }
                catch (Exception)
                {
                    // No action taken. Default fail message will be triggered at end of method.
                }
            }
            messageFail(name);
        }
        public static void testInstrumentSearch()
        {
            // Set up Rick's instrument inventory
            Inventory inventory = new Inventory();
            initializeInventory(inventory);

            Dictionary<string, object> guitarSpec = new Dictionary<string, object>{
                                                                { "instrumentType", InstrumentType.Guitar },
                                                                { "builder", Builder.Fender},
                                                                { "model", "Stratocastor" },
                                                                { "type", Type.electric},
                                                                { "topWood", Wood.Alder},
                                                                { "backWood", Wood.Adirondack},
                                                                { "numStrings", 6}
                                                        };
            InstrumentSpec whatErinLikes = new InstrumentSpec(guitarSpec);
            findInstrument("Erin", whatErinLikes, inventory);


            Dictionary<string, object> mandolinSpec = new Dictionary<string, object>{
                                                                { "instrumentType", InstrumentType.Mandolin },
                                                                { "builder", Builder.Fender},
                                                                { "model", "Stratocastor" },
                                                                { "type", Type.acoustic},
                                                                { "topWood", Wood.Alder},
                                                                { "backWood", Wood.Alder},
                                                                { "style", Style.A}
                                                        };
            InstrumentSpec whatPhilLikes = new InstrumentSpec(mandolinSpec);
            findInstrument("Phil", whatPhilLikes, inventory);

            Dictionary<string, object> multiInstrumentSpec = new Dictionary<string, object>{
                                                                { "builder", Builder.Gibson},
                                                                { "backWood", Wood.Maple},
                                                        };
            InstrumentSpec whatSallyLikes = new InstrumentSpec(multiInstrumentSpec);
            findInstrument("Sally", whatSallyLikes, inventory);
        }
        private static void findInstrument(string name, InstrumentSpec instrumentSpec, Inventory inventory)
        {
            List<Instrument> instruments = inventory.search(instrumentSpec);
            string choiceInstrument = "";

            if (instruments.Count > 0)
            {
                try
                {
                    string msgSuccess = string.Format("{0}, you might like these instruments: ", name);
                    foreach (Instrument instrument in instruments)
                    {
                        InstrumentSpec spec = instrument.spec;
                        //choiceInstrument = guitar.ToString().ToLower();

                        if (spec == null) { messageFail(name); }

                        msgSuccess += "\nWe have a " +
                            Enumerations.GetEnumDescription(spec.builder) + " " + spec.model + " " +
                            Enumerations.GetEnumDescription(spec.type) + " " + choiceInstrument +":\n    " +
                            Enumerations.GetEnumDescription(spec.backWood) + " back and sides,\n    " +
                            Enumerations.GetEnumDescription(spec.topWood) + " top.\nYou can have it for only $" +
                            instrument.price + "!\n  ----";
                    }
                    Console.WriteLine(msgSuccess);
                    Console.ReadKey();

                    return;
                }
                catch (Exception)
                {
                    // No action taken. Default fail message will be triggered at end of method.
                }
            }
            messageFail(name);
        }