static void Main(string[] args)
        {
            List <ClassicCar> carList = new List <ClassicCar>();

            populateData(carList);

            // How many cars are in the collection? Use count property
            Console.WriteLine("Total number of cars is: {0}", carList.Count);

            // How many Fords are there?
            ClassicCar car = carList.Find(x => x.m_Make.Equals("Ford"));

            if (car != null)
            {
                Console.WriteLine("There are {0} Fords", car.m_Make.Length);
            }



            // What is the most valuable car?
            ClassicCarComparer carComparer = new ClassicCarComparer();

            carList.Sort(carComparer);

            foreach (ClassicCar c in carList)
            {
                // Console.WriteLine($"{c.m_Make} {c.m_Value}");
                if (c.m_Value == carList.Max(i => i.m_Value))
                {
                    Console.WriteLine($"{c.m_Make} {c.m_Value}");
                }
            }


            // What is the entire collection worth?
            carList.ForEach(TotalCollectionWorth);
            Console.WriteLine("Total collection worth is: {0}", total);

            // How many unique manufacturers are there?
            Dictionary <string, bool> makes = new Dictionary <string, bool>();

            foreach (ClassicCar c in carList)
            {
                try
                {
                    makes.Add(c.m_Make, true);
                }
                catch (Exception e)
                {
                }

                ;
            }
            Console.WriteLine("The collection contains {0} unique manufacturers", makes.Keys.Count);


            Console.WriteLine("\nHit Enter key to continue...");
            Console.ReadLine();
        }
Esempio n. 2
0
 static bool FindFords(ClassicCar car)
 {
     if (car.m_Make == "Ford")
     {
         return(true);
     }
     return(false);
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            List <ClassicCar> carList = new List <ClassicCar>();

            populateData(carList);

            // How many cars are in the collection?
            Console.WriteLine($"There are {carList.Count} cars in the list.");


            // How many Fords are there?
            List <ClassicCar> fordList = carList.FindAll(FindFords);

            Console.WriteLine($"There are {fordList.Count} Fords in the list");


            // What is the most valuable car?
            ClassicCar mostValCar = null;
            int        highValue  = 0;

            foreach (ClassicCar c in carList)
            {
                if (c.m_Value > highValue)
                {
                    mostValCar = c;
                    highValue  = c.m_Value;
                }
            }
            Console.WriteLine($"The most expensive car is {mostValCar.m_Make}, {mostValCar.m_Model}, { mostValCar.m_Year} and it costs { mostValCar.m_Value}.");

            // What is the entire collection worth?
            int totalVal = 0;

            foreach (ClassicCar c in carList)
            {
                totalVal += c.m_Value;
            }
            Console.WriteLine($"Total value is {totalVal}");


            // How many unique manufacturers are there?
            Dictionary <string, bool> makes = new Dictionary <string, bool>();

            foreach (ClassicCar c in carList)
            {
                try
                {
                    makes.Add(c.m_Make, true);
                }
                catch (Exception e) { }
            }
            Console.WriteLine($"There are {makes.Keys.Count} unique manufacturers.");

            Console.WriteLine("\nHit Enter key to continue...");
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            List <ClassicCar> carList = new List <ClassicCar>();

            populateData(carList);

            // How many cars are in the collection?
            Console.WriteLine("There are {0} cars in the entire collection. \n", carList.Count);

            // How many Fords are there?
            List <ClassicCar> fordList = carList.FindAll(FindFords);

            Console.WriteLine("There are {0} Fords in the entire collection. \n", fordList.Count);

            // What is the most valuable car?
            ClassicCar mostValCar = null;
            int        highValue  = 0;

            foreach (ClassicCar c in carList)
            {
                if (c.m_Value > highValue)
                {
                    mostValCar = c;
                    highValue  = c.m_Value;
                }
            }
            Console.WriteLine("The most valuable car is a {0} {1} {2} at ${3}\n",
                              mostValCar.m_Year, mostValCar.m_Make, mostValCar.m_Model, mostValCar.m_Value);

            // What is the entire collection worth?
            int totalValue = 0;

            foreach (ClassicCar c in carList)
            {
                totalValue += c.m_Value;
            }
            Console.WriteLine("The collection is worth ${0}\n", totalValue);

            // How many unique manufacturers are there?
            Dictionary <string, bool> makes = new Dictionary <string, bool>();

            foreach (ClassicCar c in carList)
            {
                try
                {
                    makes.Add(c.m_Make, true);
                }
                catch (Exception e) { }
            }

            Console.WriteLine("\nHit Enter key to continue...");
            Console.ReadLine();
        }
 static void TotalCollectionWorth(ClassicCar car)
 {
     total += car.m_Value;
 }
Esempio n. 6
0
        static void Main(string[] args)
        {
            List <ClassicCar> carList = new List <ClassicCar>();

            populateData(carList);

            //MY ANSWER

            // How many cars are in the collection?
            Console.WriteLine("There are {0} cars in the entire collection.", carList.Count);

            // How many Fords are there?
            int countFord = carList.Count(x => x.m_Make.Equals("Ford"));

            Console.WriteLine("There are {0} Fords in the collection", countFord);

            // What is the most valuable car?

            ClassicCar c = carList.Find(x => x.m_Value.Equals(carList.Max(y => y.m_Value)));

            Console.WriteLine("The most Valuable Car is a {0} {1} {2} at ${3}", c.m_Year, c.m_Make, c.m_Model, c.m_Value);
            // What is the entire collection worth?
            double sum = carList.Sum(x => x.m_Value);

            Console.WriteLine("The collection is worth ${0}", sum);
            // How many unique manufacturers are there?
            int m = (from x in carList
                     select x.m_Make).Distinct().Count();

            Console.WriteLine("The collection has {0} unique manufacturers", m);

            Console.WriteLine("\nHit Enter key to continue...");
            Console.ReadLine();

            /* instructors answers
             *     // How many cars are in the collection?
             * Console.WriteLine("There are {0} cars in the entire collection.\n", carList.Count);
             *
             * // How many Fords are there?
             * List<ClassicCar> fordList = carList.FindAll(FindFords);
             * Console.WriteLine("There are {0} Fords in the entire collection.\n", fordList.Count);
             *
             * // What is the most valuable car?
             * ClassicCar mostValCar = null;
             * int highValue = 0;
             * foreach (ClassicCar c in carList) {
             *  if (c.m_Value > highValue) {
             *      mostValCar = c;
             *      highValue = c.m_Value;
             *  }
             * }
             * Console.WriteLine("The most valuable car is a {0} {1} {2} at ${3}\n",
             *  mostValCar.m_Year, mostValCar.m_Make, mostValCar.m_Model, mostValCar.m_Value);
             *
             *
             * // What is the entire collection worth?
             * int totalValue = 0;
             * foreach (ClassicCar c in carList) {
             *  totalValue += c.m_Value;
             * }
             * Console.WriteLine("The collection is worth ${0}\n", totalValue);
             *
             * // How many unique manufacturers are there?
             * Dictionary<string, bool> makes = new Dictionary<string, bool>();
             * foreach (ClassicCar c in carList) {
             *  try {
             *      makes.Add(c.m_Make, true);
             *  }
             *  catch (Exception e) { }
             * };
             * Console.WriteLine("The collection contains {0} unique manufacturers.\n", makes.Keys.Count);
             *
             *
             * Console.WriteLine("\nHit Enter key to continue...");
             * Console.ReadLine();
             */
        }