public static Bucket[] BuildAr (int[] numAr)
Bucket[] ar = new Bucket[3];
for (i=0; i<ar.Length; i++)
ar[i] = new Bucket (100,numAr[i]);
public static Bucket MaxAmount (Bucket[] ar)
double max = ar[0].GetCurrentAmount();
for (i=1; i<ar.Length; i++)
if (ar[i].GetCurrentAmount()>max)
max = ar[i].GetCurrentAmount();
public static bool IsExist (Bucket[] ar, Bucket buck)
for (i=0; i<ar.Length; i++)
if (ar[i].GetCapacity()==buck.GetCapacity() && ar[i].GetCurrentAmount()==buck.GetCurrentAmount())
public static int SmallBucket (Bucket[] ar)
for (i=0; i<ar.Length; i++)
if (ar[i].GetCurrentAmount()<50)
ar[i].Fill(50-ar[i].GetCurrentAmount());
public static void Print (Bucket[] ar)
for (i=0; i<ar.Length; i++)
Console.WriteLine("bucket number " + (i+1) + ":\n" + ar[i].ToString() + "\n");
-התוכנית תודיע כמה דליים קיימים שתכולתם נמוכה מ50, באמצעות שימוש בפעולה ד, ולסיום תדפיס שוב את ערכי כל הדליים לאחר השינוי, באמצעות הפעולה מסעיף ה.
public static void Main (string[] args)
Console.WriteLine("Hello World");
int[] numAr = new int[3];
for (i=0; i<numAr.Length; i++)
numAr[i] = int.Parse(Console.ReadLine());
Bucket[] ar = BuildAr(numAr);
Console.WriteLine(MaxAmount(ar).ToString());
Bucket b = new Bucket(100,31);
Console.WriteLine("exists");
Console.WriteLine("not exists");
int count = SmallBucket(ar);
Console.WriteLine("there are: " + count + " bucket with small currentAmount");
private double currentAmount;
public Bucket (double capacity)
this.capacity = capacity;
public Bucket (double capacity, double currentAmount)
this.capacity = capacity;
this.currentAmount = currentAmount;
public double GetCapacity ()
public double GetCurrentAmount ()
return this.currentAmount;
public void Empty (double amountToEmpty)
if (amountToEmpty > this.currentAmount)
else this.currentAmount = this.currentAmount - amountToEmpty;
return this.currentAmount == 0;
public void Fill (double amountToFill)
if (this.capacity < this.currentAmount + amountToFill)
this.currentAmount = this.capacity;
this.currentAmount = this.currentAmount+ amountToFill;
public override string ToString ()
return "(my capacity=" + this.capacity +" my current amount=" + this.currentAmount+")";