コード例 #1
0
ファイル: ProgramEntry.cs プロジェクト: MihailDobrev/SoftUni
        static void Main()
        {
            long   jarvisEnergy = long.Parse(Console.ReadLine());
            Jarvis jarvis       = new Jarvis();

            jarvis.Energy = jarvisEnergy;

            while (true)
            {
                string[] tokens = Console.ReadLine().Split();
                if (tokens[0] == "Assemble!")
                {
                    break;
                }
                switch (tokens[0])
                {
                case "Head":
                    Head head = new Head()
                    {
                        Energy   = int.Parse(tokens[1]),
                        Iq       = int.Parse(tokens[2]),
                        Material = tokens[3]
                    };
                    jarvis.addHead(head);
                    break;

                case "Torso":
                    Torso torso = new Torso()
                    {
                        Energy        = int.Parse(tokens[1]),
                        ProcessorSize = double.Parse(tokens[2]),
                        Material      = tokens[3]
                    };
                    jarvis.addTorso(torso);
                    break;

                case "Leg":
                    Leg leg = new Leg()
                    {
                        Energy   = int.Parse(tokens[1]),
                        Strenght = int.Parse(tokens[2]),
                        Speed    = int.Parse(tokens[3]),
                    };
                    jarvis.addLeg(leg);
                    break;

                case "Arm":
                    Arm arm = new Arm()
                    {
                        Energy  = int.Parse(tokens[1]),
                        Reach   = int.Parse(tokens[2]),
                        Fingers = int.Parse(tokens[3]),
                    };
                    jarvis.addArm(arm);
                    break;
                }
            }
            Console.WriteLine(jarvis.ToString());
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var energyCapacity = long.Parse(Console.ReadLine());

            var classJarvis = new Jarvis();

            classJarvis.EnergyCapacity = energyCapacity;

            while (true)
            {
                var input = Console.ReadLine().Split();

                if (input[0] == "Assemble!")
                {
                    break;
                }

                var component        = input[0];
                var energyConsuption = int.Parse(input[1]);
                var property1        = input[2];
                var property2        = input[3];

                switch (component)
                {
                case "Head":
                    var classHead = new Head()
                    {
                        Energy   = energyConsuption,
                        Iq       = int.Parse(property1),
                        Material = property2
                    };

                    classJarvis.AddHead(classHead);
                    break;

                case "Torso":
                    var classTorso = new Torso()
                    {
                        Energy    = energyConsuption,
                        Processor = double.Parse(property1),
                        Material  = property2
                    };

                    classJarvis.AddTorso(classTorso);
                    break;

                case "Arm":
                    var classArms = new Arms()
                    {
                        Energy  = energyConsuption,
                        Reach   = int.Parse(property1),
                        Fingers = int.Parse(property2)
                    };

                    classJarvis.AddArms(classArms);
                    break;

                case "Leg":
                    var classLegs = new Legs()
                    {
                        Energy   = energyConsuption,
                        Strength = int.Parse(property1),
                        Speed    = int.Parse(property2)
                    };

                    classJarvis.AddLegs(classLegs);
                    break;

                default: break;
                }
            }
            Console.WriteLine(classJarvis.ToString());
        }