From 9a93dd2af5cecf378a01db63cbaf6cbdc76540d2 Mon Sep 17 00:00:00 2001 From: Zhelovanov_Dmitrii Date: Thu, 22 Dec 2022 21:57:30 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB(?= =?UTF-8?q?=D0=B0)=20=D0=BD=D0=B0=20'MyParametrClass.java'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MyParametrClass.java | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/MyParametrClass.java b/MyParametrClass.java index 59abc76..876b05f 100644 --- a/MyParametrClass.java +++ b/MyParametrClass.java @@ -2,34 +2,35 @@ import java.util.ArrayList; import java.util.Random; public class MyParametrClass { - private final Object[] EntityArray; - private final Object[] BlocksArray; + private final ArrayList EntityArray; + private final ArrayList BlocksArray; int entitiesCount = 0; int blocksCount = 0; public MyParametrClass(int entitiesCount, int blocksCount) { - EntityArray = new Object[entitiesCount]; - BlocksArray = new Object[blocksCount]; + EntityArray = new ArrayList(); + BlocksArray = new ArrayList(); } public void Insert(T battleship){ - if(entitiesCount < EntityArray.length) { - EntityArray[entitiesCount] = battleship; + + EntityArray.add(battleship); entitiesCount++; - } + } public void Insert(U drawningBlocks){ - if(blocksCount < BlocksArray.length) { - BlocksArray[blocksCount] = drawningBlocks; + + BlocksArray.add(drawningBlocks); blocksCount++; - } + } public DrawningBattleship GetDrawningBattleship() { Random random = new Random(); - int entityIndex = random.nextInt(EntityArray.length); - int blockIndex = random.nextInt(BlocksArray.length); + int entityIndex = random.nextInt(EntityArray.size()); + int blockIndex = random.nextInt( BlocksArray.size()); - EntityBattleship battleship = (T)EntityArray[entityIndex]; - IDrawningBlocks blocks = (U)BlocksArray[blockIndex]; + + EntityBattleship battleship = EntityArray.get(entityIndex); + IDrawningBlocks blocks = BlocksArray.get(blockIndex); if (battleship instanceof EntityLinkor) { return new DrawningLinkor(battleship, blocks);