kurec

Untitled

May 12th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace OnlineStore
  8. {
  9. class Product
  10. {
  11. private string name;
  12. private double price;
  13. private bool isOnPromotion;
  14. string promociq;
  15.  
  16. public Product(string name, double price)
  17. {
  18. this.name = name;
  19. this.price = price;
  20. this.isOnPromotion = false;
  21. }
  22. public Product(string name, double price, bool isOnPromotion)
  23. {
  24. this.name = name;
  25. this.price = price;
  26. this.isOnPromotion = isOnPromotion;
  27. }
  28. public static void CreateProduct(string name, double price, Dictionary<string, Product> products)
  29. {
  30. Product P1 = new Product(name, price);
  31.  
  32. products.Add(name, P1);
  33. }
  34. public static void CreateProduct(string name, double price, bool isOnPromotion, Dictionary<string, Product> products)
  35. {
  36. Product P2 = new Product(name, price, isOnPromotion);
  37. products.Add(name, P2);
  38. }
  39.  
  40. public override string ToString()
  41. {
  42. double cena = price;
  43. if (this.isOnPromotion == true)
  44. {
  45. promociq = "YES";
  46. cena = cena - cena * 0.2;
  47. }
  48. else promociq = "NO";
  49. return $"Product -> {this.name} with price {cena:F2}. On promotion: {promociq}";
  50.  
  51. }
  52.  
  53. public String Name
  54. {
  55. get { return name; }
  56. set {
  57. if(value.Length<3)
  58. {
  59. throw new ArgumentException("Invalid product name!");
  60. }
  61. name = value;
  62. }
  63. }
  64. public double Price
  65. {
  66. get { return price; }
  67. set
  68. {
  69. if (price < 0)
  70. {
  71. throw new ArgumentException("Price should be positive!");
  72. }
  73. this.price = value;
  74. }
  75.  
  76. }
  77. public bool IsOnPromotion
  78. {
  79. get { return isOnPromotion; }
  80. set { isOnPromotion = value; }
  81. }
  82.  
  83. }
  84. }
Add Comment
Please, Sign In to add comment