Ejemplo n.º 1
0
 /// <summary>
 /// اضافه کردن ماده اولیه
 /// </summary>
 /// <param name="ingredient">ماده اولیه</param>
 /// <returns>عمل اضافه کردن موفقیت آمیز انجام شد یا خیر. در صورت تکمیل ظرفیت مقدار برگشتی "خیر" میباشد.</returns>
 public bool AddIngredient(Ingredient ingredient)
 {
     ingredients.Add(ingredient);
     return(true);
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            int        RecipeBookCapacity = 20;
            RecipeBook fromMom            = new RecipeBook("دستور پخت های مادر", RecipeBookCapacity);

            ConsoleKeyInfo cki;

            do
            {
                Console.WriteLine($"Press N(ew), D(el), S(earch)or L(ist)");
                cki = Console.ReadKey();
                Console.WriteLine();
                switch (cki.Key)
                {
                case ConsoleKey.N:

                    Console.WriteLine("New Recipe");
                    Console.WriteLine("Enter the title :");
                    string title = Console.ReadLine();
                    Console.WriteLine("Enter the instruction :");
                    string recInstruction = Console.ReadLine();
                    Console.WriteLine("Enter the number of ingredients :");
                    int ingredientCount = int.Parse(Console.ReadLine());
                    Console.WriteLine("Enter the the number of people that this food can feed :");
                    int serCount = int.Parse(Console.ReadLine());
                    Console.WriteLine("Enter the cuisine :");
                    string cuisine = Console.ReadLine();
                    Console.WriteLine("Enter the keywords and separate them with ',' :");
                    string[] keywords = Console.ReadLine().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    Recipe   food     = new Recipe(title, recInstruction, new Ingredient[ingredientCount], serCount, cuisine, keywords);
                    food.Ingredientscount = ingredientCount;
                    for (int i = 0; i < ingredientCount; i++)
                    {
                        Console.WriteLine($"ingredient {i + 1} of {ingredientCount} : ");
                        Console.WriteLine("Enter the name : ");
                        string ingName = Console.ReadLine();
                        Console.WriteLine("Enter the description : ");
                        string description = Console.ReadLine();
                        Console.WriteLine("Enter the quantity : ");
                        double quanty = double.Parse(Console.ReadLine());
                        Console.WriteLine("Enter the unit :");
                        string     unit = Console.ReadLine();
                        Ingredient ing  = new Ingredient(ingName, description, quanty, unit);

                        if (food.AddIngredient(ing))
                        {
                            Console.WriteLine("Ingredient added successfully.");
                        }
                        else
                        {
                            Console.WriteLine("You can't add new ingredient anymore.");
                        }
                    }
                    if (fromMom.Add(food))
                    {
                        RecipeBookCapacity--;
                        Console.WriteLine("This recipe added successfully.");
                        Console.WriteLine($"{RecipeBookCapacity} capacity remaining.");
                    }
                    else
                    {
                        Console.WriteLine("You can't add new recipe anymore.");
                    }
                    break;

                case ConsoleKey.D:

                    Console.WriteLine("Delete Recipe");
                    Console.WriteLine("Enter the title of recipe that you want to delete :");
                    string name = Console.ReadLine();
                    if (fromMom.Remove(name))
                    {
                        Console.WriteLine("Recipe deleted successfully.");
                    }
                    else
                    {
                        Console.WriteLine("Nothing deleted.");
                    }
                    break;

                case ConsoleKey.S:

                    string answer;
                    string SearchWay;
                    Console.WriteLine("Search Recipe");
                    Console.WriteLine("How do you want to find your recipe('t' for title, 'c' for cuisine, 'k' for keyword) :");
                    bool loop = true;
                    do
                    {
                        SearchWay = Console.ReadLine();
                        if (SearchWay == "t")
                        {
                            Console.WriteLine("Enter the title :");
                            answer = Console.ReadLine();
                            Recipe resault = fromMom.LookupByTitle(answer);
                            if (resault != null)
                            {
                                fromMom.ShowDetails(fromMom.LookupByTitle(answer));
                            }
                            else
                            {
                                Console.WriteLine("There is not any recipes with the title that you enter.");
                            }
                            loop = false;
                        }
                        else if (SearchWay == "c")
                        {
                            Console.WriteLine("Enter the cuisine :");
                            answer = Console.ReadLine();
                            Recipe[] array = new Recipe[1];
                            array = fromMom.LookupByCuisine(answer);
                            if (array != null)
                            {
                                for (int i = 0; i < array.Length; i++)
                                {
                                    fromMom.ShowDetails(array[i]);
                                }
                            }
                            else
                            {
                                Console.WriteLine("There is not any recipes with the cuisine that you enter.");
                            }
                            loop = false;
                        }
                        else if (SearchWay == "k")
                        {
                            Console.WriteLine("Enter the keyword :");
                            answer = Console.ReadLine();
                            Recipe[] array = new Recipe[1];
                            array = fromMom.LookupByKeyword(answer);
                            if (array != null)
                            {
                                for (int i = 0; i < array.Length; i++)
                                {
                                    fromMom.ShowDetails(array[i]);
                                }
                            }
                            else
                            {
                                Console.WriteLine("There is not any recipes with the keyword that you enter.");
                            }
                            loop = false;
                        }
                        else
                        {
                            Console.WriteLine("invalid key!! Enter another kay :");
                        }
                    }while (loop == true);
                    break;

                case ConsoleKey.L:

                    Console.WriteLine("List Recipes");
                    for (int i = 0; i < fromMom.Book.Length; i++)
                    {
                        if (fromMom.Book[i] != null)
                        {
                            Console.WriteLine($"recipe {i + 1} : {fromMom.Book[i].Title}");
                        }
                        else if (i == 0)
                        {
                            Console.WriteLine("You didn't add any recipes yet.");
                        }
                    }
                    break;

                case ConsoleKey.Escape:

                    Console.WriteLine("Esc");
                    break;

                default:

                    Console.WriteLine($"Invalid Key: {cki.KeyChar}");
                    break;
                }

                Console.WriteLine("Press any key to continue, Esc to exit");
                cki = Console.ReadKey();
                Console.Clear();
            }while (cki.Key != ConsoleKey.Escape);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //RecipeBook fromMom = new RecipeBook("دستور پخت های مادر", 20);
            ConsoleKeyInfo cki;
            //creating the Recipebook object
            RecipeBook recipeBook       = GetBookInput();
            int        NumberOfRceipies = 0;

            do
            {
                Console.WriteLine($"Press (N)ew, (D)el, (S)earch, (L)ist, sa(V)e or l(O)ad");
                cki = Console.ReadKey();
                Console.WriteLine();
                Recipe recipe;
                switch (cki.Key)
                {
                case ConsoleKey.N:
                    if (NumberOfRceipies < recipeBook.Capacity)
                    {
                        // بر عهده دانشجو
                        recipe = GetRecipeInput();
                        //adding ingredeints
                        for (int i = 0; i < recipe.IngredientCount; i++)
                        {
                            Console.WriteLine($"adding ingredient {i + 1}");
                            Ingredient ingredientTemp = GetIngredientInput();
                            recipe.AddIngredient(ingredientTemp);
                        }
                        do
                        {
                            Console.WriteLine("Do you want to remove an ingredient? Y or N");
                            cki = Console.ReadKey();
                            string nameToDelete = RemoveIngredient();
                            if (cki.Key == ConsoleKey.Y)
                            {
                                recipe.RemoveIngredient(nameToDelete);
                            }
                            else
                            {
                                break;
                            }
                        } while (true);
                        recipeBook.Add(recipe);
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Recipe Book is full!");
                        break;
                    }

                case ConsoleKey.D:
                    Console.WriteLine("Delete Recipe");
                    // بر عهده دانشجو
                    DeleteRecipe(ref recipeBook);
                    break;

                case ConsoleKey.S:
                    Console.WriteLine("Search Recipe");
                    // بر عهده دانشجو
                    Console.WriteLine("Which one do you want to search? \ntitle \nkeyword \ncuisine");
                    string action = ReadAction();
                    switch (action)
                    {
                    case "title":
                        Recipe recipeTitle = RemoveByTitle(recipeBook);
                        cki = Console.ReadKey();
                        switch (cki.Key)
                        {
                        case ConsoleKey.Y:
                            recipeBook.Remove(recipeTitle.title);
                            break;

                        case ConsoleKey.U:
                            recipeTitle.UpdateServingCount(UpdateServingCount());
                            break;

                        default:
                            break;
                        }
                        break;

                    case "keyword":
                        Recipe[] recipeKeyword = RemoveByKeyword(recipeBook);
                        cki = Console.ReadKey();
                        switch (cki.Key)
                        {
                        case ConsoleKey.Y:
                            for (int i = 0; i < recipeKeyword.Length; i++)
                            {
                                recipeBook.Remove(recipeKeyword[i].ToString());
                            }
                            break;

                        default:
                            break;
                        }
                        break;

                    case "cuisine":
                        Recipe[] recipeCuisine = RemoveByCuisine(recipeBook);
                        cki = Console.ReadKey();
                        switch (cki.Key)
                        {
                        case ConsoleKey.Y:
                            for (int i = 0; i < recipeCuisine.Length; i++)
                            {
                                recipeBook.Remove(recipeCuisine[i].title);
                            }
                            break;

                        default:
                            break;
                        }
                        break;

                    default:
                        Console.WriteLine("Wrong entry! \nPlease try again!");
                        break;
                    }
                    break;

                case ConsoleKey.L:
                    Console.WriteLine("List Recipes");
                    // بر عهده دانشجو
                    Console.WriteLine(recipeBook.ToString());
                    break;

                case ConsoleKey.Escape:
                    Console.WriteLine("Esc");
                    break;

                case ConsoleKey.V:
                    recipeBook.Save(RecipeFilePath, ingFilePath);
                    break;

                case ConsoleKey.O:
                    //bool flag = recipeBook.Load(RecipeFilePath,ingFilePath);
                    //if (flag)
                    //{
                    //    Console.WriteLine("Loaded successfuly!");
                    //}
                    //else
                    //{
                    //    Console.WriteLine("Failed to load!");
                    //}
                    LoadRecipes(ref recipeBook, RecipeFilePath, ingFilePath);
                    break;

                default:
                    Console.WriteLine($"Invalid Key: {cki.KeyChar}");
                    break;
                }

                Console.WriteLine("Press any key to continue, Esc to exit");
                cki = Console.ReadKey();
                Console.Clear();
            }while (cki.Key != ConsoleKey.Escape);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            //RecipeBook fromMom = new RecipeBook("دستور پخت های مادر", 20);

            ConsoleKeyInfo cki;

            //creating the Recipebook object
            Console.WriteLine("Enter title of the recipe book:");
            string titleOfTheBook = Console.ReadLine();

            Console.WriteLine("Enter capacity of the recipe book:");
            int        capacity         = int.Parse(Console.ReadLine());
            RecipeBook recipeBook       = new RecipeBook(titleOfTheBook, capacity);
            int        NumberOfRceipies = 0;

            do
            {
                Console.WriteLine($"Press N(ew), D(el), S(earch)or L(ist)");
                cki = Console.ReadKey();
                Console.WriteLine();
                Recipe recipe;
                switch (cki.Key)
                {
                case ConsoleKey.N:
                    if (NumberOfRceipies < capacity)
                    {
                        Console.WriteLine("New Recipe");
                        // بر عهده دانشجو
                        //reading the requirements
                        Console.WriteLine("Enter instructions:");
                        string instructions = Console.ReadLine();
                        Console.WriteLine("Enter servingCount:");
                        int servingCount = int.Parse(Console.ReadLine());
                        Console.WriteLine("Enter cuisine:");
                        string cuisine = Console.ReadLine();
                        Console.WriteLine("Enter keywords:");
                        string[] keywords = (Console.ReadLine()).Split();
                        Console.WriteLine("Enter ingredientCount:");
                        int ingredientCount = int.Parse(Console.ReadLine());
                        Console.WriteLine("Enter title:");
                        string title = Console.ReadLine();
                        //creating object of Recipe Class
                        recipe = new Recipe(title, instructions,
                                            new Ingredient[ingredientCount], servingCount, cuisine, keywords);
                        //adding ingredeints
                        for (int i = 0; i < ingredientCount; i++)
                        {
                            Console.WriteLine($"adding ingredient {i + 1}");
                            Console.WriteLine("add description");
                            string description = Console.ReadLine();
                            Console.WriteLine("unit");
                            string unit = Console.ReadLine();
                            Console.WriteLine("name");
                            string ingredientName = Console.ReadLine();
                            Console.WriteLine("quantity");
                            double     quantity       = double.Parse(Console.ReadLine());
                            Ingredient ingredientTemp = new Ingredient(ingredientName, description, quantity, unit);
                            recipe.AddIngredient(ingredientTemp);
                        }
                        do
                        {
                            Console.WriteLine("Do you want to remove an ingredient? Y or N");
                            cki = Console.ReadKey();
                            if (cki.Key == ConsoleKey.Y)
                            {
                                Console.WriteLine("Remove Ingredient \nEnter the name: ");
                                string nameToDelete = Console.ReadLine();
                                recipe.RemoveIngredient(nameToDelete);
                            }
                            else
                            {
                                break;
                            }
                        } while (true);
                        recipeBook.Add(recipe);
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Recipe Book is full!");
                        break;
                    }

                case ConsoleKey.D:
                    Console.WriteLine("Delete Recipe");
                    // بر عهده دانشجو
                    bool   flag           = false;
                    string recipeToDelete = Console.ReadLine();
                    flag = recipeBook.Remove(recipeToDelete);
                    if (flag)
                    {
                        Console.WriteLine("Successfully deleted!");
                    }
                    else
                    {
                        Console.WriteLine("Failed to delete!");
                    }
                    break;

                case ConsoleKey.S:
                    Console.WriteLine("Search Recipe");
                    // بر عهده دانشجو
                    Console.WriteLine("Which one do you want to search? \ntitle \nkeyword \ncuisine");
                    string action = Console.ReadLine();
                    switch (action)
                    {
                    case "title":
                        string titleToSearch = Console.ReadLine();
                        Recipe recipeTitle   = recipeBook.LookupByTitle(titleToSearch);
                        Console.WriteLine(recipeTitle.ToString());
                        Console.WriteLine("Do you want to remove the following recipe or update the serving count? Y or N or U");
                        cki = Console.ReadKey();
                        switch (cki.Key)
                        {
                        case ConsoleKey.Y:
                            recipeBook.Remove(recipeTitle.title);
                            break;

                        case ConsoleKey.U:
                            Console.WriteLine("Enter the new Serving count:");
                            int newServingCount = int.Parse(Console.ReadLine());
                            recipeTitle.UpdateServingCount(newServingCount);
                            break;

                        default:
                            break;
                        }
                        break;

                    case "keyword":
                        string   keywordToSearch = Console.ReadLine();
                        Recipe[] recipeKeyword   = recipeBook.LookupByKeyword(keywordToSearch);
                        for (int i = 0; i < recipeKeyword.Length; i++)
                        {
                            Console.WriteLine(recipeKeyword[i].ToString());
                        }
                        Console.WriteLine("Do you want to remove the following recipies? Y or N");
                        cki = Console.ReadKey();
                        switch (cki.Key)
                        {
                        case ConsoleKey.Y:
                            for (int i = 0; i < recipeKeyword.Length; i++)
                            {
                                recipeBook.Remove(recipeKeyword[i].ToString());
                            }
                            break;

                        default:
                            break;
                        }
                        break;

                    case "cuisine":
                        string   cuisineToSearch = Console.ReadLine();
                        Recipe[] recipeCuisine   = recipeBook.LookupByKeyword(cuisineToSearch);
                        for (int i = 0; i < recipeCuisine.Length; i++)
                        {
                            Console.WriteLine(recipeCuisine[i].ToString());
                        }
                        Console.WriteLine("Do you want to remove the following recipies? Y or N");
                        cki = Console.ReadKey();
                        switch (cki.Key)
                        {
                        case ConsoleKey.Y:
                            for (int i = 0; i < recipeCuisine.Length; i++)
                            {
                                recipeBook.Remove(recipeCuisine[i].title);
                            }
                            break;

                        default:
                            break;
                        }
                        break;

                    default:
                        Console.WriteLine("Wrong entry! \nPlease try again!");
                        break;
                    }
                    break;

                case ConsoleKey.L:
                    Console.WriteLine("List Recipes");
                    // بر عهده دانشجو
                    Console.WriteLine(recipeBook.ToString());
                    break;

                case ConsoleKey.Escape:
                    Console.WriteLine("Esc");
                    break;

                default:
                    Console.WriteLine($"Invalid Key: {cki.KeyChar}");
                    break;
                }

                Console.WriteLine("Press any key to continue, Esc to exit");
                cki = Console.ReadKey();
                Console.Clear();
            }while (cki.Key != ConsoleKey.Escape);
        }