protected FarmUnit(string id, int health, int productionQuantity, Product product) : base(id) { this.Health = health; this.ProductionQuantity = productionQuantity; this.Product = product; }
public override Product GetProduct() { if (!this.HasGrown) { throw new Exception("Plant is not grown yet");} if (!this.IsAlive) { throw new Exception("Tabacco plant is dead");} var product= new Product(string.Format(this.Id+"Product"),ProductType.Tobacco,productionQuantity); return product; }
public void AddProduct(Product product) { var foundProduct = this.Products.FirstOrDefault(x => x.Id == product.Id); if (foundProduct != null) { foundProduct.Quantity += product.Quantity; } else { this.Products.Add(product); } }
public void AddProduct(Product product) { var productWithSameId = this.Products.Where(p => p.Id == product.Id).Select(p => p).FirstOrDefault(); if (productWithSameId != null) { productWithSameId.Quantity += product.Quantity; } else { this.Products.Add(product); } }
public void AddProduct(Product productToBeAdded) { Product currentProduct = this.products.Find(x => x.Id == productToBeAdded.Id); if (currentProduct == null) { this.products.Add(productToBeAdded); } else { currentProduct.Quantity += productToBeAdded.Quantity; } }
public void AddProduct(Product product) { var existingProduct = this.Products .FirstOrDefault(p => p.Id == product.Id); if (existingProduct != null) { existingProduct.Quantity += product.Quantity; } else { this.Products.Add(product); } }
public override Product GetProduct() { if (!this.IsAlive) { throw new InvalidOperationException("Tobacco is dead!"); } if (!this.HasGrown) { throw new InvalidOperationException("Tobacco is still growing!"); } var product = new Product(this.Id + "Product", ProductType.Tobacco, this.ProductionQuantity); return product; }
public static Product ProduceProduct(string originalID, ProductType productType) { string productID = originalID + PlantValues.PlantProductIDIndex; Product currentProduct; switch (productType) { case ProductType.Grain: { currentProduct = new Food(productID); LoadGrainProductValues(currentProduct as Food); return currentProduct as Food; } case ProductType.Tobacco: { currentProduct = new Product(productID); LoadTobaccoProductValues(currentProduct); return currentProduct; } case ProductType.Cherry: { currentProduct = new Food(productID); LoadCherryProductValues(currentProduct as Food); return currentProduct; } case ProductType.Milk: { currentProduct = new Food(productID); LoadMilkProductValues(currentProduct as Food); return currentProduct as Food; } case ProductType.PorkMeat: { currentProduct = new Food(productID); LoadPorkMeatProductValues(currentProduct as Food); return currentProduct as Food; } default: { throw new NotImplementedException("Unknown product type " + productType); } } }
public void AddProduct(Product product) { if (product == null) { throw new ArgumentNullException("product"); } // If a product with a given Id is added to the farm and another product with the same Id already exists, only the quantity of the existing product is increased if (this.products.Any(x => x.Id == product.Id)) { foreach (var item in this.products.Where(item => item.Id == product.Id)) { item.Quantity += product.Quantity; } } else { this.products.Add(product); } }
public void AddProduct(Product product) { bool alreadyExcists = false; for (int i = 0; i < Products.Count; i++) { if (Products[i].Id == product.Id) { alreadyExcists = true; } } if (alreadyExcists) { for (int i = 0; i < Products.Count; i++) { if (Products[i].Id == product.Id) { Products[i].Quantity += product.Quantity; } } } else { this.Products.Add(product);} }
private static void LoadTobaccoProductValues(Product currentProduct) { currentProduct.Quantity = PlantValues.TobaccoPlantProductQuantity; }
public void AddProduct(Product product) { this._products.Add(product); }
public void AddProduct(Product product) { throw new NotImplementedException(); }
public virtual Product GetProduct() { Product product = new Product(this.productId, this.productType, this.ProductionQuantity); return product; }