public StockStatistics ComputeStatistics() { StockStatistics stats = new StockStatistics(); float sum = 0; foreach (float stock in stocks) { stats.HighestStock = Math.Max(stock, stats.HighestStock); stats.LowestStock = Math.Min(stock, stats.LowestStock); sum += stock; } stats.AverageStock = sum / stocks.Count; return(stats); }
static void Main(string[] args) { StockPortfolio portfolio = new StockPortfolio(); portfolio.AddStock(1000); portfolio.AddStock(25000); portfolio.AddStock(8500); portfolio.AddStock(2900); portfolio.AddStock(7000); portfolio.AddStock(11700); portfolio.AddStock(9000); StockStatistics stats = portfolio.ComputeStatistics(); Console.WriteLine("The average price is " + stats.AverageStock); Console.WriteLine("The highest price is " + stats.HighestStock); Console.WriteLine("The lowest price is " + stats.LowestStock); }