private static Food ParseFood(string[] foodTokens) { string foodType = foodTokens[0]; int quantity = int.Parse(foodTokens[1]); Food food = null; switch (foodType) { case "Meat": food = new Meat(quantity); break; case "Vegetable": food = new Vegetable(quantity); break; case "Fruit": food = new Fruit(quantity); break; case "Seeds": food = new Seeds(quantity); break; default: throw new ArgumentException("Invalid type of food!"); } return(food); }
private static Food ReadFoods(string[] food) { Food currentFood = null; switch (food[0]) { case "Vegetable": Food vegetable = new Vegetable(int.Parse(food[1])); currentFood = vegetable; break; case "Fruit": Food fruit = new Fruit(int.Parse(food[1])); currentFood = fruit; break; case "Meat": Food meat = new Meat(int.Parse(food[1])); currentFood = meat; break; case "Seeds": Food seeds = new Seeds(int.Parse(food[1])); currentFood = seeds; break; } return(currentFood); }