Пример #1
0
        public static void testErin()
        {
            // Set up Rick's guitar inventory
            Inventory inventory = new Inventory();

            initializeInventory(inventory);

            Guitar        whatErinLikes = new Guitar("", 0, Builder.Fender, "Stratocastor", Type.electric, Wood.Alder, Wood.Alder);
            List <Guitar> guitars       = inventory.search(whatErinLikes);

            if (guitars.Count > 0)
            {
                string msgSuccess = "Erin, you might like these guitars: ";
                foreach (Guitar guitar in guitars)
                {
                    msgSuccess += "\nWe have a " +
                                  Enumerations.GetEnumDescription(guitar.builder) + " " + guitar.model + " " +
                                  Enumerations.GetEnumDescription(guitar.type) + " guitar:\n    " +
                                  Enumerations.GetEnumDescription(guitar.backWood) + " back and sides,\n    " +
                                  Enumerations.GetEnumDescription(guitar.topWood) + " top.\nYou can have it for only $" +
                                  guitar.price + "!\n  ----";
                }
                Console.WriteLine(msgSuccess);
                Console.ReadKey();
            }
            else
            {
                string msgFail = "Sorry, Erin, we have nothing for you.";
                Console.WriteLine(msgFail);
                Console.ReadKey();
            }
        }
        public static void testErin()
        {
            // Set up Rick's guitar inventory
            Inventory inventory = new Inventory();
            initializeInventory(inventory);

            Guitar whatErinLikes = new Guitar("", 0, "Fender", "Stratocastor", "electric", "Alder", "Alder");
            Guitar guitar = inventory.search(whatErinLikes);
            if (guitar != null)
            {
                string msgSuccess = "Erin, you might like this " +
                    guitar.builder + " " + guitar.model + " " +
                    guitar.type + " guitar:\n    " +
                    guitar.backWood + " back and sides,\n    " +
                    guitar.topWood + " top.\nYou can have it for only $" +
                    guitar.price + "!";

                Console.WriteLine(msgSuccess);
                Console.ReadKey();
            }
            else
            {
                string msgFail = "Sorry, Erin, we have nothing for you.";
                Console.WriteLine(msgFail);
                Console.ReadKey();
            }
        }
Пример #3
0
 public void addGuitar(string serialNumber,
                         double price,
                         GuitarSpec spec)
 {
     Guitar guitar = new Guitar(serialNumber, price, spec);
     _guitars.Add(guitar);
 }
Пример #4
0
        public static void testErin()
        {
            // Set up Rick's guitar inventory
            Inventory inventory = new Inventory();

            initializeInventory(inventory);

            Guitar whatErinLikes = new Guitar("", 0, "Fender", "Stratocastor", "electric", "Alder", "Alder");
            Guitar guitar        = inventory.search(whatErinLikes);

            if (guitar != null)
            {
                string msgSuccess = "Erin, you might like this " +
                                    guitar.builder + " " + guitar.model + " " +
                                    guitar.type + " guitar:\n    " +
                                    guitar.backWood + " back and sides,\n    " +
                                    guitar.topWood + " top.\nYou can have it for only $" +
                                    guitar.price + "!";

                Console.WriteLine(msgSuccess);
                Console.ReadKey();
            }
            else
            {
                string msgFail = "Sorry, Erin, we have nothing for you.";
                Console.WriteLine(msgFail);
                Console.ReadKey();
            }
        }
        public static void testErin()
        {
            // Set up Rick's guitar inventory
            Inventory inventory = new Inventory();
            initializeInventory(inventory);

            Guitar whatErinLikes = new Guitar("", 0, Builder.Fender, "Stratocastor", Type.electric, Wood.Alder, Wood.Alder);
            List<Guitar> guitars = inventory.search(whatErinLikes);
            if (guitars.Count > 0)
            {
                string msgSuccess = "Erin, you might like these guitars: ";
                foreach (Guitar guitar in guitars)
                {
                    msgSuccess +=   "\nWe have a " +
                        Enumerations.GetEnumDescription(guitar.builder) + " " + guitar.model + " " +
                        Enumerations.GetEnumDescription(guitar.type) + " guitar:\n    " +
                        Enumerations.GetEnumDescription(guitar.backWood) + " back and sides,\n    " +
                        Enumerations.GetEnumDescription(guitar.topWood) + " top.\nYou can have it for only $" +
                        guitar.price + "!\n  ----";
                }
                Console.WriteLine(msgSuccess);
                Console.ReadKey();
            }
            else
            {
                string msgFail = "Sorry, Erin, we have nothing for you.";
                Console.WriteLine(msgFail);
                Console.ReadKey();
            }
        }
Пример #6
0
        public void addGuitar(string serialNumber,
                              double price,
                              GuitarSpec spec)
        {
            Guitar guitar = new Guitar(serialNumber, price, spec);

            _guitars.Add(guitar);
        }
Пример #7
0
        public void addGuitar(String serialNumber, double price, Builder builder, string model, Type type,
                              Wood backWood, Wood topWood)
        {
            Guitar guitar = new Guitar(serialNumber, price, builder,
                                       model, type, backWood, topWood);

            guitars.Add(guitar);
        }
Пример #8
0
 public void addGuitar(string serialNumber,
                         double price,
                         Builder builder,
                         string model,
                         Type type,
                         Wood backWood,
                         Wood topWood)
 {
     Guitar guitar = new Guitar(serialNumber, price, builder, model, type, backWood, topWood);
     _guitars.Add(guitar);
 }
Пример #9
0
 public Guitar getGuitar(string serialNumber)
 {
     for (int i = 0; i < _guitars.Count; i++)
     {
         Guitar guitar = _guitars[i];
         if (guitar.serialNumber.Equals(serialNumber))
         {
             return(guitar);
         }
     }
     return(null);
 }
