c# - How to write a method that prints out a list of days an entree will be served based on user input? -


i know may lots of down votes this, i'm little alright in c#, still have while go. id appreciate if me. application contained in class called dailymenu. class has these fields:

public class dailymenu {     private string day = "";     private int date = 0;     public string entree { get; private set; }     private double price;     private double calories;     static int initaldate = 1;     static string[] daysofweek = { "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" };     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",         "fajitas", "bacon cheeseburger", " beef burgandy", "spagehetti"};     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 };     static int[] entreemealcaloricval = { 999, 1288, 770, 699, 450, 999, 1500, 873, 911, 1011, 777, 500 };  

these properties:

public string day {     { return day; }     set { day = value; } } public int date {     { return date; }     set { date = value; } } public string entree {     { return entree; }     set { entree = value; } } public double price {     { return price; }     set { price = value; } } public double calories {     { return calories; }     set { calories = value; } } 

next, had create objects of dailymenu class in main method.

public static void main(string[] args) {     dailymenu[,] daysofmonth = new dailymenu[4, 5];     (int column = 0; column < daysofmonth.getlength(0); column++)     {         (int row = 0; row < daysofmonth.getlength(1); row++)         {             dailymenu dm = new dailymenu();             daysofmonth[column, row] = dm;             console.writeline(dm.tostring());         }     } } 

and now, trying come function after user enters in 1 of above entrees, console print out days in entree entered served on. takes 2d array argument. i've come far.

static void entreesearch(dailymenu[,] daysofmonth) {     console.writeline("please enter entree you'd search today :)");     string response = console.readline();     response = response.toupper();      (int column = 0; column < daysofmonth.getlength(0); column++)     {         (int row = 0; row < daysofmonth.getlength(1); row++)         {             if (response ==)             {                 dailymenu dm = new dailymenu();                 daysofmonth[column, row] = dm;                 console.writeline(dm.tostring());             }          }     } 

well need fill in day has entree. initializing default values, every single day's entree null. once fix that, should work:

    static void entreesearch(dailymenu [,] daysofmonth)     {         console.writeline ("please enter entree you'd search today :)");         string response = console.readline ();         response = response.toupper ();          (int column = 0; column < daysofmonth.getlength(0); column++)          {             (int row = 0; row < daysofmonth.getlength(1); row++)              {                 dailymenu dailymenuatthisrowandcolumn = daysofmonth[column, row];                 if (dailymenuatthisrowandcolumn.entree.toupper() == response)                 {                      console.writeline($"entree {response} found on day {daysofmonth[column, row].day}");                 }              }         } 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -