Advertisement
Guest User

Compurters

a guest
Oct 13th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Unit4.BucketLib;
  6. using Unit4.TurtleLib;
  7.  
  8. namespace TestFun
  9. {
  10. class Program
  11. {
  12.  
  13. public static void Main(string[] args)
  14. {
  15. Ex3Buc();
  16. }
  17.  
  18. static void Ex2()
  19. {
  20. Bucket[] Arr = new Bucket[3];
  21. for (int i = 1; i <= 2; i++)
  22. {
  23. Console.WriteLine("enter capacity of bucket number " + i);
  24. int capacity = int.Parse(Console.ReadLine());
  25.  
  26. Console.WriteLine("enter name of bucket number " + i);
  27. string name = Console.ReadLine();
  28.  
  29. Arr[i] = new Bucket(capacity, name);
  30.  
  31. Console.WriteLine("enter amount to fill to number " + i);
  32. double amount = double.Parse(Console.ReadLine());
  33.  
  34. Arr[i].Fill(amount);
  35.  
  36. Console.WriteLine(i + ": " + Arr[i].ToString());
  37. }
  38. }
  39.  
  40. static void Ex3()
  41. {
  42. Bucket[] Arr = new Bucket[4];
  43. int[] capac = new int[3];
  44. for (int i = 1; i <= 3; i++)
  45. {
  46. Console.WriteLine("Enter name for " + i);
  47. Arr[i] = new Bucket(100, Console.ReadLine());
  48. }
  49. for (int i = 0; i < 3; i++)
  50. {
  51. Console.WriteLine("Enter how much to fill number " + i);
  52. capac[i] = CheckCapacity();
  53. }
  54.  
  55. int[] sorted = IndexOfBiggestOfArray(capac);
  56. for (int i = 0; i < 3; i++)
  57. {
  58. Arr[i + 1].Fill(sorted[i]);
  59. }
  60.  
  61. for (int i = 1; i <= 3; i++)
  62. {
  63. Console.WriteLine("arr" + i + " " + Arr[i].ToString()); ;
  64. }
  65.  
  66. }
  67.  
  68. static int CheckCapacity()
  69. {
  70. int capacity;
  71. capacity = int.Parse(Console.ReadLine());
  72. while (capacity > 100 && capacity < 0)
  73. {
  74. Console.WriteLine("Wrong! do it again please: ");
  75. capacity = int.Parse(Console.ReadLine());
  76. }
  77. return capacity;
  78. }
  79.  
  80. static int[] IndexOfBiggestOfArray(int[] capacity)
  81. {
  82. int[] sortedArr = new int[capacity.Length];
  83. for (int i = 0; i < capacity.Length; i++)
  84. {
  85. int maxIndex = 0;
  86. for (int j = 1; j < capacity.Length; j++)
  87. {
  88. if (capacity[j] > capacity[maxIndex])
  89. {
  90. maxIndex = j;
  91. }
  92. }
  93. sortedArr[i] = capacity[maxIndex];
  94. capacity[maxIndex] = 0;
  95. }
  96. return sortedArr;
  97. }
  98.  
  99. static void Ex4()
  100. {
  101. Bucket[] bucs = new Bucket[4];
  102. int firstNum,
  103. hefresh;
  104. Console.WriteLine("Enter Amount to fill to first Bucket: ");
  105. firstNum = int.Parse(Console.ReadLine());
  106. Console.WriteLine("Now enter the hefresh between the buckets: ");
  107. hefresh = int.Parse(Console.ReadLine());
  108.  
  109. for (int i = 0; i < 4; i++)
  110. {
  111. Console.WriteLine("Enter name: ");
  112. bucs[i] = new Bucket(100, Console.ReadLine());
  113. bucs[i].Fill(firstNum + hefresh * i);
  114. if (i == 3)
  115. {
  116. if (firstNum + hefresh * i > 100)
  117. {
  118. Console.WriteLine("Enter New Fill: ");
  119. bucs[i] = new Bucket(CheckCapacity(), Console.ReadLine());
  120. }
  121. }
  122. }
  123.  
  124. for (int i = 0; i < 4; i++)
  125. {
  126. Console.WriteLine("bucket" + i + " " + bucs[i].ToString());
  127. }
  128. }
  129.  
  130. static void Ex5()
  131. {
  132. Bucket b1 = new Bucket(12, "name");
  133. b1.Fill(6);
  134. Console.WriteLine("b1: " + b1.ToString());
  135. b1.Empty();
  136. Console.WriteLine("b1: " + b1.ToString());
  137. }
  138.  
  139. static void Ex6()
  140. {
  141. Bucket b1 = new Bucket(12, "Name");
  142. b1.Fill(6);
  143. Console.WriteLine("b1: " + b1.ToString());
  144. if (b1.IsEmpty())
  145. {
  146. Console.WriteLine("b1 is empty");
  147. }
  148. else
  149. {
  150. Console.WriteLine("b1 is not empty");
  151. Console.WriteLine("Test");
  152. }
  153. b1.Empty();
  154. if (b1.IsEmpty())
  155. {
  156. Console.WriteLine("now b1 is empty");
  157. Console.WriteLine("b1: " + b1.ToString());
  158. }
  159. }
  160.  
  161. static void Ex10()
  162. {
  163. Console.WriteLine("Enter capacity for bucket: ");
  164. int capacity = int.Parse(Console.ReadLine());
  165. while (capacity < 0)
  166. {
  167. capacity = CheckForPos();
  168. }
  169. Console.WriteLine("Enter name: ");
  170. Bucket b1 = new Bucket(capacity, Console.ReadLine());
  171.  
  172. Console.WriteLine("Enter to Fill: ");
  173. int fill = int.Parse(Console.ReadLine());
  174. while (fill < 0 || (capacity - b1.GetCurrentAmount() - fill < 1))
  175. {
  176. if (fill < 0)
  177. {
  178. fill = CheckForPos();
  179. }
  180. else
  181. {
  182. b1.Fill(fill);
  183. }
  184. }
  185.  
  186. }
  187.  
  188. static int CheckForPos()
  189. {
  190. Console.WriteLine("Wrong! enter again, and positive: ");
  191. int num = int.Parse(Console.ReadLine());
  192. return num;
  193. }
  194.  
  195. static void Shahar()
  196. {
  197. Turtle t1 = new Turtle();
  198. //t1.
  199. t1.MoveForward(5);
  200.  
  201. }
  202.  
  203. static void Ex1()
  204. {
  205. Turtle t1 = new Turtle();
  206.  
  207. t1.TailDown();
  208.  
  209. t1.MoveForward(100);
  210. t1.TurnRight(90);
  211. t1.MoveForward(90);
  212. t1.TurnRight(90);
  213. t1.MoveForward(100);
  214. t1.TurnRight(90);
  215. t1.MoveForward(100);
  216.  
  217. t1.TailUp();
  218. t1.MoveForward(100);
  219. }
  220.  
  221. static void Hexagon()
  222. {
  223. Turtle t1 = new Turtle();
  224. t1.TailDown();
  225.  
  226. t1.TurnRight(60);
  227. t1.MoveForward(70);
  228. t1.TurnLeft(60);
  229. t1.MoveForward(70);
  230. t1.TurnLeft(60);
  231. t1.MoveForward(70);
  232. t1.TurnLeft(60);
  233. t1.MoveForward(70);
  234. t1.TurnLeft(60);
  235. t1.MoveForward(70);
  236. t1.TurnLeft(60);
  237. t1.MoveForward(70);
  238. t1.TurnLeft(30);
  239. t1.MoveForward(100);
  240. t1.TurnRight(90);
  241. t1.MoveForward(25);
  242. t1.TurnRight(90);
  243. t1.MoveForward(200);
  244. t1.TurnRight(90);
  245. t1.MoveForward(25);
  246. t1.TurnRight(90);
  247. t1.MoveForward(100);
  248.  
  249. }
  250.  
  251. static void House()
  252. {
  253.  
  254. }
  255.  
  256. static void Ex3Buc()
  257. {
  258. Console.WriteLine("Enter number: ");
  259. int n = int.Parse(Console.ReadLine());
  260.  
  261. Bucket[] arr = new Bucket[n];
  262. int[] contains = new int[n];
  263.  
  264. Random random = new Random();
  265. int randomLiters;
  266.  
  267. for (int i = 0; i < n; i++)
  268. {
  269. randomLiters = random.Next(1, 10);
  270. arr[i] = new Bucket(randomLiters, (i+1).ToString());
  271. }
  272.  
  273. for (int i = 0; i < n; i++)
  274. {
  275. randomLiters = random.Next(1, 10);
  276. while (randomLiters > arr[i].GetCapacity())
  277. {
  278. randomLiters = random.Next(1, 10);
  279. }
  280. Console.WriteLine("Litters are " + randomLiters + ", capa is: " + arr[i].GetCapacity());
  281. arr[i].Fill(randomLiters);
  282. contains[i] = randomLiters;
  283. }
  284.  
  285. int[] sorted = SortArray(contains);
  286. for (int i = 0; i < n; i++)
  287. {
  288. Console.WriteLine(sorted[n-1-i] + " ");
  289. }
  290.  
  291. }
  292.  
  293. static int[] SortArray(int[] capacity)
  294. {
  295. int[] sortedArr = new int[capacity.Length];
  296. for (int i = 0; i < capacity.Length; i++)
  297. {
  298. int maxIndex = 0;
  299. for (int j = 1; j < capacity.Length; j++)
  300. {
  301. if (capacity[j] > capacity[maxIndex])
  302. {
  303. maxIndex = j;
  304. }
  305. }
  306. sortedArr[i] = capacity[maxIndex];
  307. capacity[maxIndex] = 0;
  308. }
  309. return sortedArr;
  310. }
  311.  
  312.  
  313.  
  314. }
  315.  
  316. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement