Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Inventory inventory = new Inventory();

            initializeInvetory(inventory);

            GuitarSpec    whatErinLikes   = new GuitarSpec(Builder.FENDER, "Stratocastor", Type.ELECTRIC, Wood.MAPLE, Wood.CEDAR);
            List <Guitar> matchingGuitars = inventory.search(whatErinLikes);

            if (matchingGuitars != null)
            {
                Console.WriteLine("Erin, you might like these guitars :");

                foreach (Guitar guitar in matchingGuitars)  // we can use foreach instead of IEnumerator to loop thorugh the collection
                {
                    GuitarSpec spec = guitar.getSpec();
                    Console.WriteLine(" We have a " +
                                      spec.getBuilder() + " " + spec.getModel() + " " +
                                      spec.getType() + " guitar : \n    " +
                                      spec.getBackWood() + " back and sides, \n    " +
                                      spec.getTopWood() + " top. \nYou can have it only for $" +
                                      guitar.getPrice() + " ! ");
                }
            }
            else
            {
                Console.WriteLine("Sorry, Erin, we have nothing for you.");
            }
        }
Exemplo n.º 2
0
        public List <Guitar> search(GuitarSpec searchSpec)
        {
            List <Guitar> matchingGuitars = new List <Guitar>();

            for (IEnumerator i = guitars.GetEnumerator(); i.MoveNext();)
            {
                Guitar     guitar     = (Guitar)i.Current;
                GuitarSpec guitarSpec = guitar.getSpec();
                // Ignore serial number since that's uniquer
                // Ignore price since that's unique
                string builder = searchSpec.getBuilder();
                if (searchSpec.getBuilder() != searchSpec.getBuilder())
                {
                    continue;
                }
                String model = searchSpec.getModel().ToLower();
                if ((model != null) && (!model.Equals("")) && (!model.Equals(guitarSpec.getModel().ToLower())))
                {
                    continue;
                }
                if (searchSpec.getType() != guitarSpec.getType())
                {
                    continue;
                }
                if (searchSpec.getBackWood() != guitarSpec.getBackWood())
                {
                    continue;
                }
                if (searchSpec.getTopWood() != guitarSpec.getTopWood())
                {
                    continue;
                }

                matchingGuitars.Add(guitar);
            }
            return(matchingGuitars);
        }