static void Main(string[] args) { Case menu = new Case(); List <Flavor> availableFlavors = menu.Flavors; List <Cone> availableCones = menu.Cones; // TODO: Use a Comparer class to sort the 'flavors' array alphabetically by the 'name' // field. FlavorComparer comparer = new FlavorComparer(); availableFlavors.Sort(comparer); // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost' // field. availableCones.Sort(new ConeComparer()); // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting. foreach (Flavor flavor in availableFlavors) { Console.WriteLine(flavor.Name); } foreach (Cone cone in availableCones) { Console.WriteLine($"{cone.Name} + {cone.Cost}"); } }
static void Main(string[] args) { Case menu = new Case(); List <Flavor> availableFlavors = menu.Flavors; List <Cone> availableCones = menu.Cones; // TODO: Use a Comparer class to sort the 'flavors' array alphabetically by the 'name' // field. FlavorComparer flavorComparer = new FlavorComparer(); availableFlavors.Sort(flavorComparer); // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost' // field. ConeComparer coneComparer = new ConeComparer(); availableCones.Sort(coneComparer); // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting. foreach (Flavor flavor in availableFlavors) { System.Console.WriteLine(flavor.Name + ": (Allergens: " + String.Join(", ", flavor.Allergens.ToArray()) + ")"); } Console.WriteLine("\n"); foreach (Cone cone in availableCones) { Console.WriteLine(cone.Name + ": " + cone.Cost); } }
static void Main(string[] args) { Case menu = new Case(); List <Flavor> availableFlavors = menu.Flavors; List <Cone> availableCones = menu.Cones; // TODO: Use a Comparer class to sort the 'flavors' array alphabetically by the 'name' // field. FlavorComparer comparer = new FlavorComparer(); availableFlavors.Sort(comparer); // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost' // field. ConeComparer coneCost = new ConeComparer(); availableCones.Sort(coneCost); // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting. Console.WriteLine("Sorted by name:"); foreach (Flavor i in availableFlavors) { Console.WriteLine(i.Name + ": $" + i.Cost); } Console.WriteLine("------------------------"); Console.WriteLine("Sorted by cost:"); foreach (Cone i in availableCones) { Console.WriteLine(i.Name + ": $" + i.Cost); } }
static void Main(string[] args) { Case menu = new Case(); List <Flavor> availableFlavors = menu.Flavors; List <Cone> availableCones = menu.Cones; // TODO: Use a Comparer class to sort the 'flavors' array alphabetically by the 'name' // field. // To sort availableFlavors, Create a new FlavorComparer object FlavorComparer comparer1 = new FlavorComparer(); availableFlavors.Sort(comparer1); //availableFlavors.Sort(new FlavorComparer()); // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost' // field. ConeComparer comparer2 = new ConeComparer(); availableCones.Sort(comparer2); // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting. Console.WriteLine("Flavors: "); foreach (Flavor f in availableFlavors) { Console.WriteLine(f.Name); } Console.WriteLine("Cones: "); foreach (Cone c in availableCones) { Console.WriteLine(c.Name + ": " + c.Cost); } //Below is bonus: //Console.WriteLine("*****Bonus*****"); //availableFlavors.Sort(new FlavorComparer2()); //Console.WriteLine("Flovors by number of allergens:"); //foreach (Flavor f in availableFlavors) //{ // Console.WriteLine(f.Name +": "); // foreach (String allergen in f.Allergens) // { // Console.WriteLine(allergen); // } //} }
static void Main(string[] args) { Case menu = new Case(); List <Flavor> availableFlavors = menu.Flavors; List <Cone> availableCones = menu.Cones; // TODO: Use a Comparer class to sort the 'flavors' array alphabetically by the 'name' // field. //flavors before sorting Console.WriteLine("Unsorted flavors: "); foreach (Flavor item in availableFlavors) { Console.WriteLine(item.Name); } //comparer for flavors FlavorComparer comparer = new FlavorComparer(); availableFlavors.Sort(comparer); //flavors after sorting Console.WriteLine("\nSorted flavors by allergen: "); foreach (Flavor item in availableFlavors) { Console.WriteLine(item.Name); } //cones before sorting Console.WriteLine("\nUnsorted cones: "); foreach (Cone item in availableCones) { Console.WriteLine(item.Name + ": $" + item.Cost); } //comparer for cones ConeComparer anotherComparer = new ConeComparer(); availableCones.Sort(anotherComparer); //comparer for cones after sorting Console.WriteLine("\nSorted cones by price: "); foreach (Cone item in availableCones) { Console.WriteLine(item.Name + ": $" + item.Cost); } // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost' // field. // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting. }
static void Main(string[] args) { Case menu = new Case(); List <Flavor> availableFlavors = menu.Flavors; List <Cone> availableCones = menu.Cones; List <Flavor> b4SortFlavors = menu.Flavors; // TODO: Use a Comparer class to sort the 'flavors' array alphabetically by the 'name' // field. Console.WriteLine("Flavors Before Sort:"); for (int i = 0; i < availableFlavors.Count; i++) { Console.WriteLine(availableFlavors[i].Name); } FlavorComparer comparer = new FlavorComparer(); availableFlavors.Sort(comparer); // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost' // field. Console.WriteLine("\nCones Before Sort:"); for (int i = 0; i < availableCones.Count; i++) { Console.WriteLine(availableCones[i].Name + ": $" + availableCones[i].Cost); } CostComparer coneComparer = new CostComparer(); availableCones.Sort(coneComparer); // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting. //foreach (object item in availableFlavors) //Console.WriteLine("\nFlavors After Sort:"); //for (int i = 0; i < availableFlavors.Count; i++) //{ //Console.WriteLine(availableFlavors[i].Name); //} //FlavorComparer was changed to sort by number of Allergens Console.WriteLine("\nFlavors by Allergen Count"); for (int i = 0; i < availableFlavors.Count; i++) { Console.WriteLine(availableFlavors[i].Name + " " + availableFlavors[i].Allergens.Count); } Console.WriteLine("\nCones After Sort:"); for (int i = 0; i < availableCones.Count; i++) { Console.WriteLine(availableCones[i].Name + ": $" + availableCones[i].Cost); } }
static void Main(string[] args) { Case menu = new Case(); List <Flavor> availableFlavors = menu.Flavors; List <Cone> availableCones = menu.Cones; // TODO: Use a Comparer class to sort the 'flavors' array alphabetically by the 'name' // field. for (int i = 0; i < availableFlavors.Count; i++) { Console.WriteLine(availableFlavors[i].Name); } Console.WriteLine(); FlavorComparer comparer = new FlavorComparer(); availableFlavors.Sort(comparer); for (int i = 0; i < availableFlavors.Count; i++) { Console.WriteLine(availableFlavors[i]); } Console.WriteLine(); // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost' // field. for (int i = 0; i < availableCones.Count; i++) { Console.WriteLine(availableCones[i].Name); } Console.WriteLine(); ConeComparer comparer2 = new ConeComparer(); availableCones.Sort(comparer2); for (int i = 0; i < availableCones.Count; i++) { Console.WriteLine(availableCones[i].Name + " Cost: " + availableCones[i].Cost); } Console.WriteLine(); // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting. }
static void Main(string[] args) { Case menu = new Case(); List <Flavor> availableFlavors = menu.Flavors; List <Cone> availableCones = menu.Cones; FlavorComparer comparer = new FlavorComparer(); ConeComparer comparer2 = new ConeComparer(); /*foreach (Flavor flav in availableFlavors) * { * Console.WriteLine(flav); * } * availableFlavors.Sort(comparer); * foreach(Flavor flav in availableFlavors) * { * Console.WriteLine(flav); * }*/ /*foreach(Cone con in availableCones) * { * Console.WriteLine(con); * } * availableCones.Sort(comparer2); * foreach(Cone con in availableCones) * { * Console.WriteLine(con); * }*/ foreach (Flavor flav in availableFlavors) { Console.WriteLine(flav); } availableFlavors.Sort(comparer); foreach (Flavor flav in availableFlavors) { Console.WriteLine(flav); } // TODO: Use a Comparer class to sort the 'flavors' array alphabetically by the 'name' // field. // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost' // field. // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting. }
static void Main(string[] args) { Case menu = new Case(); List <Flavor> availableFlavors = menu.Flavors; List <Cone> availableCones = menu.Cones; // TODO: Use a Comparer class to sort the 'flavors' array alphabetically by the 'name' // field. FlavorComparer comparer = new FlavorComparer(); availableFlavors.Sort(comparer); for (int i = 0; i < availableFlavors.Count; i++) { Console.WriteLine(availableFlavors[i]); } // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost' // field. ConeComparer comparer2 = new ConeComparer(); availableCones.Sort(comparer2); // availableCones.Sort((x, y) => x.Cost.CompareTo(y.Cost)); //How moe would do it... // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting. for (int i = 0; i < availableCones.Count; i++) { Console.WriteLine(availableCones[i].ToString()); } }
static void Main(string[] args) { Case menu = new Case(); List <Flavor> availableFlavors = menu.Flavors; List <Cone> availableCones = menu.Cones; // TODO: Use a Comparer class to sort the 'flavors' array alphabetically by the 'name' // field. FlavorComparer comparer = new FlavorComparer(); availableFlavors.Sort(comparer); //could also have done this: availableFlavors.Sort(new FlavorComparer()); // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost' // field. availableCones.Sort(new ConeComparer()); // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting. Console.WriteLine(menu.ToString()); }
static void Main(string[] args) { Case menu = new Case(); List <Flavor> availableFlavors = menu.Flavors; List <Cone> availableCones = menu.Cones; // TODO: Use a Comparer class to sort the 'flavors' array alphabetically by the 'name' // field. FlavorComparer comparer = new FlavorComparer(); availableFlavors.Sort(comparer); // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost' // field. availableCones.Sort(new ConeComparer()); // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting. foreach (Flavor f in availableFlavors) { Console.WriteLine(f.ToString() + "\n"); foreach (string a in f.Allergens) { Console.WriteLine(" * " + a); } Console.WriteLine("\n"); } foreach (Cone c in availableCones) { foreach (string a in c.Allergens) { Console.WriteLine(c.ToString() + a + "\n"); } } }