Question
using System;
using System.Collections.Generic;
namespace RecipeApp
{
class Recipe
{
public string Name { get; set; }
public List<Ingredient> Ingredients { get; set; }
public List<string> Steps { get; set; }
public void DisplayRecipe()
{
Console.WriteLine("Recipe: " + Name);
Console.WriteLine("Ingredients:");
foreach (var ingredient in Ingredients)
{
Console.WriteLine("- " + ingredient.Name + " - " + ingredient.Quantity + " " + ingredient.Measurement + " - " + ingredient.Calories + " calories - " + ingredient.FoodGroup);
}
Console.WriteLine("\nSteps:");
for (int i = 0; i < Steps.Count; i++)
{
Console.WriteLine((i + 1) + ". " + Steps[i]);
}
}
public double CalculateTotalCalories()
{
double totalCalories = 0;
foreach (var ingredient in Ingredients)
{
totalCalories += ingredient.Calories;
}
return totalCalories;
}
}
class Ingredient
{
public string Name { get; set; }
public double Quantity { get; set; }
public string Measurement { get; set; }
public int Calories { get; set; }
public string FoodGroup { get; set; }
}
class Program
{
static List<Recipe> recipes = new List<Recipe>();
static void Main(string[] args)
{
bool running = true;
while (running)
{
Console.WriteLine("\nMENU:");
Console.WriteLine("1. Add a Recipe");
Console.WriteLine("2. Scale Recipe");
Console.WriteLine("3. Set to Original Recipe");
Console.WriteLine("4. Display Recipes");
Console.WriteLine("5. Exit");
Console.Write("Select an option: ");
int option = Convert.ToInt32(Console.ReadLine());
switch (option)
{
case 1:
Recipe recipe = new Recipe();
Console.Write("Enter the recipe name: ");
recipe.Name = Console.ReadLine();
List<Ingredient> ingredients = new List<Ingredient>();
Console.Write("Enter the number of ingredients: ");
int numIngredients = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < numIngredients; i++)
{
Ingredient ingredient = new Ingredient();
Console.Write("Enter ingredient " + (i + 1) + " name: ");
ingredient.Name = Console.ReadLine();
Console.Write("Enter the quantity " + (i + 1) + ": ");
ingredient.Quantity = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the measurement " + (i + 1) + " (cup, Kg, ml, L, g): ");
ingredient.Measurement = Console.ReadLine();
Console.Write("Enter the number of calories for " + ingredient.Name + ": ");
ingredient.Calories = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the food group for " + ingredient.Name + ": ");
ingredient.FoodGroup = Console.ReadLine();
ingredients.Add(ingredient);
}
recipe.Ingredients = ingredients;
Console.Write("\nEnter the number of steps: ");
int numSteps = Convert.ToInt32(Console.ReadLine());
List<string> steps = new List<string>();
for (int i = 0; i < numSteps; i++)
{
Console.Write("Enter step " + (i + 1) + ": ");
steps.Add(Console.ReadLine());
}
recipe.Steps = steps;
recipes.Add(recipe);
break;
case 2:
// Scale Recipe
break;
case 3:
// Set to Original Recipe
break;
case 4:
DisplayRecipes();
break;
case 5:
running = false;
break;
default:
Console.WriteLine("Invalid option. Please try again.");
break;
}
}
}
static void DisplayRecipes()
{
if (recipes.Count == 0)
{
Console.WriteLine("No recipes available. Please add a recipe first.");
}
else
{
Console.WriteLine("Recipes:");
foreach (var recipe in recipes)
{
Console.WriteLine("- " + recipe.Name);
}
Console.Write("Enter the number of the recipe to display: ");
int recipeIndex = Convert.ToInt32(Console.ReadLine());
if (recipeIndex >= 1 && recipeIndex <= recipes.Count)
{
Recipe selectedRecipe = recipes[recipeIndex - 1];
selectedRecipe.DisplayRecipe();
double totalCalories = selectedRecipe.CalculateTotalCalories();
Console.WriteLine("\nTotal Calories: " + totalCalories);
if (totalCalories > 300)
{
Console.WriteLine("Warning: Total Calories exceed 300.");
}
}
else
{
Console.WriteLine("Invalid recipe number. Please try again.");
}
}
}
}
}
create unit test to test the total calorie calculation
using System.Collections.Generic;
namespace RecipeApp
{
class Recipe
{
public string Name { get; set; }
public List<Ingredient> Ingredients { get; set; }
public List<string> Steps { get; set; }
public void DisplayRecipe()
{
Console.WriteLine("Recipe: " + Name);
Console.WriteLine("Ingredients:");
foreach (var ingredient in Ingredients)
{
Console.WriteLine("- " + ingredient.Name + " - " + ingredient.Quantity + " " + ingredient.Measurement + " - " + ingredient.Calories + " calories - " + ingredient.FoodGroup);
}
Console.WriteLine("\nSteps:");
for (int i = 0; i < Steps.Count; i++)
{
Console.WriteLine((i + 1) + ". " + Steps[i]);
}
}
public double CalculateTotalCalories()
{
double totalCalories = 0;
foreach (var ingredient in Ingredients)
{
totalCalories += ingredient.Calories;
}
return totalCalories;
}
}
class Ingredient
{
public string Name { get; set; }
public double Quantity { get; set; }
public string Measurement { get; set; }
public int Calories { get; set; }
public string FoodGroup { get; set; }
}
class Program
{
static List<Recipe> recipes = new List<Recipe>();
static void Main(string[] args)
{
bool running = true;
while (running)
{
Console.WriteLine("\nMENU:");
Console.WriteLine("1. Add a Recipe");
Console.WriteLine("2. Scale Recipe");
Console.WriteLine("3. Set to Original Recipe");
Console.WriteLine("4. Display Recipes");
Console.WriteLine("5. Exit");
Console.Write("Select an option: ");
int option = Convert.ToInt32(Console.ReadLine());
switch (option)
{
case 1:
Recipe recipe = new Recipe();
Console.Write("Enter the recipe name: ");
recipe.Name = Console.ReadLine();
List<Ingredient> ingredients = new List<Ingredient>();
Console.Write("Enter the number of ingredients: ");
int numIngredients = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < numIngredients; i++)
{
Ingredient ingredient = new Ingredient();
Console.Write("Enter ingredient " + (i + 1) + " name: ");
ingredient.Name = Console.ReadLine();
Console.Write("Enter the quantity " + (i + 1) + ": ");
ingredient.Quantity = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the measurement " + (i + 1) + " (cup, Kg, ml, L, g): ");
ingredient.Measurement = Console.ReadLine();
Console.Write("Enter the number of calories for " + ingredient.Name + ": ");
ingredient.Calories = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the food group for " + ingredient.Name + ": ");
ingredient.FoodGroup = Console.ReadLine();
ingredients.Add(ingredient);
}
recipe.Ingredients = ingredients;
Console.Write("\nEnter the number of steps: ");
int numSteps = Convert.ToInt32(Console.ReadLine());
List<string> steps = new List<string>();
for (int i = 0; i < numSteps; i++)
{
Console.Write("Enter step " + (i + 1) + ": ");
steps.Add(Console.ReadLine());
}
recipe.Steps = steps;
recipes.Add(recipe);
break;
case 2:
// Scale Recipe
break;
case 3:
// Set to Original Recipe
break;
case 4:
DisplayRecipes();
break;
case 5:
running = false;
break;
default:
Console.WriteLine("Invalid option. Please try again.");
break;
}
}
}
static void DisplayRecipes()
{
if (recipes.Count == 0)
{
Console.WriteLine("No recipes available. Please add a recipe first.");
}
else
{
Console.WriteLine("Recipes:");
foreach (var recipe in recipes)
{
Console.WriteLine("- " + recipe.Name);
}
Console.Write("Enter the number of the recipe to display: ");
int recipeIndex = Convert.ToInt32(Console.ReadLine());
if (recipeIndex >= 1 && recipeIndex <= recipes.Count)
{
Recipe selectedRecipe = recipes[recipeIndex - 1];
selectedRecipe.DisplayRecipe();
double totalCalories = selectedRecipe.CalculateTotalCalories();
Console.WriteLine("\nTotal Calories: " + totalCalories);
if (totalCalories > 300)
{
Console.WriteLine("Warning: Total Calories exceed 300.");
}
}
else
{
Console.WriteLine("Invalid recipe number. Please try again.");
}
}
}
}
}
create unit test to test the total calorie calculation
Answers
There are no human answers yet.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.