Beispiel #1
0
        public static string GetOutput(TimeOfDay timeOfDay, string inputDishes)
        {
            var meal = new Meal(timeOfDay);
            List<short> dishIndexes;
            if (!Meal.TryParseMealItems(inputDishes, out dishIndexes))
            {
                return "Sorry, I didn't get that.";
            }

            string dishesOutput = string.Empty;
            foreach (var dishIndex in dishIndexes)
            {
                meal.AddMealItem(dishIndex);

                if (meal.IsValid)
                {
                    dishesOutput = GetOutputFromMeal(meal);
                }
                else
                {
                    if (!string.IsNullOrEmpty(dishesOutput))
                    {
                        dishesOutput += ", ";
                    }
                    dishesOutput += "error";
                    break;
                }
            }

            return dishesOutput;
        }
        public MealItem GetMealItems(TimeOfDay timeOfDay, short dishType)
        {
            var dishTypeIndex = dishType - 1;

            switch (timeOfDay.Time)
            {
                case TimeOfDayEnum.morning:
                    return MorningMealItems[dishTypeIndex];
                case TimeOfDayEnum.night:
                    return NightMealItems[dishTypeIndex];
                default:
                    throw new ArgumentException();
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the only meal planner you'll ever need!");

            Console.WriteLine("Please enter the time of day. You may enter morning or night.");
            var inputTimeOfDay = Console.ReadLine();
            var timeOfDay = new TimeOfDay(inputTimeOfDay);
            if (!timeOfDay.IsValid)
            {
                Console.WriteLine("error");
                return;
            }

            Console.WriteLine();

            Console.WriteLine("What dishes would you like?");
            var inputDishes = Console.ReadLine();

            var output = GetOutput(timeOfDay, inputDishes);

            Console.WriteLine(output);
            Console.ReadLine();
        }
Beispiel #4
0
 public Meal(TimeOfDay timeOfDay)
 {
     _timeOfDay = timeOfDay;
 }