Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.03 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 ClassDogger
  8. {
  9. class Program
  10. {
  11. public bool running = true;
  12. private bool searching = true;
  13.  
  14. private List<Dog> Dogs = new List<Dog>();
  15.  
  16. static void Main(string[] args)
  17. {
  18. Program p = new Program();
  19. p.Run();
  20.  
  21. }
  22. public bool Run()
  23. {
  24. Dogs.Add(new Pudel("ramus", 13, 10, 4, 10, true));
  25. Dogs.Add(new Labrador("kim", 14, 1, 44, 101, true));
  26.  
  27. while (running)
  28. {
  29. inputhandler("give input:", out string input);
  30. if (input == "add")
  31. {
  32. add();
  33. }
  34. else if (input == "search")
  35. {
  36. search();
  37. }
  38. else if (input == "list")
  39. {
  40. doglist();
  41. }
  42. else if (input == "help")
  43. {
  44. Console.WriteLine("Valid inputs: add, search, list, exit, help");
  45. }
  46.  
  47. else
  48. {
  49. Console.WriteLine("Wrong input, try again:");
  50. Console.Write(Environment.NewLine);
  51.  
  52. }
  53. }
  54. return true;
  55. }
  56.  
  57. #region inputhandlers
  58. private void inputhandler(string message, out string input)
  59. {
  60. Console.WriteLine(message);
  61. input = Console.ReadLine().ToLower();
  62. }
  63.  
  64. private void inputhandler(string message, out int input)
  65. {
  66. Console.WriteLine(message);
  67. input = int.Parse(Console.ReadLine());
  68. }
  69.  
  70. private void inputhandler(string message, out double input)
  71. {
  72. Console.WriteLine(message);
  73. input = double.Parse(Console.ReadLine());
  74. }
  75.  
  76. private void inputhandler(string message, out bool input)
  77. {
  78. Console.WriteLine(message);
  79. input = bool.Parse(Console.ReadLine());
  80. }
  81. #endregion
  82.  
  83. #region add
  84. private void add()
  85. {
  86. inputhandler("Race:", out string race);
  87. inputhandler("Name:", out string name);
  88. inputhandler("Age:", out int age);
  89. inputhandler("Length:", out double lenght);
  90. inputhandler("Withers:", out double withers);
  91. inputhandler("Weight:", out double weight);
  92. inputhandler("Sex:", out bool sex);
  93.  
  94. if (race == "pudel")
  95. {
  96. Dogs.Add(new Pudel(name, age, lenght, withers, weight, sex));
  97. }
  98.  
  99. if (race == "labrador")
  100. {
  101. Dogs.Add(new Labrador(name, age, lenght, withers, weight, sex));
  102. }
  103.  
  104. if (race == "wienerdog")
  105. {
  106. Dogs.Add(new WienerDog(name, age, lenght, withers, weight, sex));
  107. }
  108. }
  109. #endregion
  110.  
  111. #region list
  112. private void doglist()
  113. {
  114. Dogs.Sort();
  115. foreach (Dog Dog in Dogs)
  116. {
  117. Dog.PrintAll();
  118. }
  119. Console.ReadLine();
  120. }
  121. #endregion
  122.  
  123. #region search
  124. private void search()
  125. {
  126. searching = true;
  127. inputhandler("Search for a dog", out string name);
  128. foreach (Dog Dog in Dogs)
  129. {
  130. if (Dog.Name == name)
  131. {
  132. Dog.PrintAll();
  133. }
  134. }
  135. while (searching)
  136. {
  137. inputhandler("What do you want to do with the dog?:", out string choice);
  138. #region edit
  139. if (choice == "edit")
  140. {
  141. foreach (Dog Dog in Dogs)
  142. {
  143. if (Dog.Name == name)
  144. {
  145. inputhandler("What do you want to change?:", out string input);
  146.  
  147. if (input == "name")
  148. {
  149. inputhandler("What's the new name?:", out string newname);
  150. Dogs[Getindex(Dog)].Name = newname;
  151. }
  152. if (input == "age")
  153. {
  154. inputhandler("What's the new name?:", out int newage);
  155. Dogs[Getindex(Dog)].Age = newage;
  156. }
  157. if (input == "length")
  158. {
  159. inputhandler("What's the new name?:", out int newlength);
  160. Dogs[Getindex(Dog)].Length = newlength;
  161. }
  162. if (input == "withers")
  163. {
  164. inputhandler("What's the new name?:", out int newwithers);
  165. Dogs[Getindex(Dog)].Withers = newwithers;
  166. }
  167. if (input == "weight")
  168. {
  169. inputhandler("What's the new name?:", out int newweight);
  170. Dogs[Getindex(Dog)].Weight = newweight;
  171. }
  172. }
  173. }
  174. }
  175. #endregion
  176. #region remove
  177. else if (choice == "remove")
  178. {
  179. foreach (Dog Dog in Dogs)
  180. {
  181. if (Dog.Name == name)
  182. {
  183. Dogs.RemoveAt(Getindex(Dog));
  184. return;
  185. }
  186. }
  187. }
  188. #endregion
  189. #region help
  190. else if (choice == "help")
  191. {
  192. Console.WriteLine("Valid inputs: edit, remove, done, help");
  193. }
  194. #endregion
  195. else searching = false;
  196. }
  197. }
  198. #endregion
  199.  
  200. #region exit
  201. void exit()
  202. {
  203. inputhandler("Which dog do you want to remove?:", out string input);
  204. if (input == "yes")
  205. {
  206. running = false;
  207. }
  208. else
  209. {
  210. return;
  211. }
  212. }
  213. #endregion
  214.  
  215. #region getindex
  216. private int Getindex(Dog dog)
  217. {
  218. for (int i = 0; i < Dogs.Count; i++)
  219. {
  220. if (Dogs[i].Equals(dog))
  221. {
  222. return i;
  223. }
  224. }
  225. return -1;
  226. }
  227. #endregion
  228.  
  229. }
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement