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

            initializeInventory(inventory);

            GuitarSpec searchQuery = new GuitarSpec(Builder.FENDER, "Stratocastor",
                                                    Type.ELECTRIC, 6, Wood.ALDER, Wood.ALDER);

            List <Guitar> matchingGuitars = inventory.search(searchQuery);
            bool          isEmpty         = !matchingGuitars.Any();

            if (isEmpty)
            {
                Console.WriteLine("You might like these guitars:");
                IEnumerator <Guitar> iterator = matchingGuitars.GetEnumerator();

                while (iterator.MoveNext())
                {
                    Guitar     guitar = (Guitar)iterator.Current;
                    GuitarSpec spec   = guitar.Spec;

                    Console.WriteLine("We have a " + spec.Builder + " " + spec.Model + " " + spec.Type + " guitar:\n" + spec.BackWood + " back and sides,\n" + spec.TopWood + " top.\nPrice :$" + guitar.Price + "");
                }
            }
            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>();

            foreach (Guitar guitar in guitars)
            {
                if (guitar.Spec.matches(searchSpec))
                {
                    matchingGuitars.Add(iterator.Current);
                }
            }
            return(matchingGuitars);
        }
Exemplo n.º 3
0
 public void AddGuitar(String serialNumber, double price, GuitarSpec spec)
 {
     guitars.Add(new Guitar(serialNumber, price, spec));
 }
Exemplo n.º 4
0
 public Guitar(String serialNumber, double price, GuitarSpec spec)
 {
     _serialNumber = serialNumber;
     _price        = price;
     _spec         = spec;
 }