public static void Main(string[] args) { Inventory inventory = new Inventory(); initializeInventory(inventory); GuitarSpec whatErinLikes = new GuitarSpec(Builder.FENDER, "Stratocastor", Typeg.ELECTRIC, Wood.ALDER, Wood.ALDER); List <Guitar> guitars = inventory.search(whatErinLikes); if (guitars.Count != 0) { Console.WriteLine("Erin, you might like these guitars:"); foreach (Guitar guitar in guitars) { GuitarSpec guitarSpec = guitar.Spec; Console.WriteLine(" We have a " + guitarSpec.Builder + " " + guitarSpec.Model + " " + guitarSpec.Typeg + " guitar:\n " + guitarSpec.BackWood + " back and sides,\n " + guitarSpec.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 Guitar(string serialNumber, double price, Builder builder, string model, Typeg type, Wood backWood, Wood topWood) { this.serialNumber = serialNumber; this.price = price; this.guitarSpec = new GuitarSpec(builder, model, type, backWood, topWood); }
public List <Guitar> search(GuitarSpec searchSpec) { List <Guitar> matchingGuitars = new List <Guitar>(); foreach (Guitar guitar in guitars) { GuitarSpec guitarSpec = guitar.Spec; if (!guitarSpec.Builder.Equals(searchSpec.Builder)) { continue; } string model = searchSpec.Model.ToLower(); if ((model != null) && (!model.Equals("")) && (!model.Equals(guitarSpec.Model.ToLower()))) { continue; } if (!guitarSpec.Typeg.Equals(searchSpec.Typeg)) { continue; } if (!guitarSpec.BackWood.Equals(searchSpec.BackWood)) { continue; } if (!guitarSpec.TopWood.Equals(searchSpec.TopWood)) { continue; } matchingGuitars.Add(guitar); } return(matchingGuitars); }