Search code examples
c#monodevelop

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


I know i may get lots of down votes for this, but I'm just a little alright in c#, but still have a while to go. Id really appreciate if someone could help me. My application is mostly a contained in a class called dailyMenu. The 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 are my properties:

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 double Calories
{
    get { return calories; }
    set { calories = value; }
}

Next, I had to create objects of my dailymenu class in my main method.

public static void Main(string[] args)
{
    dailyMenu[,] daysOfMonth = new dailyMenu[4, 5];
    for (int column = 0; column < daysOfMonth.GetLength(0); column++)
    {
        for (int row = 0; row < daysOfMonth.GetLength(1); row++)
        {
            dailyMenu dm = new dailyMenu();
            daysOfMonth[column, row] = dm;
            Console.WriteLine(dm.ToString());
        }
    }
}

And now, i am trying to come up with a function that after the user enters in one of the above entrees, the console will print out all days in which the entree that was entered will be served on. It also takes a 2D array as an argument. This is what I've come up with so far.

static void entreeSearch(dailyMenu[,] daysOfMonth)
{
    Console.WriteLine("PLease enter the entree you'd like to search for today :)");
    string response = Console.ReadLine();
    response = response.ToUpper();

    for (int column = 0; column < daysOfMonth.GetLength(0); column++)
    {
        for (int row = 0; row < daysOfMonth.GetLength(1); row++)
        {
            if (response ==)
            {
                dailyMenu dm = new dailyMenu();
                daysOfMonth[column, row] = dm;
                Console.WriteLine(dm.ToString());
            }

        }
    }

Solution

  • Well you need to fill in what day has what entree. Currently you are initializing to default values, so every single day's entree is null. But once you fix that, this should work:

        static void entreeSearch(dailyMenu [,] daysOfMonth)
        {
            Console.WriteLine ("PLease enter the entree you'd like to search for today :)");
            string response = Console.ReadLine ();
            response = response.ToUpper ();
    
            for (int column = 0; column < daysOfMonth.GetLength(0); column++) 
            {
                for (int row = 0; row < daysOfMonth.GetLength(1); row++) 
                {
                    dailyMenu dailyMenuAtThisRowAndColumn = daysOfMonth[column, row];
                    if (dailyMenuAtThisRowAndColumn.Entree.ToUpper() == response)
                    {
                         Console.WriteLine($"Entree {response} was found on day {daysOfMonth[column, row].Day}");
                    }
    
                }
            }