Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OnlineStore
- {
- class Product
- {
- private string name;
- private double price;
- private bool isOnPromotion;
- string promociq;
- public Product(string name, double price)
- {
- this.name = name;
- this.price = price;
- this.isOnPromotion = false;
- }
- public Product(string name, double price, bool isOnPromotion)
- {
- this.name = name;
- this.price = price;
- this.isOnPromotion = isOnPromotion;
- }
- public static void CreateProduct(string name, double price, Dictionary<string, Product> products)
- {
- Product P1 = new Product(name, price);
- products.Add(name, P1);
- }
- public static void CreateProduct(string name, double price, bool isOnPromotion, Dictionary<string, Product> products)
- {
- Product P2 = new Product(name, price, isOnPromotion);
- products.Add(name, P2);
- }
- public override string ToString()
- {
- double cena = price;
- if (this.isOnPromotion == true)
- {
- promociq = "YES";
- cena = cena - cena * 0.2;
- }
- else promociq = "NO";
- return $"Product -> {this.name} with price {cena:F2}. On promotion: {promociq}";
- }
- public String Name
- {
- get { return name; }
- set {
- if(value.Length<3)
- {
- throw new ArgumentException("Invalid product name!");
- }
- name = value;
- }
- }
- public double Price
- {
- get { return price; }
- set
- {
- if (price < 0)
- {
- throw new ArgumentException("Price should be positive!");
- }
- this.price = value;
- }
- }
- public bool IsOnPromotion
- {
- get { return isOnPromotion; }
- set { isOnPromotion = value; }
- }
- }
- }
Add Comment
Please, Sign In to add comment