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

            initializeInvetory(inventory);

            GuitarSpec    whatErinLikes   = new GuitarSpec(Builder.FENDER, "Stratocastor", Type.ELECTRIC, Wood.ALDER, 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.");
            }
        }
Esempio 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);
        }
Esempio n. 3
0
 public Guitar(String serialNumber, double price, Builder builder, string model, Type type, Wood backWood, Wood topWood)
 {
     this.serialNumber = serialNumber;
     this.price        = price;
     spec = new GuitarSpec(builder, model, type, backWood, topWood);
 }