Beispiel #1
0
        public string AddProduct(string type, double price)
        {
            if (!productTypes.Contains(type))
            {
                throw new InvalidOperationException("Invalid product type!");
            }

            if (type == productTypes[0])
            {
                Gpu gpu = new Gpu(price);
                products.Add(gpu);
            }
            else if (type == productTypes[1])
            {
                HardDrive hardDrive = new HardDrive(price);
                products.Add(hardDrive);
            }
            else if (type == productTypes[2])
            {
                Ram ram = new Ram(price);
                products.Add(ram);
            }
            else if (type != productTypes[3])
            {
                SolidStateDrive solid = new SolidStateDrive(price);
                products.Add(solid);
            }

            return($"Added {type} to pool");
        }
        public Product CreateProduct(string type, double price)
        {
            Product product = null;

            switch (type)
            {
            case "Ram":
            {
                product = new Ram(price);
                break;
            }

            case "Gpu":
            {
                product = new Gpu(price);
                break;
            }

            case "HardDrive":
            {
                product = new HardDrive(price);
                break;
            }

            case "SolidStateDrive":
            {
                product = new SolidStateDrive(price);
                break;
            }

            default:
                throw new InvalidOperationException("Invalid product type!");
            }
            return(product);
        }
        public string AddProduct(string type, double price)
        {
            Product newProduct;


            switch (type)
            {
            case "Gpu":
                newProduct = new Gpu(price);
                break;

            case "Ram":
                newProduct = new Ram(price);
                break;

            case "hardDrive":
                newProduct = new HardDrive(price);
                break;

            case "SolidStateDrive":
                newProduct = new SolidStateDrive(price);
                break;

            default: { throw new InvalidOperationException("Invalid product type!"); }
            }

            productsPool.Add(newProduct);
            return("Added {type} to pool.");
        }