Example #1
0
        static void Main(string[] args)
        {
            Garbage[] rottenTomatoes = new Garbage[3];
            for (int i = 0; i < 3; i++)
            {
                rottenTomatoes[i] = new Garbage("rotten tomato nr " + (i + 1));
            }
            PlasticGarbage milkJug  = new PlasticGarbage("milkjug", false);
            Dustbin        trashcan = new Dustbin("blue");

            trashcan.DisplayContents();
            Console.ReadLine();

            for (int i = 0; i < 3; i++)
            {
                trashcan.ThrowOutGarbage(rottenTomatoes[i]);
            }
            if (!milkJug.IsClean())
            {
                milkJug.Clean();
            }
            Console.ReadLine();
            trashcan.ThrowOutGarbage(milkJug);

            trashcan.DisplayContents();
            Console.ReadLine();
            trashcan.EmptyContents();
            trashcan.DisplayContents();
        }
Example #2
0
 public Dustbin(string color)
 {
     this.color        = color;
     paperContent      = new PaperGarbage[0];
     plasticContent    = new PlasticGarbage[0];
     houseWasteContent = new Garbage[0];
 }
Example #3
0
 public void ThrowOutGarbage(Garbage garbage)
 {
     if (garbage is PlasticGarbage)
     {
         PlasticGarbage plasticTrash = (PlasticGarbage)garbage;
         if (plasticTrash.IsClean())
         {
             int newLength = plasticContent.Length + 1;
             plasticContent = new PlasticGarbage[newLength];
             plasticContent[newLength - 1] = plasticTrash;
             Console.WriteLine("Plastic +1");
         }
         else
         {
             throw new DustbinContentException();
         }
     }
     else if (garbage is PaperGarbage)
     {
         PaperGarbage paperTrash = (PaperGarbage)garbage;
         if (paperTrash.IsSqueezed())
         {
             int newLength = paperContent.Length + 1;
             paperContent = new PaperGarbage[newLength];
             paperContent[newLength - 1] = paperTrash;
             Console.WriteLine("Paper +1");
         }
         else
         {
             throw new DustbinContentException();
         }
     }
     else if (garbage is Garbage)
     {
         int newLength = houseWasteContent.Length + 1;
         var tmp       = new Garbage[newLength];
         for (int i = 0; i < houseWasteContent.Length; i++)
         {
             tmp[i] = houseWasteContent[i];
         }
         houseWasteContent = tmp;
         houseWasteContent[newLength - 1] = garbage;
         Console.WriteLine(" Housewaste +1 ");
     }
     else
     {
         throw new DustbinContentException();
     }
 }
Example #4
0
 public void EmptyContents()
 {
     paperContent      = new PaperGarbage[0];
     plasticContent    = new PlasticGarbage[0];
     houseWasteContent = new Garbage[0];
 }