From c4403447c70e7df1e41a5d5381e1469c87670bf2 Mon Sep 17 00:00:00 2001 From: Timourka Date: Tue, 24 Oct 2023 12:10:39 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BC=D0=B5=D0=BD=D1=8F=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=8D=D1=80=D1=8D=D0=B9=D0=9B=D0=B8=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- laba1Loco/GenericDopClass.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) 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; }