Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

using System;

using System.Runtime.CompilerServices;

namespace Products
{
class Program
{
static void Main(string[] args)
{
Product product = new Product();
product.name = "Pencils";
product.price = 25.25m;
product.quantity = 50;
Console.WriteLine(product.ToString());

Product product2 = new Product();


product2.name = "Paints";
product2.price = 30.25m;
product2.quantity = 50;
Console.WriteLine(product2.ToString());

Product product3 = new Product("Pen", 55, 100.50m);


Console.WriteLine(product3.ToString());

StoreManager store = new StoreManager();


store.AddProduct(product);
store.AddProduct(product2);
store.AddProduct(product3);

Product result = store.GetTheMostExpensiveProduct();


Console.WriteLine("Info product max price");
Console.WriteLine(result.ToString());
}
}
}

using System;
using System.Collections.Generic;
using System.Text;

namespace Products
{
public class Product
{
public string name;
public int quantity;
public decimal price;
public string Name
{
get { return this.name; }
set { this.name = value; }
}
public int Quantity
{
get { return this.quantity; }
set { this.quantity = value; }
}
public decimal Price
{
get { return this.price; }
set { this.price = value; }
}
public Product()
{

}
public Product(string name, int quantity, decimal price)
{
this.name = name;
this.quantity = quantity;
this.price = price;
}

public override string ToString()


{
return ("Product: " + name + ", Quantity: " + quantity + ", Price: " + price + " leva");
}
}
}

using System;
using System.Collections.Generic;
using System.Text;

namespace Products
{
public class StoreManager
{
public List<Product> newproducts { get; set; }
public StoreManager()
{
newproducts = new List<Product>();
}
public void AddProduct(Product product)
{
newproducts.Add(product);
}
public Product GetTheMostExpensiveProduct()
{
Product product = new Product();
foreach (Product item in newproducts)
{
if (item.price > product.price)
{
product = item;
}
}
return product;
}

}
}

You might also like