Exemplo n.º 1
0
        private static Food CreateFood(string[] informationFood)
        {
            string type     = informationFood[0];
            int    quantity = int.Parse(informationFood[1]);

            switch (type)
            {
            case "Vegetable":
                Food food = new Vegetable(quantity);
                return(food);

            case "Fruit":
                food = new Fruit(quantity);
                return(food);

            case "Meat":
                food = new Meat(quantity);
                return(food);

            case "Seeds":
                food = new Seeds(quantity);
                return(food);

            default:
                return(null);
            }
        }
Exemplo n.º 2
0
        private static Food GetFood()
        {
            var foodTokens = Console.ReadLine()
                             .Split();
            var foodType     = foodTokens[0];
            var foodQuantity = int.Parse(foodTokens[1]);

            Food food = null;

            switch (foodType)
            {
            case "Vegetable":
                food = new Vegetable(foodQuantity);
                break;

            case "Fruit":
                food = new Fruit(foodQuantity);
                break;

            case "Meat":
                food = new Meat(foodQuantity);
                break;

            case "Seeds":
                food = new Seeds(foodQuantity);
                break;

            default:
                throw new InvalidOperationException("The food type is invalid!");
            }

            return(food);
        }
Exemplo n.º 3
0
        private static Food ReadFood(string[] foodArgs)
        {
            Food food;
            var  foodType = foodArgs[0];
            var  quantity = int.Parse(foodArgs[1]);

            switch (foodType)
            {
            case "Vegetable":
                food = new Vegetable(quantity);
                break;

            case "Fruit":
                food = new Fruit(quantity);
                break;

            case "Meat":
                food = new Meat(quantity);
                break;

            case "Seeds":
                food = new Seeds(quantity);
                break;

            default:
                food = new Fruit();
                break;
            }

            return(food);
        }