static void Main(string[] args) { { Inventory inventory = new Inventory(); initializeInvetory(inventory); Guitar whatErinLikes = new Guitar("", 0, Builder.FENDER, "Stratocastor", Type.ELECTRIC, Wood.ALDER, Wood.CEDAR); List <Guitar> guitars = inventory.search(whatErinLikes); if (guitars != null) { foreach (Guitar guitar in guitars) // we can use foreach instead of IEnumerator to loop thorugh the collection { Console.WriteLine("Erin, you might like this " + guitar.GetBuilder() + " " + guitar.GetModel() + " " + guitar.GetType() + " guitar : \n " + guitar.GetBackwood() + " back and sides, \n " + guitar.GetTopwood() + " top. \nYou can have it only for $" + guitar.GetPrice() + " ! "); } } else { Console.WriteLine("Sorry, Erin, we have nothing for you."); } } }
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); }
public Guitar GetGuitar(Guitar serialnumber) { for (IEnumerator i = guitars.GetEnumerator(); i.MoveNext();) { Guitar guitar = (Guitar)i.Current; if (guitar.GetSerialNumber().Equals(serialnumber)) { return(guitar); } } return(null); }
public List <Guitar> search(Guitar searchGuitar) { List <Guitar> matchingguitars = new List <Guitar>(); for (IEnumerator i = guitars.GetEnumerator(); i.MoveNext();) { Guitar guitar = (Guitar)i.Current; // Ignore serial number since that's uniquer // Ignore price since that's unique string builder = searchGuitar.GetBuilder(); if ((builder != null) && (!builder.Equals("")) && (!builder.Equals(guitar.GetBuilder()))) { continue; } String model = searchGuitar.GetModel(); if ((model != null) && (!model.Equals("")) && (!model.Equals(guitar.GetModel()))) { continue; } String type = searchGuitar.Gettype(); if ((type != null) && (!type.Equals("")) && (!type.Equals(guitar.GetType()))) { continue; } String backWood = searchGuitar.GetBackwood(); if ((backWood != null) && (!backWood.Equals("")) && (!backWood.Equals(guitar.GetBackwood()))) { continue; } String topWood = searchGuitar.GetTopwood(); if ((topWood != null) && (!topWood.Equals("")) && (!topWood.Equals(guitar.GetTopwood()))) { continue; } matchingguitars.Add(guitar); } return(matchingguitars); }