Пример #10
0
        public void addGuitar(string serialNumber,
                              double price,
                              string builder,
                              string model,
                              string type,
                              string backWood,
                              string topWood)
        {
            Guitar guitar = new Guitar(serialNumber, price, builder, model, type, backWood, topWood);

            _guitars.Add(guitar);
        }
Пример #11
0
 public Guitar getGuitar(string serialNumber)
 {
     for (IEnumerator i = guitars.GetEnumerator(); i.MoveNext();)
     {
         Guitar guitar = (Guitar)i.Current;
         if (guitar.getSerialNumber().Equals(serialNumber))
         {
             return(guitar);
         }
     }
     return(null);
 }
Пример #12
0
        public List <Guitar> search(GuitarSpec searchSpec)
        {
            List <Guitar> matchingGuitars = new List <Guitar>();

            for (int i = 0; i < _guitars.Count; i++)
            {
                Guitar     guitar     = _guitars[i];
                GuitarSpec guitarSpec = guitar.spec;

                if (guitarSpec.matches(searchSpec))
                {
                    matchingGuitars.Add(guitar);
                }
            }
            return(matchingGuitars);
        }
Пример #13
0
        public List<Guitar> search(Guitar searchGuitar)
        {
            List<Guitar> matchingGuitars = new List<Guitar>();
            for (int i = 0; i < _guitars.Count; i++)
            {
                Guitar guitar = _guitars[i];
                // Ignore serial # since that's unique
                // Ignore price since that's unique

                // Check if matches fail
                if (searchGuitar.builder != guitar.builder) { continue; }
                if (!stringsMatch(searchGuitar.model, guitar.model)) { continue; }
                if (searchGuitar.type != guitar.type) { continue; }
                if (searchGuitar.backWood != guitar.backWood) { continue; }
                if (searchGuitar.topWood != guitar.topWood) { continue; }

                matchingGuitars.Add(guitar);
            }
            return matchingGuitars;
        }
Пример #14
0
        public Guitar search(Guitar searchGuitar)
        {
            for (int i = 0; i < _guitars.Count; i++)
            {
                Guitar guitar = _guitars[i];
                // Ignore serial # since that's unique
                // Ignore price since that's unique

                // Check if matches fail
                if (!stringsMatch(searchGuitar.builder, guitar.builder))
                {
                    continue;
                }
                if (!stringsMatch(searchGuitar.model, guitar.model))
                {
                    continue;
                }
                if (!stringsMatch(searchGuitar.type, guitar.type))
                {
                    continue;
                }
                if (!stringsMatch(searchGuitar.backWood, guitar.backWood))
                {
                    continue;
                }
                if (!stringsMatch(searchGuitar.topWood, guitar.topWood))
                {
                    continue;
                }

                // Head First example never returns the 'guitar' object if this part of the code is reached.
                // Main reason for failure in the first example. It works if the following is used:
                // return guitar;
                // This would also have failed if I had copied the Java more literally:
                //      'string.Compare' is case is case insensitive, and this was reasonable to apply
                //      since I had refactored all of the string comparisons into a single method.
            }
            return(null);
        }
Пример #15
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);
        }
Пример #16
0
        public List <Guitar> search(GuitarSpec searchSpec)
        {
            List <Guitar> matchingGuitars = new List <Guitar>();

            for (int i = 0; i < _guitars.Count; i++)
            {
                Guitar     guitar     = _guitars[i];
                GuitarSpec guitarSpec = guitar.spec;
                // Ignore serial # since that's unique
                // Ignore price since that's unique

                // Check if matches fail
                if (searchSpec.builder != guitarSpec.builder)
                {
                    continue;
                }
                if (!stringsMatch(searchSpec.model, guitarSpec.model))
                {
                    continue;
                }
                if (searchSpec.type != guitarSpec.type)
                {
                    continue;
                }
                if (searchSpec.backWood != guitarSpec.backWood)
                {
                    continue;
                }
                if (searchSpec.topWood != guitarSpec.topWood)
                {
                    continue;
                }

                matchingGuitars.Add(guitar);
            }
            return(matchingGuitars);
        }
Пример #17
0
        public Guitar search(Guitar searchGuitar)
        {
            for (int i = 0; i < _guitars.Count; i++)
            {
                Guitar guitar = _guitars[i];
                // Ignore serial # since that's unique
                // Ignore price since that's unique

                // Check if matches fail
                if (!stringsMatch(searchGuitar.builder, guitar.builder)) { continue; }
                if (!stringsMatch(searchGuitar.model, guitar.model)) { continue; }
                if (!stringsMatch(searchGuitar.type, guitar.type)) { continue; }
                if (!stringsMatch(searchGuitar.backWood, guitar.backWood)) { continue; }
                if (!stringsMatch(searchGuitar.topWood, guitar.topWood)) { continue; }

                // Head First example never returns the 'guitar' object if this part of the code is reached.
                // Main reason for failure in the first example. It works if the following is used:
                // return guitar;
                // This would also have failed if I had copied the Java more literally: 
                //      'string.Compare' is case is case insensitive, and this was reasonable to apply
                //      since I had refactored all of the string comparisons into a single method.
            }
            return null;
        }
Пример #18
0
        public void AddGuitar(string serialNumber, double price, GuitarSpec spec)
        {
            var guitar = new Guitar(serialNumber, price, spec);

            guitars.AddLast(guitar);
        }
Пример #19
0
 public void AddGuitar(string serialNumber, double price, GuitarSpec spec)
 {
     var guitar = new Guitar(serialNumber, price, spec);
     guitars.AddLast(guitar);
 }