Begin an empty console application. 2. Design a class named dailyMenu that has t
ID: 3917165 • Letter: B
Question
Begin an empty console application. 2. Design a class named dailyMenu that has the following attributes. Please take care to use the proper level of visibility: ¬ string day (name of day of the week) ¬ int date (date) ¬ string entrée ¬ double price ¬ int calories 3. Write properties for every instance field. 4. Create a static int variable that you will use to assign the date; initialize the value to 1. 5. Create a static array of strings that hold the days of the week (M-F). 6. Create a static array of strings that hold 12 random entrée items. You may initialize this array with items of your choosing. 7. Create a static parallel array of doubles that contain the price of each entrée. You may initialize this array with values of your choosing. 8. Create a static parallel array of ints that contains the caloric value of each entrée. You may initialize this array with values of your choosing. -------------- 9. Write a parameter-less constructor that uses the following methods to create an array instance of dailyMenu. Note: when you have finished 10, 11, and 12, you’ll need to call them from the constructor. 10. Write a method that assigns the name of the day of the week to the instance. 11. Write a method to assign the current value in the static date variable to instance’s date field. Increment the date. Using a conditional expression, handle incrementation to skip the weekend dates! 12. Write a method to that will choose a random number and then populate the instance’s entrée, price, and calorie fields from those arrays. Take care that your random number generator will not go out of bounds of these arrays! ---------------------------------------- 13. In Main, create a 2D array of 20 days that will hold objects of type day. Your array should contain 4 rows for the weeks and 5 days for each week. 14. Write a loop to populate the 2D array with a dailyMenu object for each day. Due to the automation you’ve created in your class, you should require NO input from your user to do this! Take a look at the Preston tutorial that is shown in the course calendar labeled “Collections of Instances” for help with this part. NOTE: Please use a 2D Array, NOT a List. 15. Output the array to the console, printing the entire array, to look something like this. Note: your printout will enable you to verify the functions you create below. Monday 1 Chicken Nuggets $3.99 280 Calories Wednesday 10 Pizza $5.99 480 Calories 16. Write a function that accepts the 2D array as an argument. Your function should allow your user to enter an entrée to search for. Provide your user with a printout of any and all days on which this entrée will be served. 17. Call function you just wrote from main. 18. Write a function that accepts the 2D array as an argument. Print out the item with the highest caloric value and the lowest caloric value. 19. Call the function you just wrote from main. 20. Write one last function that accepts the 2D array as an argument. Ask the user how much money he has budgeted for lunch per day. Print out a list of items that he can afford to purchase and what days (day and date) those items are available. 21. Call the function that you just wrote from main. In CSharp please explain steps if can.
Explanation / Answer
// Create 3 classes as given below.
// Please find code in bold
// Program.cs
using System;
namespace ConsoleApp
{
class Program
{
static DailyMenu[,] array = new DailyMenu[4, 5];
static void Main(string[] args)
{
Menu menu = new Menu();
int index = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 5; j++)
{
array[i, j] = menu.Items[index];
index++;
}
}
ShowMenu(array);
Console.WriteLine();
FindEntree(array);
Console.WriteLine();
GetCalories(array);
Console.WriteLine();
GetBudgetItems(array);
Console.ReadLine();
}
private static void ShowMenu(DailyMenu[,] items)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 5; j++)
{
Console.WriteLine(items[i, j]);
}
}
}
private static void FindEntree(DailyMenu[,] items)
{
Console.Write("Enter entree to find : ");
string entree = Console.ReadLine();
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 5; j++)
{
DailyMenu item = items[i, j];
if (string.Compare(item.Entree, entree, true) == 0)
{
Console.WriteLine(item);
}
}
}
}
private static void GetCalories(DailyMenu[,] items)
{
int minCal = 0, maxCal = 0;
minCal = items[0, 0].Calories;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 5; j++)
{
DailyMenu item = items[i, j];
if (item.Calories < minCal)
{
minCal = item.Calories;
}
if (item.Calories > maxCal)
{
maxCal = item.Calories;
}
}
}
Console.WriteLine("Min Calory : {0} Max Calory : {1}", minCal, maxCal);
}
private static void GetBudgetItems(DailyMenu[,] items)
{
Console.Write("Enter your budget : ");
string value = Console.ReadLine();
double budget = 0;
if (double.TryParse(value, out budget))
{
Console.WriteLine("Menu Items under your budget : ");
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 5; j++)
{
DailyMenu item = items[i, j];
if (item.Price <= budget)
{
Console.WriteLine(item);
}
}
}
}
else
{
Console.WriteLine("Invalid budget value.");
}
}
}
}
// Menu.cs
using System;
namespace ConsoleApp
{
public class Menu
{
private Random _Random;
private static int _Date = 1;
private static string[] _Days = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
private static string[] _Entrees = new string[] { "Chicken Nuggets", "Pizza", "Pasta", "Falafel", "Bruschetta", "Tacos", "Nachos", "Burger", "Burrito", "Guacamole", "Quesadilla", "Fajita" };
private static double[] _Prices = new double[] { 3.99, 5.99, 2.5, 6.15, 7, 4.44, 5.66, 7.88, 8.77, 1.1, 2.2, 3.3 };
private static int[] _Calories = new int[] { 280, 480, 550, 350, 165, 452, 321, 520, 689, 785, 150, 120 };
public DailyMenu[] Items { get; }
public Menu()
{
_Random = new Random();
Items = new DailyMenu[20];
int day = 0;
for (int index = 0; index < Items.Length; index++)
{
// Skip weekends.
if(day > 4)
{
day = 0;
_Date += 2;
}
Items[index] = new DailyMenu();
AssignNameOfDay(day, Items[index]);
AssignDay(Items[index]);
AssignEntree(Items[index]);
day++;
}
}
private void AssignNameOfDay(int day, DailyMenu item)
{
item.Day = _Days[day];
}
private void AssignDay(DailyMenu item)
{
item.Date = _Date;
_Date++;
}
private void AssignEntree(DailyMenu item)
{
item.Entree = _Entrees[_Random.Next(0, _Entrees.Length - 1)];
item.Price = _Prices[_Random.Next(0, _Prices.Length - 1)];
item.Calories = _Calories[_Random.Next(0, _Calories.Length - 1)];
}
}
}
// DailyMenu.cs
namespace ConsoleApp
{
public class DailyMenu
{
private string day;
private int date;
private string entree;
private double price;
private int calories;
public string Day
{
get
{
return day;
}
set
{
day = value;
}
}
public int Date
{
get
{
return date;
}
set
{
date = value;
}
}
public string Entree
{
get
{
return entree;
}
set
{
entree = value;
}
}
public double Price
{
get
{
return price;
}
set
{
price = value;
}
}
public int Calories
{
get
{
return calories;
}
set
{
calories = value;
}
}
public override string ToString()
{
return $"{Day} {Date} {Entree} ${price} {Calories} calories";
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.