コード例 #1
0
        public static void Main(string[] args)
        {
            ChampionshipController controller = new ChampionshipController();

            string line = Console.ReadLine();

            while (line != "End")
            {
                string[] commandItems = line.Split();
                string   result       = string.Empty;

                try
                {
                    switch (commandItems[0])
                    {
                    case "CreateRider":
                        result += controller.CreateRider(commandItems[1]);
                        break;

                    case "CreateMotorcycle":
                        result += controller.CreateMotorcycle(commandItems[1],
                                                              commandItems[2],
                                                              int.Parse(commandItems[3]));
                        break;

                    case "AddMotorcycleToRider":
                        result += controller.AddMotorcycleToRider(commandItems[1], commandItems[2]);
                        break;

                    case "AddRiderToRace":
                        result += controller.AddRiderToRace(commandItems[1], commandItems[2]);
                        break;

                    case "CreateRace":
                        result += controller.CreateRace(commandItems[1], int.Parse(commandItems[2]));
                        break;

                    case "StartRace":
                        result += controller.StartRace(commandItems[1]);
                        break;
                    }

                    Console.WriteLine(result);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                line = Console.ReadLine();
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            StringBuilder message = new StringBuilder();

            string result = string.Empty;
            ChampionshipController championshipController = new ChampionshipController();
            string input = string.Empty;

            while ((input = Console.ReadLine()) != "End")
            {
                try
                {
                    string[] elements = input
                                        .Split(" ")
                                        .ToArray();

                    string command = elements[0];

                    if (command == "CreateRider")
                    {
                        string name = elements[1];
                        result = championshipController.CreateRider(name);
                    }
                    else if (command == "CreateMotorcycle")
                    {
                        string type       = elements[1];
                        string model      = elements[2];
                        int    horsePower = int.Parse(elements[3]);

                        result = championshipController.CreateMotorcycle(type, model, horsePower);
                    }
                    else if (command == "AddMotorcycleToRider")
                    {
                        string nameRider = elements[1];
                        string nameMotor = elements[2];

                        result = championshipController.AddMotorcycleToRider(nameRider, nameMotor);
                    }
                    else if (command == "AddRiderToRace")
                    {
                        string nameRace = elements[1];
                        string nameRide = elements[2];

                        result = championshipController.AddRiderToRace(nameRace, nameRide);
                    }
                    else if (command == "CreateRace")
                    {
                        string name = elements[1];
                        int    labs = int.Parse(elements[2]);

                        result = championshipController.CreateRace(name, labs);
                    }
                    else if (command == "StartRace")
                    {
                        string name = elements[1];
                        result = championshipController.StartRace(name);
                    }
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                }

                message.AppendLine(result);
            }

            Console.WriteLine(message);
        }