private static Food GetFood(string item)
        {
            Food food;

            item = item.ToLower();
            if (item == "apple")
            {
                food = new Apple();
            }
            else if (item == "cram")
            {
                food = new Cram();
            }
            else if (item == "honeycake")
            {
                food = new HoneyCake();
            }
            else if (item == "lembas")
            {
                food = new Lembas();
            }
            else if (item == "melon")
            {
                food = new Melon();
            }
            else if (item == "mushrooms")
            {
                food = new Mushrooms();
            }
            else
            {
                food = new Other();
            }
            return(food);
        }
    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        JObject    obj           = JObject.Load(reader);
        string     discriminator = (string)obj["ObjectType"];
        ItemToSell item;

        switch (discriminator)
        {
        case "apple":
            item = new Apple();
            break;

        case "books":
            item = new Books();
            break;

        case "melon":
            item = new Melon();
            break;

        default:
            throw new NotImplementedException();
        }
        serializer.Populate(obj.CreateReader(), item);
        return(item);
    }
示例#3
0
    public int CalculateHappiness(string[] foods)
    {
        int happiness = 0;

        foreach (var food in foods)
        {
            switch (food.ToLower())
            {
            case "cram":
                happiness += new Cram().HappinessPoints;
                break;

            case "lembas":
                happiness += new Lembas().HappinessPoints;
                break;

            case "apple":
                happiness += new Apple().HappinessPoints;
                break;

            case "melon":
                happiness += new Melon().HappinessPoints;
                break;

            case "honeycake":
                happiness += new HoneyCake().HappinessPoints;
                break;

            case "mushrooms":
                happiness += new Mushrooms().HappinessPoints;
                break;

            default:
                int everythingElse = -1;
                happiness += everythingElse;
                break;
            }
        }
        return(happiness);
    }
示例#4
0
        public virtual Food CreateFood(string name)
        {
            Food food = null;

            switch (name)
            {
            case "cram":
                food = new Cram(2);
                break;

            case "lembas":
                food = new Lembas(3);
                break;

            case "apple":
                food = new Apple(1);
                break;

            case "melon":
                food = new Melon(1);
                break;

            case "honeycake":
                food = new HoneyCake(5);
                break;

            case "mushrooms":
                food = new Mushrooms(-10);
                break;

            default:
                food = new Misc(-1);
                break;
            }

            return(food);
        }
示例#5
0
        public Food.Food GetFood(string food)
        {
            Food.Food currentFood;

            switch (food)
            {
            case "cram":
                currentFood = new Cram();
                break;

            case "lembas":
                currentFood = new Lembas();;
                break;

            case "apple":
                currentFood = new Apple();;
                break;

            case "melon":
                currentFood = new Melon();
                break;

            case "honeycake":
                currentFood = new HoneyCake();
                break;

            case "mushroom":
                currentFood = new Mushrooms();
                break;

            default:
                currentFood = null;
                break;
            }

            return(currentFood);
        }
示例#6
0
        static void Main(string[] args)
        {
            try
            {
                int      totalpoints = 0;
                string   a           = Console.ReadLine();
                string[] s           = a.Split(' ');
                if (a.Length > 1000)
                {
                    throw new Exception("The characters in the input string will be no more than: 1000");
                }
                if (s.Length < 1 || s.Length > 100)
                {
                    throw new Exception("The food count would be in the range [1…100].");
                }
                string caseSwitch;
                foreach (var p in s)
                {
                    caseSwitch = p;
                    switch (caseSwitch)
                    {
                    case "Apple":
                        Apple apple = new Apple(p);
                        totalpoints += apple.Point;
                        break;

                    case "Cram":
                        Cram cram = new Cram(p);
                        totalpoints += cram.Point;
                        break;

                    case "HoneyCake":
                        HoneyCake honeyCake = new HoneyCake(p);
                        totalpoints += honeyCake.Point;
                        break;

                    case "Lembas":
                        Lembas lembas = new Lembas(p);
                        totalpoints += lembas.Point;
                        break;

                    case "Melon":
                        Melon melon = new Melon(p);
                        totalpoints += melon.Point;
                        break;

                    case "Mushrooms":
                        Mushrooms mushrooms = new Mushrooms(p);
                        totalpoints += mushrooms.Point;
                        break;

                    default:
                        EverithingElse everithingElse = new EverithingElse(p);
                        totalpoints += everithingElse.Point;
                        break;
                    }
                }
                if (totalpoints < -5)
                {
                    Angry angry = new Angry();
                    Console.WriteLine(totalpoints);
                    angry.Output();
                }
                else if (totalpoints >= 1 && totalpoints <= 15)
                {
                    Happy happy = new Happy();
                    Console.WriteLine(totalpoints);
                    happy.Output();
                }
                else if (totalpoints >= -5 && totalpoints <= 0)
                {
                    Sad sad = new Sad();
                    Console.WriteLine(totalpoints);
                    sad.Output();
                }
                else if (totalpoints > 15)
                {
                    JavaScript javaScript = new JavaScript();
                    Console.WriteLine(totalpoints);
                    javaScript.Output();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message}");
            }


            Console.ReadKey();
        }