For this exercise you are asked to complete the provided CalorieCounter program. This program reads from a two-dimensional array showing the calories consumed during various meals throughout the week and presents some statistics and tables from this data.
You are to complete these three methods to get the program working:
When these three methods have been completed, your program should produce the following output: see image.
Make sure that you display the results in the same format as the above image so that 1000.809 displays as 1,000. This can be done using the formatting methods (https://docs.microsoft.com/en-us/dotnet/standard/base- types/composite-formatting) previously introduced with the 'N' format specifier (an example is provided in the sample code)
While the provided program does contain a Main() method, this is for your convenience in developing and testing your functions. The AMS will test your CalculateAverageByMeal(), DisplayMealAverage() and DisplayAverageCaloriesPerMeal() methods directly, which means they must be public.
Sample Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CalorieCounter {
class Program {
const int DAYS_IN_WEEK = 7;
const int MEALS_IN_DAY = 3;
static string[] DaysOfWeek = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "
Saturday", "Sunday" };
static string[] MealsOfDay = { "Breakfast", "Lunch", "Dinner" };
static void Main(string[] args) {
int[,] calories = {{900, 750, 1020 },
{300, 1000, 2700 },
{500, 700, 2100 },
{400, 900, 1780 },
{600, 1200, 1100},
{575, 1150, 1900 },
{600, 1020, 1700 } };
double[] dailyAverage = new double [DAYS_IN_WEEK];
double[] mealAverage = new double[MEALS_IN_DAY];
Welcome();
dailyAverage = CalculateAverageByDay(calories);
mealAverage = CalculateAverageByMeal(calories);
DisplayDailyAverage(dailyAverage);
DisplayMealAverage(mealAverage);
DisplayAverageCaloriesPerMeal(calories);
ExitProgram();
}//end Main
static double [] CalculateAverageByDay(int[,] calories) {
int totalByDay = 0;
double [] dailyAverage = new double[DAYS_IN_WEEK];
for(int row = 0; row < DAYS_IN_WEEK; row++) {
for (int column = 0; column < MEALS_IN_DAY; column++) {
totalByDay = totalByDay + calories[row, column];
}
dailyAverage[row] = (double) totalByDay / MEALS_IN_DAY;
totalByDay = 0;
}//end for (int row ...)
return dailyAverage;
}//end CalculateAverageByDay
static void DisplayDailyAverage(double [] dailyAverage) {
int dayNumber = 0;
Console.WriteLine("t Daily Averagesn");
foreach (double average in dailyAverage) {
Console.WriteLine("t{0, -12}: {1, 6:N0}n", DaysOfWeek[dayNumber], average);
dayNumber++;
}//end foreach
}// end DisplayDailyAverage
public static double [] CalculateAverageByMeal(int[,] calories) {
int totalByMeals = 0;
double[] mealAverage = new double[MEALS_IN_DAY];
// Calculate the average number of calories per meal
return mealAverage;
}//end CalculateAverageByMeal
public static void DisplayMealAverage(double [] mealAverage) {
Console.WriteLine("nnt Average per Mealn");
// Output the average number of calories per meal
}//end DisplayMealAverage
public static void DisplayAverageCaloriesPerMeal(int[,] calories) {
int totalCalories = 0;
// Calculate the total number of calories consumed in a week
// Output the average calories per meal
}//end DisplayAverageCaloriesPerMeal
static void Welcome() {
Console.WriteLine("nnt Welcome to Calorie Counternn");
}//end Welcome
static void ExitProgram() {
Console.Write("Press enter to exit ...");
Console.ReadLine();
}//end ExitProgram
}//end class
}