package CollectionGenericObjects; import Drawnings.DrawningTruck; import java.awt.*; import java.util.Random; public class AbstractCompany { protected int _placeSizeWidth = 120; protected int _placeSizeHeight = 120; protected int _pictureWidth; protected int _pictureHeight; public ICollectionGenericObjects _collection = null; private int GetMaxCount (){ return _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);} public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection) { _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = collection; _collection.SetMaxCount( GetMaxCount(), DrawningTruck.class); } public DrawningTruck GetRandomObject() { Random random = new Random(); return _collection.Get(random.nextInt(GetMaxCount())); } public void DrawBackgound(Graphics g) { } protected void SetObjectsPosition() { } public void SetPosition() { SetObjectsPosition(); } }