예제 #1
0
        private static void CheckSource(string source, Raincast curr)
        {
            if (curr.Next != "source" || !String.IsNullOrEmpty(curr.Source))
            {
                return;
            }

            bool valid = source.All(sign => char.IsLetterOrDigit(sign));

            if (valid)
            {
                curr.Source = source;
                curr.Next   = "forecast";
            }
        }
예제 #2
0
        private static void CheckType(string type, Raincast curr)
        {
            if (curr.Next != "type" || !String.IsNullOrEmpty(curr.Type))
            {
                return;
            }

            string[] validTypes = new string[] { "Normal", "Warning", "Danger" };

            bool valid = validTypes.Contains(type);

            if (valid)
            {
                curr.Type = type;
                curr.Next = "source";
            }
        }
예제 #3
0
        private static bool CheckForecast(string forecast, Raincast curr)
        {
            if (curr.Next != "forecast")
            {
                return(false);
            }

            char[] invalidSigns = new char[] { '!', '.', ',', '?' };

            bool valid = forecast.All(sign => !invalidSigns.Contains(sign));

            if (valid)
            {
                curr.Forecast = forecast;
            }

            return(valid);
        }
예제 #4
0
        private static void GetRaincasts(List <Raincast> raincasts)
        {
            Raincast curr = new Raincast();

            while (true)
            {
                string[] commandArgs = Console.ReadLine().Split(':');

                if (commandArgs[0] == "Davai Emo")
                {
                    break;
                }

                switch (commandArgs[0])
                {
                case "Type":
                {
                    CheckType(commandArgs[1].Trim(), curr);
                    break;
                }

                case "Source":
                {
                    CheckSource(commandArgs[1].Trim(), curr);
                    break;
                }

                case "Forecast":
                {
                    bool complited = CheckForecast(commandArgs[1].Trim(), curr);

                    if (complited)
                    {
                        raincasts.Add(curr);
                        curr = new Raincast();
                    }
                    break;
                }
                }
            }
        }