Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program in C#, for The Cactus Cantina named FoodOrder that accepts a us

ID: 3930075 • Letter: C

Question

Create a program in C#, for The Cactus Cantina named FoodOrder that accepts a user’s choice from the options shown in the accompanying table. Allow the user to enter either an integer item number or a string description. Pass the user’s entry to one of two overloaded GetDetails( ) methods, and then display a returned string with all the order details. The method version that accepts an integer looks up the description and price; the version that accepts a string description looks up the item number and price. The methods return an appropriate message if the item is not found.

Explanation / Answer

using System;
using System.Text;
using System.Collections.Generic;

public class FoodOrder
{
private IList<Item> items = new List<Item>(0);

public static void Main()
{
Console.WriteLine("Welcome to the Cactus Cantina!");
FoodOrder order = new FoodOrder();
Item item = order.Search();
if (item != null) //if / else loop to determine if item is there or not
{
Console.WriteLine(item);
Console.WriteLine("Thank You for ordering at the Cactus Cantina!");
}
else
{
Console.WriteLine("item not found");
}

Console.ReadLine();
}

public FoodOrder()
{
items = BuildItem(); //constructs the items
}

public Item Search()
{
Item item = null;
Console.WriteLine("Enter item number or description? ");
string input = Console.ReadLine();
try //orders the GetDetails methods
{
int itemNum = Convert.ToInt32(input);
item = GetDetails(itemNum);
}
catch
{
item = GetDetails(input);
}
return item;
}

public Item GetDetails(string description) //GetDetails method to determine string if typed
{
Item item = null;
foreach (Item i in this.items)
{
if (i.Description.Equals(description))
{
item = i;
break;
}
}
return item;
}

public Item GetDetails(int itemNum) //GetDetails method to determine int if typed
{
Item item = null;
foreach (Item i in this.items)
{
if (i.ItemNum == itemNum)
{
item = i;
break;
}
}
return item;
}

private static IList<Item> BuildItem()
{
IList<Item> items = new List<Item>(0); //items are added
items.Add(new Item { ItemNum = 20, Description = "Enchilada", Price = 2.95 });
items.Add(new Item { ItemNum = 23, Description = "Burrito", Price = 1.95 });
items.Add(new Item { ItemNum = 25, Description = "Taco", Price = 2.25 });
items.Add(new Item { ItemNum = 31, Description = "Tostada", Price = 3.10 });
return items;
}
}

public class Item
{
public int ItemNum { get; set; } //gets and sets the itemNum, Description, and Price
public string Description { get; set; }
public double Price { get; set; }

public override string ToString() //overrides string to display the items
{
StringBuilder sb = new StringBuilder();
sb.Append(string.Format("Item Num: {0},", this.ItemNum));
sb.Append(string.Format(" Description: {0},", this.Description));
sb.Append(string.Format(" Price: {0:c}", this.Price));
return sb.ToString();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote