static void Main(string[] args) { // Set up Rick's guitar inventory var inventory = new Inventory(); InitializeInventory(inventory); var whatErinLikes = new GuitarSpec(Builder.FENDER, "Stratocastor", Type.ELECTRIC, 6 ,Wood.ALDER, Wood.ALDER); List<Guitar> matchingGuitars = inventory.Search(whatErinLikes); if (matchingGuitars.Count != 0) { Console.WriteLine("Erin, you might like these guitars:"); foreach(Guitar guitar in matchingGuitars) { var 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.\n You can have it for only $" + guitar.Price + "!\n ----"); } } else { Console.WriteLine("Sorry, Erin, we have nothing for you."); } Console.ReadKey(); }
public List<Guitar> Search(GuitarSpec searchSpec) { var matchingGuitars = new List<Guitar>(); foreach (Guitar guitar in guitars) { if (guitar.Spec.Matches(searchSpec)) matchingGuitars.Add(guitar); } return matchingGuitars; }
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; }
public void AddGuitar(string serialNumber, double price, GuitarSpec spec) { var guitar = new Guitar(serialNumber, price, spec); guitars.Add(guitar); }
public Guitar(string serialNumber, double price, GuitarSpec spec) { this.SerialNumber = serialNumber; this.Price = price; this.Spec = spec; }