private static void ReadToSheep(Dictionary<int, FarmAnimal> allAnimals)
 {
     //read all sheeps
     string _q = "Select * From Sheep";
     OleDbCommand cmd = new OleDbCommand(_q, _fConnection);
     using (OleDbDataReader reader = cmd.ExecuteReader())
     {
         //add to dictionary
         while (reader != null && reader.Read())
         {
             FarmAnimal af = new Sheep(Convert.ToInt32(reader[0]), Convert.ToDouble(reader[1]), Convert.ToInt32(reader[2]), Convert.ToDouble(reader[3]), Convert.ToInt32(reader[4]), Convert.ToString(reader[5]), Convert.ToDouble(reader[6]));
             allAnimals.Add(Convert.ToInt32(reader[0]), af);
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// get average sheep profitability
        /// </summary>
        /// <param name="allAnimals"></param>
        /// <returns></returns>
        public static double AverageSheepProf(Dictionary <int, FarmAnimal> allAnimals)
        {
            double sheep   = 0;
            int    counter = 0;

            foreach (FarmAnimal fa in allAnimals.Values)
            {
                //if is sheep
                if (fa.GetType() == typeof(Sheep))
                {
                    //cast as a sheep
                    Sheep faSheep = (Sheep)fa;
                    //get profitability
                    sheep += faSheep.Profitability();
                    //increase counter
                    counter++;
                }
            }
            //get average
            double averageProfit = sheep / counter;

            return(averageProfit);
        }