/* * Calculate the feeding cost as follows: * feedingCost = foodPricePerKg * amountOfFoodNeeded * */ public double CalculateAnimalFeedingCost(ZooContentInfo zooContentInfo) { RateInfo rateInfo = GetRateInfoForAnimal(zooContentInfo.animalType); // foodPricePerKg var meatPricePerKg = Double.Parse(GetFoodPricePerKg(Food.Meat.ToString()), CultureInfo.InvariantCulture); var fruitPricePerKg = Double.Parse(GetFoodPricePerKg(Food.Fruit.ToString()), CultureInfo.InvariantCulture); // carnivore if (rateInfo.foodType.Equals(Carnivore.foodType.ToLower())) { Carnivore carnivore = new Carnivore(zooContentInfo.animalType, zooContentInfo.name, zooContentInfo.weight); var amountOfFoodNeeded = carnivore.CalculateAmountOfFoodNeeded(rateInfo); var feedingCost = meatPricePerKg * amountOfFoodNeeded; totalFeedingCost = totalFeedingCost + feedingCost; Console.Write("\t\t\t\t" + Carnivore.foodType + "\t\t" + meatPricePerKg + "\t\t" + amountOfFoodNeeded + "Kg" + "\t\t" + meatPricePerKg + " * " + amountOfFoodNeeded + " = " + feedingCost + "\t\t" + "\n"); return(feedingCost); } // herbivore if (rateInfo.foodType.Equals(Herbivore.foodType.ToLower())) { Herbivore herbivore = new Herbivore(zooContentInfo.animalType, zooContentInfo.name, zooContentInfo.weight); var amountOfFoodNeeded = herbivore.CalculateAmountOfFoodNeeded(rateInfo); var feedingCost = fruitPricePerKg * amountOfFoodNeeded; totalFeedingCost = totalFeedingCost + feedingCost; Console.Write("\t\t\t\t" + Herbivore.foodType + "\t\t" + fruitPricePerKg + "\t\t" + amountOfFoodNeeded + "Kg" + "\t\t" + fruitPricePerKg + " * " + amountOfFoodNeeded + " = " + feedingCost + " " + "\t\t" + "\n"); return(feedingCost); } // omnivore if (rateInfo.foodType.Equals(Omnivore.foodType.ToLower())) { Omnivore omnivore = new Omnivore(zooContentInfo.animalType, zooContentInfo.name, zooContentInfo.weight); // meat rateInfo.foodType = Food.Meat.ToString(); var amountOfMeatNeeded = omnivore.CalculateAmountOfFoodNeeded(rateInfo); var feedingCostMeat = meatPricePerKg * amountOfMeatNeeded; totalFeedingCost = totalFeedingCost + feedingCostMeat; Console.Write("\t\t\t\t" + Food.Meat.ToString() + "\t\t" + meatPricePerKg + "\t\t" + amountOfMeatNeeded + "Kg" + "\t\t" + meatPricePerKg + " * " + amountOfMeatNeeded + " = " + feedingCostMeat + "\t\t" + "\n"); // fruit rateInfo.foodType = Food.Fruit.ToString(); var amountOfFruitNeeded = omnivore.CalculateAmountOfFoodNeeded(rateInfo); var feedingCostFruit = fruitPricePerKg * amountOfFruitNeeded; //var feedingCost = feedingCostFruit + feedingCostMeat; totalFeedingCost = totalFeedingCost + feedingCostFruit; Console.Write("\t\t\t\t" + Food.Fruit.ToString() + "\t\t" + fruitPricePerKg + "\t\t" + amountOfFruitNeeded + "Kg" + "\t\t" + fruitPricePerKg + " * " + amountOfFruitNeeded + " = " + feedingCostFruit + "\t\t" + "\n"); return(feedingCostFruit + feedingCostMeat); } return(0.0); }
/** * Extract information regarding the content of the zoo from zoo.xml **/ public List <ZooContentInfo> GetZooContent() { XmlReader xmlReader = XmlReader.Create("zoo.xml"); Dictionary <string, ZooContentInfo> dictionary = new Dictionary <string, ZooContentInfo>(); ZooContentInfo zooContentInfo = new ZooContentInfo(); List <ZooContentInfo> zooList = new List <ZooContentInfo>(); while (xmlReader.Read()) { if ((xmlReader.NodeType == XmlNodeType.Element)) { if (xmlReader.HasAttributes) { zooContentInfo = new ZooContentInfo(xmlReader.Name, xmlReader.GetAttribute("name"), Double.Parse(xmlReader.GetAttribute("kg"), CultureInfo.InvariantCulture)); zooList.Add(zooContentInfo); //Console.WriteLine(xmlReader.Name + ": " + xmlReader.GetAttribute("name") + ": " + xmlReader.GetAttribute("kg")); } } } return(zooList); }