public Dustbin(string color) { this.color = color; paperContent = new PaperGarbage[0]; plasticContent = new PlasticGarbage[0]; houseWasteContent = new Garbage[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(); } }
public void EmptyContents() { paperContent = new PaperGarbage[0]; plasticContent = new PlasticGarbage[0]; houseWasteContent = new Garbage[0]; }