diff --git a/laba1Loco/GenericDopClass.java b/laba1Loco/GenericDopClass.java index 65235c9..b8c0681 100644 --- a/laba1Loco/GenericDopClass.java +++ b/laba1Loco/GenericDopClass.java @@ -1,11 +1,12 @@ package laba1Loco; +import java.util.ArrayList; import java.util.Random; public class GenericDopClass { - private Object[] Trains; - private Object[] Wheels; + private ArrayList Trains; + private ArrayList Wheels; private int maxCountTrains; private int countTrains; private int maxCountWheels; @@ -23,8 +24,8 @@ public class GenericDopClass { public GenericDopClass(int _maxCountTrains, int _maxCountWheels, int pictureWidth, int pictureHeight){ maxCountTrains = _maxCountTrains; maxCountWheels = _maxCountWheels; - Trains = new Object[maxCountTrains]; - Wheels = new Object[maxCountWheels]; + Trains = new ArrayList(maxCountTrains); + Wheels = new ArrayList(maxCountWheels); countTrains = 0; countWheels = 0; _pictureWidth = pictureWidth; @@ -37,7 +38,7 @@ public class GenericDopClass { return false; if (countTrains > maxCountTrains) return false; - Trains[countTrains++] = train; + Trains.add(countTrains++, train); return true; } @@ -46,7 +47,7 @@ public class GenericDopClass { return false; if (countWheels > maxCountWheels) return false; - Wheels[countWheels++] = wheel; + Wheels.add(countWheels++, wheel); return true; } @@ -56,11 +57,11 @@ public class GenericDopClass { int i = random.nextInt(countTrains); int j = random.nextInt(countWheels); DrawingTrain drawingTrain; - if (Trains[i] instanceof EntityLoco){ - drawingTrain = new DrawingLoco((EntityLoco)Trains[i], (IWheelDrawing)Wheels[j], _pictureWidth, _pictureHeight); + if (Trains.get(i) instanceof EntityLoco){ + drawingTrain = new DrawingLoco((EntityLoco)Trains.get(i), Wheels.get(j), _pictureWidth, _pictureHeight); } else{ - drawingTrain = new DrawingTrain((EntityTrain)Trains[i], (IWheelDrawing)Wheels[j], _pictureWidth, _pictureHeight); + drawingTrain = new DrawingTrain(Trains.get(i), Wheels.get(j), _pictureWidth, _pictureHeight); } return drawingTrain; }