Esempio n. 1
0
        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;
            FlavorComparer comparer         = new FlavorComparer();
            ConeComparer   compareCones     = new ConeComparer();

            // TODO: Use a Comparer class to sort the 'flavors' array alphabetically by the 'name' field.
            availableFlavors.Sort(comparer);

            // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost'
            //  field.
            availableCones.Sort(compareCones);

            // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting.

            foreach (Cone c in availableCones)
            {
                Console.WriteLine(c);
            }

            foreach (Flavor f in availableFlavors)
            {
                Console.WriteLine(f);
            }
        }
Esempio n. 3
0
        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 coneComparer = new ConeComparer();

            availableCones.Sort(coneComparer);

            availableCones.Sort((x, y) => x.Cost.CompareTo(y.Cost));

            // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting.
            foreach (var flavor in availableFlavors)
            {
                Console.WriteLine(flavor.Name);
            }
            foreach (var cone in availableCones)
            {
                Console.WriteLine($"{cone.Name}: {cone.Cost} ");
            }
        }
Esempio n. 4
0
        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();
            // TODO: Use a Comparator class to sort the 'cones' array in increasing order by the 'cost'
            //  field.
            //for (int i = 0; i < availableFlavors.Count; i++)
            //{
            //    Console.WriteLine(availableFlavors[i].Name);
            //}
            //availableFlavors.Sort(comparer);

            //for (int i = 0; i < availableFlavors.Count; i++)
            //{
            //    Console.WriteLine(availableFlavors[i].Name);
            //}

            // TODO: Print the 'flavors' and 'cones' lists (in a clear manner) to verify the sorting.
            ConeComparer comparer = new ConeComparer();

            availableCones.Sort(comparer);
            for (int i = 0; i < availableCones.Count; i++)
            {
                Console.WriteLine(availableCones[i]);
            }
        }
        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.
        }