コード例 #1
0
        public string CreateComputer(List <string> args)
        {
            string  name                = args[0];
            string  processorType       = args[1];
            string  processorModel      = args[2];
            int     processorGeneration = int.Parse(args[3]);
            decimal processorPrice      = decimal.Parse(args[4]);
            string  videoCardType       = args[5];
            string  videoCardModel      = args[6];
            int     videoCardGeneration = int.Parse(args[7]);
            int     videoCardRam        = int.Parse(args[8]);
            decimal videoCardPrice      = decimal.Parse(args[9]);
            int     computerRam         = int.Parse(args[10]);

            if (users.Any(x => x.Name == name))
            {
                Processor processor = null;
                if (processorType == "Low")
                {
                    processor = new LowPerformanceProcessor(processorModel, processorGeneration, processorPrice);
                }
                else if (processorType == "High")
                {
                    processor = new HighPerformanceProcessor(processorModel, processorGeneration, processorPrice);
                }
                else
                {
                    return($"Invalid type processor!");
                }


                VideoCard videoCard = null;
                if (videoCardType == "Game")
                {
                    videoCard = new GameVideoCard(videoCardModel, videoCardGeneration, videoCardRam, videoCardPrice);
                }
                else if (videoCardType == "Mine")
                {
                    videoCard = new MineVideoCard(videoCardModel, videoCardGeneration, videoCardRam, videoCardPrice);
                }
                else
                {
                    return($"Invalid type video card!");
                }

                decimal configurationPrice = videoCard.Price + processor.Price;

                if (configurationPrice > users.First(x => x.Name == name).Money)
                {
                    return($"User: {name} - insufficient funds!");
                }

                computers.Add(new Computer(processor, videoCard, computerRam));
                return($"Successfully created computer for user: {name}!");
            }
            else
            {
                return($"Username: {name} does not exist!");
            }
        }
コード例 #2
0
        private VideoCard CreateVideoCartd(string videoCardType, string videoCardModel, int videoCardGerenation, int videoCardRam, decimal videoCardPrice)
        {
            VideoCard videoCard = null;

            if (videoCardType == "Mine")
            {
                videoCard = new MineVideoCard(videoCardModel, videoCardGerenation, videoCardRam, videoCardPrice);
            }
            else
            {
                videoCard = new GameVideoCard(videoCardModel, videoCardGerenation, videoCardRam, videoCardPrice);
            }
            return(videoCard);
        }
コード例 #3
0
        public static VideoCard CreateVideoCard(List <string> args)
        {
            string  type       = args[0];
            string  model      = args[1];
            int     generation = int.Parse(args[2]);
            int     ram        = int.Parse(args[3]);
            decimal price      = decimal.Parse(args[4]);

            VideoCard videoCard = null;

            if (type == "Game")
            {
                videoCard = new GameVideoCard(model, price, generation, ram);
            }
            else if (type == "Mine")
            {
                videoCard = new MineVideoCard(model, price, generation, ram);
            }

            return(videoCard);
        }