Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Unit4.BucketLib;
- using Unit4.TurtleLib;
- namespace TestFun
- {
- class Program
- {
- public static void Main(string[] args)
- {
- Ex3Buc();
- }
- static void Ex2()
- {
- Bucket[] Arr = new Bucket[3];
- for (int i = 1; i <= 2; i++)
- {
- Console.WriteLine("enter capacity of bucket number " + i);
- int capacity = int.Parse(Console.ReadLine());
- Console.WriteLine("enter name of bucket number " + i);
- string name = Console.ReadLine();
- Arr[i] = new Bucket(capacity, name);
- Console.WriteLine("enter amount to fill to number " + i);
- double amount = double.Parse(Console.ReadLine());
- Arr[i].Fill(amount);
- Console.WriteLine(i + ": " + Arr[i].ToString());
- }
- }
- static void Ex3()
- {
- Bucket[] Arr = new Bucket[4];
- int[] capac = new int[3];
- for (int i = 1; i <= 3; i++)
- {
- Console.WriteLine("Enter name for " + i);
- Arr[i] = new Bucket(100, Console.ReadLine());
- }
- for (int i = 0; i < 3; i++)
- {
- Console.WriteLine("Enter how much to fill number " + i);
- capac[i] = CheckCapacity();
- }
- int[] sorted = IndexOfBiggestOfArray(capac);
- for (int i = 0; i < 3; i++)
- {
- Arr[i + 1].Fill(sorted[i]);
- }
- for (int i = 1; i <= 3; i++)
- {
- Console.WriteLine("arr" + i + " " + Arr[i].ToString()); ;
- }
- }
- static int CheckCapacity()
- {
- int capacity;
- capacity = int.Parse(Console.ReadLine());
- while (capacity > 100 && capacity < 0)
- {
- Console.WriteLine("Wrong! do it again please: ");
- capacity = int.Parse(Console.ReadLine());
- }
- return capacity;
- }
- static int[] IndexOfBiggestOfArray(int[] capacity)
- {
- int[] sortedArr = new int[capacity.Length];
- for (int i = 0; i < capacity.Length; i++)
- {
- int maxIndex = 0;
- for (int j = 1; j < capacity.Length; j++)
- {
- if (capacity[j] > capacity[maxIndex])
- {
- maxIndex = j;
- }
- }
- sortedArr[i] = capacity[maxIndex];
- capacity[maxIndex] = 0;
- }
- return sortedArr;
- }
- static void Ex4()
- {
- Bucket[] bucs = new Bucket[4];
- int firstNum,
- hefresh;
- Console.WriteLine("Enter Amount to fill to first Bucket: ");
- firstNum = int.Parse(Console.ReadLine());
- Console.WriteLine("Now enter the hefresh between the buckets: ");
- hefresh = int.Parse(Console.ReadLine());
- for (int i = 0; i < 4; i++)
- {
- Console.WriteLine("Enter name: ");
- bucs[i] = new Bucket(100, Console.ReadLine());
- bucs[i].Fill(firstNum + hefresh * i);
- if (i == 3)
- {
- if (firstNum + hefresh * i > 100)
- {
- Console.WriteLine("Enter New Fill: ");
- bucs[i] = new Bucket(CheckCapacity(), Console.ReadLine());
- }
- }
- }
- for (int i = 0; i < 4; i++)
- {
- Console.WriteLine("bucket" + i + " " + bucs[i].ToString());
- }
- }
- static void Ex5()
- {
- Bucket b1 = new Bucket(12, "name");
- b1.Fill(6);
- Console.WriteLine("b1: " + b1.ToString());
- b1.Empty();
- Console.WriteLine("b1: " + b1.ToString());
- }
- static void Ex6()
- {
- Bucket b1 = new Bucket(12, "Name");
- b1.Fill(6);
- Console.WriteLine("b1: " + b1.ToString());
- if (b1.IsEmpty())
- {
- Console.WriteLine("b1 is empty");
- }
- else
- {
- Console.WriteLine("b1 is not empty");
- Console.WriteLine("Test");
- }
- b1.Empty();
- if (b1.IsEmpty())
- {
- Console.WriteLine("now b1 is empty");
- Console.WriteLine("b1: " + b1.ToString());
- }
- }
- static void Ex10()
- {
- Console.WriteLine("Enter capacity for bucket: ");
- int capacity = int.Parse(Console.ReadLine());
- while (capacity < 0)
- {
- capacity = CheckForPos();
- }
- Console.WriteLine("Enter name: ");
- Bucket b1 = new Bucket(capacity, Console.ReadLine());
- Console.WriteLine("Enter to Fill: ");
- int fill = int.Parse(Console.ReadLine());
- while (fill < 0 || (capacity - b1.GetCurrentAmount() - fill < 1))
- {
- if (fill < 0)
- {
- fill = CheckForPos();
- }
- else
- {
- b1.Fill(fill);
- }
- }
- }
- static int CheckForPos()
- {
- Console.WriteLine("Wrong! enter again, and positive: ");
- int num = int.Parse(Console.ReadLine());
- return num;
- }
- static void Shahar()
- {
- Turtle t1 = new Turtle();
- //t1.
- t1.MoveForward(5);
- }
- static void Ex1()
- {
- Turtle t1 = new Turtle();
- t1.TailDown();
- t1.MoveForward(100);
- t1.TurnRight(90);
- t1.MoveForward(90);
- t1.TurnRight(90);
- t1.MoveForward(100);
- t1.TurnRight(90);
- t1.MoveForward(100);
- t1.TailUp();
- t1.MoveForward(100);
- }
- static void Hexagon()
- {
- Turtle t1 = new Turtle();
- t1.TailDown();
- t1.TurnRight(60);
- t1.MoveForward(70);
- t1.TurnLeft(60);
- t1.MoveForward(70);
- t1.TurnLeft(60);
- t1.MoveForward(70);
- t1.TurnLeft(60);
- t1.MoveForward(70);
- t1.TurnLeft(60);
- t1.MoveForward(70);
- t1.TurnLeft(60);
- t1.MoveForward(70);
- t1.TurnLeft(30);
- t1.MoveForward(100);
- t1.TurnRight(90);
- t1.MoveForward(25);
- t1.TurnRight(90);
- t1.MoveForward(200);
- t1.TurnRight(90);
- t1.MoveForward(25);
- t1.TurnRight(90);
- t1.MoveForward(100);
- }
- static void House()
- {
- }
- static void Ex3Buc()
- {
- Console.WriteLine("Enter number: ");
- int n = int.Parse(Console.ReadLine());
- Bucket[] arr = new Bucket[n];
- int[] contains = new int[n];
- Random random = new Random();
- int randomLiters;
- for (int i = 0; i < n; i++)
- {
- randomLiters = random.Next(1, 10);
- arr[i] = new Bucket(randomLiters, (i+1).ToString());
- }
- for (int i = 0; i < n; i++)
- {
- randomLiters = random.Next(1, 10);
- while (randomLiters > arr[i].GetCapacity())
- {
- randomLiters = random.Next(1, 10);
- }
- Console.WriteLine("Litters are " + randomLiters + ", capa is: " + arr[i].GetCapacity());
- arr[i].Fill(randomLiters);
- contains[i] = randomLiters;
- }
- int[] sorted = SortArray(contains);
- for (int i = 0; i < n; i++)
- {
- Console.WriteLine(sorted[n-1-i] + " ");
- }
- }
- static int[] SortArray(int[] capacity)
- {
- int[] sortedArr = new int[capacity.Length];
- for (int i = 0; i < capacity.Length; i++)
- {
- int maxIndex = 0;
- for (int j = 1; j < capacity.Length; j++)
- {
- if (capacity[j] > capacity[maxIndex])
- {
- maxIndex = j;
- }
- }
- sortedArr[i] = capacity[maxIndex];
- capacity[maxIndex] = 0;
- }
- return sortedArr;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement