コード例 #1
0
 public Guitar(String serialNumber, double price,
        GuitarSpec guitarSpec)
 {
     this.serialNumber = serialNumber;
     this.price = price;
     this.spec = guitarSpec;
 }
コード例 #2
0
        public List<Guitar> search(GuitarSpec searchSpec)
        {
            List<Guitar> matchingGuitars = new List<Guitar>();
            foreach (Guitar guitar in guitars)
            {

                var guitarSpec = guitar.getSpec();
                if (guitar.getSpec().matches(searchSpec))
                    matchingGuitars.Add(guitar);
            }
            return matchingGuitars;
        }
コード例 #3
0
 public bool matches(GuitarSpec otherSpec)
 {
     if (builder != otherSpec.builder)
         return false;
     if ((model != null) && (!model.Equals("")) &&
         (!model.ToLower().Equals(otherSpec.model.ToLower())))
         return false;
     if (type != otherSpec.type)
         return false;
      //   if (numStrings != otherSpec.numStrings)
     //        return false;
     if (backWood != otherSpec.backWood)
         return false;
     if (topWood != otherSpec.topWood)
         return false;
     return true;
 }
コード例 #4
0
        public void SearchGuitar()
        {
            var whatErinLikes = new GuitarSpec(Builder.FENDER, "Stratocastor",
                                   Type.ELECTRIC,6, Wood.ALDER, Wood.ALDER);

            var guitars = inventory.search(whatErinLikes);
            if (guitars.Count!=0)
            {
                foreach (var guitar in guitars)
                {
                    var guitarSpec = guitar.getSpec();
                    Debug.WriteLine("Erin, you might like this " +
                     guitarSpec.getBuilder() + " " + guitarSpec.getModel() + " " +
                     guitarSpec.getType() + " guitar:\n   " +
                     guitarSpec.getBackWood() + " back and sides,\n   " +
                     guitarSpec.getTopWood() + " top.\nYou can have it for only $" +
                     guitar.getPrice() + "!");
                }
            }
            else
            {
                System.Console.WriteLine("Sorry, Erin, we have nothing for you.");
            }
        }
コード例 #5
0
 public void addGuitar(String serialNumber, double price,
              GuitarSpec spec)
 {
     Guitar guitar = new Guitar(serialNumber, price, spec);
     guitars.Add(guitar);
 }