package ProjectElectricLocomotive; import java.util.ArrayList; import java.util.Random; public class DopClassParameters { public T[] _entityLocomotive; public U[] _idrawningWheels; int _locomotivesCount; int _idrawningWheelsCount; private int _pictureWidth; private int _pictureHeight; public DopClassParameters(int count, int width, int height) { _entityLocomotive = (T[]) new EntityLocomotive[count]; _idrawningWheels = (U[]) new IDrawingWheels[count]; _pictureWidth = width; _pictureHeight = height; _locomotivesCount = 0; _idrawningWheelsCount = 0; } public void Add(T entityLocoObj) { if (_locomotivesCount < _entityLocomotive.length) { _entityLocomotive[_locomotivesCount] = entityLocoObj; _locomotivesCount++; } } public void Add(U idrawingWheels) { if (_idrawningWheelsCount < _idrawningWheels.length) { _idrawningWheels[_idrawningWheelsCount] = idrawingWheels; _idrawningWheelsCount++; } } public DrawingLocomotive RandomLocomotive(int pictureWidth, int pictureHeight) { Random rnd = new Random(); if (_entityLocomotive == null || _idrawningWheels == null) { return null; } T entityLocomotive = _entityLocomotive[rnd.nextInt(_locomotivesCount)]; U idrawingWheels = _idrawningWheels[rnd.nextInt(_idrawningWheelsCount)]; DrawingLocomotive drawLocomotive; if (entityLocomotive instanceof EntityElectricLocomotive) { drawLocomotive = new DrawingElectricLocomotive( (EntityElectricLocomotive) entityLocomotive, idrawingWheels, pictureWidth, pictureHeight ); } else { drawLocomotive = new DrawingLocomotive( entityLocomotive, idrawingWheels, pictureWidth, pictureHeight ); } return drawLocomotive; } }