Passing my 2D array as an arguement and printing all days on which an entree wil be served based on the entree entered?


/ Published in: C#
Save to your folder(s)

I am trying to write a function that accepts my 2d array as an argument , and allows my user to enter an entrée to search for . i then print out all the days that that entree is being served on.


Copy this code and paste it in your HTML
  1. class MainClass
  2. {
  3. public static void Main (string[] args)
  4. {
  5. dailyMenu [,] daysOfMonth = new dailyMenu[4,5];
  6. for (int column = 0; column < daysOfMonth.GetLength(0); column++)
  7. {
  8. for (int row = 0; row < daysOfMonth.GetLength(1); row++)
  9. {
  10. dailyMenu dm = new dailyMenu ();
  11. daysOfMonth[column,row] = dm;
  12. Console.WriteLine (dm.ToString ());
  13. }
  14. }
  15. }
  16.  
  17. public class dailyMenu
  18. {
  19. private string day="";
  20. private int date = 0;
  21. public string entree {get; private set;}
  22. private double price;
  23. private double calories;
  24. static int initalDate=1;
  25. static string [] daysOfWeek= {"Monday","Tuesday","Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
  26. static string[] entrees = {"Beef Tenderloin Fresco", "Madagascar Filet Mignon", "Filet Mignon", " Lobster Ravioli", "Asian Infused Braised Beef", "New Age Chicken Cordon Bleu", "Short Ribs", " Beef Wellington",
  27. "Fajitas", "Bacon Cheeseburger", " Beef Burgandy", "Spagehetti"};
  28. static double [] entreePrices= { 5.99,7.99,6.99,4.50,9.99,10.29,5.67,8.99, 3.99,4.78,10,79,6.98};
  29. static int[] entreeMealCaloricVal= { 999,1288,770,699,450,999,1500,873, 911,1011, 777,500};
  30.  
  31. public dailyMenu()
  32. {
  33. assignDate();
  34. GetDay();
  35. RandPopulate();
  36. }
  37. void assignDate()
  38. {
  39. date = initalDate;
  40. initalDate++;
  41. if (GetDay()== daysOfWeek[4])
  42. {
  43. initalDate += 2;
  44. }
  45. }
  46. void RandPopulate()
  47. {
  48. Random random = new Random();
  49. int randomNumber = random.Next(0,12);
  50. entree = entrees [randomNumber];
  51. price = entreePrices [randomNumber];
  52. calories = entreeMealCaloricVal [randomNumber];
  53. }
  54. public string GetDay()
  55. {
  56. return daysOfWeek [(date % 7)-1];
  57. }
  58. public string Day
  59. {
  60. get{ return day;}
  61. set{day = value; }
  62. }
  63. public int Date
  64. {
  65. get{ return date; }
  66. set{ date = value; }
  67. }
  68. public string Entree
  69. {
  70. get{ return entree; }
  71. set{ entree = value; }
  72. }
  73. public double Price
  74. {
  75. get{ return price; }
  76. set{ price = value; }
  77. }
  78. public double Calories
  79. {
  80. get{ return calories; }
  81. set{ calories = value; }
  82. }
  83. public override string ToString ()
  84. {
  85. return string.Format ("Day of week: " + GetDay() + ", Entree: " + entree + ", Price: " + price + ", Calories: " + calories);
  86. }
  87. public string [] GetEntreeWeekDays()
  88. {
  89.  
  90. }
  91. static void entreeSearch(dailyMenu [,] entrees)
  92. {
  93. Console.WriteLine ("PLease enter the entree you'd like to search for today :)");
  94. string response = Console.ReadLine ();
  95. response = response.ToUpper ();
  96. for(int count=0; count<
  97. dailyMenu dm = entrees
  98. if (dm == null)
  99.  
  100. return;
  101. string[] weekDays = dm.GetEntreeWeekDays();
  102.  
  103.  
  104. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.