static void Main(string[] args) { Garbage[] rottenTomatoes = new Garbage[3]; Dustbin dustbin = new Dustbin("Jenny's handsome"); List <Garbage> tmpList = new List <Garbage>(); for (int i = 0; i < rottenTomatoes.Length; i++) { rottenTomatoes[i] = new Garbage("rotten tomato nr." + (i + 1)); tmpList.Add(rottenTomatoes[i]); } Garbage[] tmpHwc = new Garbage[tmpList.Count]; for (int i = 0; i < tmpList.Count; i++) { tmpHwc[i] = tmpList[i]; } dustbin.HouseWasteContent = tmpHwc; PlasticGarbage milkJug = new PlasticGarbage("plastic milk jug", false); PlasticGarbage[] tmpPla = new PlasticGarbage[dustbin.PlasticContent.Length + 1]; tmpPla[dustbin.PlasticContent.Length] = milkJug; dustbin.PlasticContent = tmpPla; dustbin.DisplayContents(); for (int i = 0; i < 3; i++) { dustbin.ThrowOutGarbage(rottenTomatoes[i]); } Console.WriteLine("Checking them milkjugs out."); if (!milkJug.IsCleaned) { Console.WriteLine("The milkjug isn't clean yet."); milkJug.Clean(); } Console.WriteLine("The milkjug is clean af."); dustbin.ThrowOutGarbage(milkJug); Console.WriteLine("The milkjug's gone."); dustbin.EmptyContents(); Console.WriteLine(); Console.WriteLine(); dustbin.DisplayContents(); }
public void ThrowOutGarbage(Garbage garbage) { if (garbage is PlasticGarbage) { PlasticGarbage garbage1 = (PlasticGarbage)garbage; if (!garbage1.IsCleaned) { garbage1.Clean(); Console.WriteLine("This garbage had to be cleaned"); } Garbage[] tmp = new Garbage[HouseWasteContent.Length + 1]; tmp[HouseWasteContent.Length] = garbage1; HouseWasteContent = tmp; PlasticGarbage[] plaTmp = new PlasticGarbage[PlasticContent.Length - 1]; PlasticContent = plaTmp; } else if (garbage is PaperGarbage) { PaperGarbage garbage1 = (PaperGarbage)garbage; if (!garbage1.IsSqueezed) { garbage1.Squeeze(); Console.WriteLine("This garbage had to be squeezed"); } Garbage[] tmp = new Garbage[HouseWasteContent.Length + 1]; tmp[HouseWasteContent.Length] = garbage1; HouseWasteContent = tmp; PaperGarbage[] papTmp = new PaperGarbage[PaperContent.Length - 1]; PaperContent = papTmp; } else { Garbage[] tmp = new Garbage[HouseWasteContent.Length + 1]; tmp[HouseWasteContent.Length] = garbage; HouseWasteContent = tmp; Garbage[] garTmp = new Garbage[HouseWasteContent.Length - 1]; HouseWasteContent = garTmp; } }