Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApp3
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. Warehouse w1 = new Warehouse();
  15. w1.dodaj(new Product(1, "pierozek", 13, 1, "maczne", "bardzo dobre pierozki", "produkty babuni", "Pozan", 1), 20);
  16. w1.dodaj(new Product(1, "bulka", 13, 1, "maczne", "bardzo dobre pierozki", "produkty babuni", "Pozan", 1), 22);
  17. w1.dodaj(new Product(1, "chleb", 13, 1, "maczne", "bardzo dobre pierozki", "produkty babuni", "Pozan", 1), 44230);
  18. w1.dodaj(new Product(1, "drozdzowka", 13, 1, "maczne", "bardzo dobre pierozki", "produkty babuni", "Pozan", 1), 24);
  19. Console.WriteLine(w1.liczbaproduktow());
  20. w1.aktualizuj("chleb",222);
  21. Console.WriteLine(w1.liczbaproduktow());
  22. w1.ToString();
  23. licz(5);
  24. }
  25.  
  26.  
  27.  
  28. static public void licz(int n)
  29. {
  30. int wyn=1;
  31. Stopwatch stopwatch = new Stopwatch();
  32. stopwatch.Start();
  33. for(int i=1;i<n;i++)
  34. {
  35. wyn = wyn * n;
  36. }
  37. stopwatch.Stop();
  38. TimeSpan ts = stopwatch.Elapsed;
  39.  
  40. Console.WriteLine("RunTime " + ts.ToString());
  41. }
  42. }
  43.  
  44. class Category
  45. {
  46. public Category() { }
  47.  
  48. public int id { get; set; }
  49. public string name { get; set; }
  50.  
  51. public string description { get; set; }
  52.  
  53. public override string ToString()
  54. {
  55. return name + " " + description;
  56. }
  57.  
  58.  
  59. }
  60.  
  61. class Supplier
  62. {
  63. public Supplier() { }
  64. public int id { get; set; }
  65. public string Companyname { get; set; }
  66. public string city { get; set; }
  67. public string homePage { get; set; }
  68.  
  69. public override string ToString()
  70. {
  71. return Companyname+" "+city+" "+homePage;
  72. }
  73.  
  74.  
  75. }
  76. class Warehouse
  77. {
  78. public Warehouse() { }
  79. public Dictionary<Product, int> stan = new Dictionary<Product, int>();
  80. public Dictionary<Product, string> stan_nazwa = new Dictionary<Product, string>();
  81.  
  82. public void dodaj(Product p, int ilosc)
  83. {
  84.  
  85. stan.Add(p, ilosc);
  86. stan_nazwa.Add(p, p.name);
  87. }
  88. public void aktualizuj(string name, int ilosc)
  89. {
  90. foreach (var prod in stan_nazwa)
  91. {
  92. if (prod.Key.name == name)
  93. {
  94. stan[prod.Key] = ilosc;
  95. break;
  96. }
  97.  
  98. }
  99. }
  100.  
  101.  
  102. public int liczbaproduktow()
  103. {
  104. int ilosc = 0;
  105. foreach (var prod in stan)
  106. {
  107. ilosc += prod.Value;
  108. }
  109. return ilosc;
  110. }
  111.  
  112.  
  113. public override string ToString()
  114. {
  115. string buff;
  116. foreach (var prod in stan)
  117. {
  118. Console.WriteLine(prod.Key.name + " "+prod.Value);
  119. }
  120. return "";
  121. }
  122. }
  123.  
  124. class Product
  125. {
  126. public Product(int id, string name, int unitPrice, int categoryid,string catname,string desc,string suppname,string suppcity,int suppid)
  127. {
  128. this.id = id;
  129. this.name = name;
  130. category.id =categoryid;
  131. category.name = catname;
  132. category.description =desc;
  133. this.unitPrice = unitPrice;
  134. supplier.city=suppcity;
  135. supplier.Companyname =suppname;
  136. supplier.id = suppid;
  137. }
  138. public int id { get; set; }
  139.  
  140. public string name { get; set; }
  141.  
  142. public Category category = new Category();
  143. public Supplier supplier= new Supplier();
  144. decimal unitPrice;
  145. public override string ToString()
  146. {
  147. return category.ToString()+supplier.ToString()+ name;
  148. }
  149. }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement