Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.34 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.  
  8. namespace ConsoleApplication1
  9. {
  10. public class Admin : ClientHandler
  11. {
  12. private string name;
  13. private int password ;
  14.  
  15. public Admin(string name,int password)
  16. {
  17. this.name = name;
  18. this.password = password;
  19. }
  20. private bool SecCHeck(string name, int password)
  21. {
  22. if (String.Equals(this.name,name) && (this.password == password))
  23. return true;
  24. return false;
  25. }
  26. public override void ClientUi(string name,int password)
  27. {
  28. if (!SecCHeck(name, password))
  29. {
  30. Console.WriteLine(" Wrong Password");
  31. return;
  32. }
  33. Console.WriteLine("Admin login succsful Please choose the option you want");
  34. while (true)
  35. {
  36. Console.WriteLine("Please choose the option you want");
  37. Console.WriteLine(" 1-Stock List, 2-Add Item, 3- Remove Item, 4 Change Item, 5-Return To main Menue");
  38. int choice = int.Parse(Console.ReadLine());
  39. switch (choice)
  40. {
  41. case 1:
  42. PrintStock();
  43. break;
  44. case 2:
  45. AddItem();
  46. break;
  47. case 3:
  48. RemoveItem();
  49. break;
  50. case 4:
  51. ChangeItem();
  52. break;
  53. case 5:
  54. return;
  55. default:
  56. Console.WriteLine("We have encoutred a problame in your selction");
  57. break;
  58. }
  59. }
  60.  
  61. }
  62. private void ChangeItem()
  63. {
  64. Console.WriteLine("Pls enetr the name of the item you want to change his propties");
  65. string name = Console.ReadLine(),Nname;
  66. int Id = base.Search(name),choice,price,age;
  67. if (items[Id].GetType() == typeof(Animal))
  68. {
  69. Console.WriteLine("1-to change price, 2-to change name,3-to change age");
  70. choice = int.Parse(Console.ReadLine());
  71. switch (choice)
  72. {
  73. case 1:
  74. Console.WriteLine("Pls write the new price you want to set for {0}", name);
  75. price = int.Parse(Console.ReadLine());
  76. items[Id].SetPrice(price);
  77. break;
  78. case 2:
  79. Console.WriteLine("Pls write the new name you want to set for {0}", name);
  80. Nname = Console.ReadLine();
  81. items[Id].SetName(Nname);
  82. break;
  83. case 3:
  84. Console.WriteLine("Pls write the new age you want to set for {0}", name);
  85. Animal animal = (Animal)items[Id];
  86. age = int.Parse(Console.ReadLine());
  87. animal.SetAge(age);
  88. break;
  89. default:
  90. Console.WriteLine("Eror you didnt give valid choice");
  91. break;
  92. }
  93. }
  94. else
  95. {
  96. Console.WriteLine("1-to change price, 2-to change name");
  97. choice = int.Parse(Console.ReadLine());
  98. switch (choice)
  99. {
  100. case 1:
  101. Console.WriteLine("Pls write the new price you want to set for {0}", name);
  102. price = int.Parse(Console.ReadLine());
  103. items[Id].SetPrice(price);
  104. break;
  105. case 2:
  106. Console.WriteLine("Pls write the new name you want to set for {0}", name);
  107. Nname = Console.ReadLine();
  108. items[Id].SetName(Nname);
  109. break;
  110. default:
  111. Console.WriteLine("Eror you didnt give valid choice");
  112. break;
  113. }
  114. }
  115.  
  116.  
  117. }
  118. private void RemoveItem()
  119. {
  120. Console.WriteLine("Pls enter the name of the item you wish to delete");
  121. string name = Console.ReadLine();
  122. base.DeleteItem(base.Search(name));
  123. }
  124.  
  125. private void AddItem()
  126. {
  127. Console.WriteLine("If you want to add an animal press 1 else if you want to add genrel item press 2");
  128. int choice = int.Parse(Console.ReadLine());
  129. if (choice == 1)
  130. {
  131. if (items[0] == null)
  132. {
  133. Console.WriteLine("Pls enter data(price,name,age)");
  134. int price = int.Parse(Console.ReadLine());
  135. string name = (Console.ReadLine());
  136. int age = int.Parse(Console.ReadLine());
  137. items[0] = new Animal(price, name, age);
  138. }
  139. else
  140. {
  141. Console.WriteLine("Pls enter data(price,name,age)");
  142. int price = int.Parse(Console.ReadLine());
  143. string name = (Console.ReadLine());
  144. int age = int.Parse(Console.ReadLine());
  145. items[items[0].GetAmm()] = new Animal(price, name, age);
  146. }
  147.  
  148. }
  149. if(choice==2)
  150. {
  151. if (items[0] != null)
  152. {
  153. Console.WriteLine("Pls enter data(price,name)");
  154. int price = int.Parse(Console.ReadLine());
  155. string name = (Console.ReadLine());
  156. items[items[0].GetAmm()] = new Item(price, name);
  157. }
  158. else
  159. {
  160. Console.WriteLine("Pls enter data(price,name)");
  161. int price = int.Parse(Console.ReadLine());
  162. string name =Console.ReadLine();
  163. items[0] = new Item (price, name);
  164. }
  165. }
  166. else
  167. {
  168. Console.WriteLine("Eror ! argument isnt valid");
  169. }
  170. }
  171. protected override void PrintStock()
  172. {
  173. int i = 0;
  174. Console.WriteLine("name price age");//need to fix formating
  175. while (i < items.Length)
  176. {
  177. if (items[i] != null)
  178. if (items[i].GetType() == typeof(Animal))
  179. {
  180. Animal animal = (Animal)items[i];
  181. Console.WriteLine(items[i].GetName() + " " + items[i].GetPrice() + " " + animal.GetAge());
  182. }
  183. else
  184. Console.WriteLine(items[i].GetName() + " " + items[i].GetPrice());
  185. i++;
  186. }
  187. Console.WriteLine();
  188. }
  189. }
  190. }
  191. using System;
  192. using System.Collections.Generic;
  193. using System.Linq;
  194. using System.Text;
  195. using System.Threading.Tasks;
  196.  
  197. namespace ConsoleApplication1
  198. {
  199. public class Animal : Item
  200. {
  201. private int age;
  202. public Animal(int price, string name, int age) : base(price, name)
  203. {
  204. SetAge(age);
  205.  
  206. }
  207.  
  208. public void SetAge(int age) { this.age = age; }
  209. public int GetAge() { return age; }
  210. public override int Buy()
  211. {
  212. Console.WriteLine("Are you sure you want to buy {0} the price is {1} and the age is {2}", GetName(), GetPrice(), age);
  213. char answer = char.Parse(Console.ReadLine());
  214. if (answer == 'N')
  215. return 0;
  216. else
  217. return GetPrice();
  218. }
  219. }
  220. }
  221. using System;
  222. using System.Collections.Generic;
  223. using System.Linq;
  224. using System.Text;
  225. using System.Threading.Tasks;
  226.  
  227. namespace ConsoleApplication1
  228. {
  229. public abstract class ClientHandler : Object
  230. {
  231. private static int MaxItems = 99;
  232. protected static Item[] items = new Item[MaxItems];
  233. protected abstract void PrintStock();
  234. public abstract void ClientUi(string name, int password);
  235. protected void DeleteItem(int itemID)
  236. {
  237.  
  238. for (int i = items[0].GetAmm(); i > itemID; itemID++)
  239. {
  240. items[itemID] = items[itemID + 1];
  241. }
  242. }
  243. protected int Search(string name)
  244. {
  245. int i = 0;
  246. while (i < MaxItems)
  247. {
  248. if (items[i] != null)
  249. if (name.Equals(items[i].GetName(), StringComparison.Ordinal))
  250. return i;
  251. i++;
  252. }
  253. return -1;
  254. }
  255. }
  256. }
  257. using System;
  258. using System.Collections.Generic;
  259. using System.Linq;
  260. using System.Text;
  261. using System.Threading.Tasks;
  262.  
  263. namespace ConsoleApplication1
  264. {
  265. public class Item : Object
  266. {
  267. private static int items_amm = 0;
  268. private int price;
  269. private string name;
  270.  
  271. public Item(int price, string name)
  272. {
  273. items_amm++;
  274. this.price = price;
  275. this.name = name;
  276. }
  277. public virtual int Buy()
  278. {
  279. Console.WriteLine("Are you sure you want to buy {0} the price is {1} press 'N' to cancel transction", name, price);
  280. char answer = char.Parse(Console.ReadLine());
  281. if (answer == 'N')
  282. return 0;
  283. else
  284. return price;
  285.  
  286. }
  287. public int GetAmm() { return items_amm; }
  288. public string GetName() { return name; }
  289. public void SetName(string name) { this.name = name; }
  290. public void SetPrice(int price) { this.price = price; }
  291. public int GetPrice() { return price; }
  292.  
  293. }
  294. }
  295. using System;
  296. using System.Collections.Generic;
  297. using System.Linq;
  298. using System.Text;
  299. using System.Threading.Tasks;
  300.  
  301. namespace ConsoleApplication1
  302. {
  303. class Class : Object
  304. {
  305. static private Admin admin = new Admin("A",1);// intalizte admin password;
  306. public static void Main(string[] args)
  307. {
  308. Ui();
  309. }
  310. public static void Ui()
  311. {
  312.  
  313. Console.WriteLine("Welcome to the pet shop");
  314. while (true)
  315. {
  316. Console.WriteLine("If you are coustomr press 1, if you are an opretor press 2");
  317. int chocie = int.Parse(Console.ReadLine());
  318. if (chocie == 1)
  319. Console.WriteLine("Pls enter your name ");
  320. string name = Console.ReadLine();
  321. Customer client = new Customer(name);
  322. }
  323. if (chocie == 2)
  324. {
  325. Console.WriteLine("Pls enter the username ");
  326. string username = Console.ReadLine();
  327. Console.WriteLine("and password");
  328. int password = int.Parse(Console.ReadLine());
  329. admin.ClientUi(username, password);
  330. }
  331.  
  332. }
  333. }
  334. }
  335. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement