Directions: 1. Begin an empty console application. 2. Design a class named daily
ID: 3692745 • Letter: D
Question
Directions:
1. 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 ¬ double 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.
Explanation / Answer
Answer:
//c# code for daily Menu
using System;
using System.IO;
using System;
class daMenu
{
public static void Main (string[] args)
{
dailyMenu [,] daily_Menu = new dailyMenu[4,5];
for (int aa = 0; aa < 4; aa++)
{
for (int bb = 0; bb< 5; bb++)
{
dailyMenu bout = new dailyMenu ();
//display entree for each day
daily_Menu[aa,bb] = bout;
Console.WriteLine (bout.ToString ());
}
}
dailyMenu bt = new dailyMenu ();
//bt.findLowHighCalorie(daily_Menu);
}
//class daily menu
public class dailyMenu
{
private string dayA;
private int dateA;
public string entreeA {get; private set;}
private double priceA;
private double caloriesA;
static int startDate=1;
static string [] strWeekDays= {"Monday","Tuesday","Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
static string[] entrees = {"Pizza","TANDOORI", "BURGER", "Chicken", "Fish","MUTTOn","EGG HAMLET","Brunswick stew","Cajun cuisine","Macaroni salad","Milk toast","Pancakes" };
static double [] entreeCostPrice= { 5,10,20,30,40,35,76,90,51,67,34};
static int[] calorieVal= { 1009,200,750,896,345,78,234,85,};
public dailyMenu()
{
findDate();
wkDay();
populateRandom();
}
void findDate()
{
dateA = startDate;
startDate++;
if (startDate>5)
{
startDate = 1;
}
}
void populateRandom()
{
Random rk = new Random();
int ranNumr = rk.Next(0,13);
entreeA = entrees [ranNumr];
priceA = entreeCostPrice [ranNumr];
caloriesA = calorieVal [ranNumr];
}
public string wkDay()
{
return strWeekDays [(dateA % 7)-1];
}
//SET & GET DAY
public string DayA
{
get{ return dayA;}
set{dayA = value; }
}
//SET & GET DATE
public int DateA
{
get{ return dateA; }
set{ dateA = value; }
}
//SET AND GET ENTREE FOR THE DAY
public string EntreeA
{
get{ return entreeA; }
set{ entreeA = value; }
}
//SET PRICE FOR THE ENTREE FOR THE DAY
public double myPrice
{
get{ return priceA; }
set{ priceA = value; }
}
//SET & GET FOR CLAORIES OT THE ENTREE
public double myCalories
{
get{ return caloriesA; }
set{ caloriesA = value; }
}
//STRING REPRESENTATION OF DAY, ENTREE, CALORIE,PRICE
public override string ToString ()
{
return string.Format ("WEEK DAY: " + wkDay() + ", Entree: " + entreeA + ", Entree Price: " + priceA + ", Entree Calories: " + caloriesA);
}
//SEARCHES ENTREE
public static void entreeSearch(dailyMenu [,] daily_Menu)
{
Console.WriteLine ("Enter Entree to search");
string getResponse = Console.ReadLine ();
getResponse = getResponse.ToUpper ();
for (int aa = 0; aa < daily_Menu.GetLength(0); aa++)
{
for (int bb = 0; bb < daily_Menu.GetLength(1); bb++)
{
dailyMenu temp = daily_Menu[aa, bb];
if (temp.EntreeA.ToUpper() == getResponse)
{
Console.WriteLine($"Entree {getResponse} is available {daily_Menu[aa, bb].DayA}");
}
}
}
}
public static void findLowHighCalorie(dailyMenu [,] daily_Menu)
{
double highCalorie=0;
double lowcalorie=100;
for (int aa = 0; aa < daily_Menu.GetLength(0); aa++)
{
for (int bb = 0; bb < daily_Menu.GetLength(1); bb++)
{
dailyMenu temp = daily_Menu[aa, bb];
if(temp.myCalories>highCalorie)
highCalorie=temp.myCalories;
else if(temp.myCalories<lowcalorie)
lowcalorie=temp.myCalories;
}
}
Console.WriteLine(" lOW CALORIE Entree :{0} ",lowcalorie);
Console.WriteLine(" high CALORIE Entree :{0} ",highCalorie);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.