using System.Collections.Generic;
public static void Main(string[] args)
ProductManager manager = new ProductManager();
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < n; i++)
string productName = Console.ReadLine();
string category = Console.ReadLine();
int quantity = Convert.ToInt32(Console.ReadLine());
float unitPrice = Convert.ToInt32(Console.ReadLine());
int id = manager.AddProduct(productName, category, unitPrice, quantity);
float unitPrice = Convert.ToInt32(Console.ReadLine());
int id = manager.AddProduct(productName, category, unitPrice);
int choice = Convert.ToInt32(Console.ReadLine());
string ProductName = Console.ReadLine();
string category = Console.ReadLine();
int quantity1 = Convert.ToInt32(Console.ReadLine());
float unitPrice1 = Convert.ToInt32(Console.ReadLine());
int id = manager.AddProduct(ProductName, category, unitPrice1, quantity1);
Console.WriteLine("Product already exists can not add again");
Console.WriteLine("The product " + ProductName + " has been added with product id " + id);
else if(category=="Services")
float unitPrice1 = Convert.ToInt32(Console.ReadLine());
int id = manager.AddProduct(ProductName, category, unitPrice1);
Console.WriteLine("Product already exists can not add again");
Console.WriteLine("The product " + ProductName + " has been added with product id " + id);
Console.WriteLine("Wrong category!");
int productid = int.Parse(Console.ReadLine());
int quantity = int.Parse(Console.ReadLine());
float unitPrice = Convert.ToInt32(Console.ReadLine());
Product pp = manager.UpdateProduct(productid, quantity, unitPrice);
Console.WriteLine(pp == null ? "Product does not exist, cannot modify" : "The product " + pp.productName + " has been updated with quantity " + pp.quantity + " and unit price" + pp.unitPrice);
string category2 = Console.ReadLine();
if(category2!="Goods" && category2!="Services" )
Console.WriteLine("Wrong category!");
List<Product> prods = manager.ViewProducts(category2);
Console.WriteLine("Category: Goods,Tax:12%");
foreach (Product prod in prods)
Console.WriteLine($"{prod.productid}, {prod.productName}: {prod.quantity} left, unit price: {prod.unitPrice}, total price: {prod.totalPrice}");
Console.WriteLine("Category: Services, Tax = 10%");
foreach (Product prod in prods)
Console.WriteLine($"{prod.productid}, {prod.productName}: {prod.quantity} left, unit price: {prod.unitPrice}, total price: {prod.totalPrice}");
manager.Statistics(out goods, out services);
if (goods != 0 && services != 0)
Console.WriteLine($"Category: Goods, Products: {goods}");
Console.WriteLine($"Category: Services, Products: {services}");
else Console.WriteLine("No products found");
public int productid { get; set; }
public string productName { get; set; }
public string category { get; set; }
public int quantity { get; set; }
public float unitPrice { get; set; }
public float tax { get; set; }
public float totalPrice { get; set; }
public Product(int productid, string productName, string category, int quantity, float unitPrice,float tax,float TotalPrice)
this.productid = productid;
this.productName = productName;
this.category = category;
this.quantity = quantity;
this.unitPrice = unitPrice;
this.tax =category=="Goods" ? 0.12f * unitPrice : 0.10f * unitPrice;
this.totalPrice = unitPrice + tax;
public Product(int productid, string productName, string category, float unitPrice, int quantity)
this.productid = productid;
this.productName = productName;
this.category = category;
this.unitPrice = unitPrice;
this.quantity = quantity;
public class ProductManager
List<Product> products { get; set; }
public int Productid = 100;
public int AddProduct(string productName,string category,float unitPrice,int quantity=0)
if (products.Exists(x => x.productName == productName))
products.Add(new Product(++Productid, productName, category, unitPrice, quantity));
public Product UpdateProduct(int Pid,int qnt,float uPrice)
Product p = products.Find(c => c.productid == Pid);
public List<Product> ViewProducts(string category)
pp = products.FindAll(x => x.category == category);
public void Statistics(out int goods, out int services)
goods = products.FindAll(x => x.category == "Goods").Count;
services = products.FindAll(x => x.category == "Services").Count;