From a62ef91a8a7f2a30ad01b5df96d84149bf69668f Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Thu, 12 May 2022 14:35:07 +0200 Subject: [PATCH] =?UTF-8?q?Implement=20=C3=9Cbungstest=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/HierarchicalSystem.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/HierarchicalSystem.java b/src/HierarchicalSystem.java index 3ec93ca..84cbdaf 100644 --- a/src/HierarchicalSystem.java +++ b/src/HierarchicalSystem.java @@ -8,8 +8,8 @@ import codedraw.CodeDraw; public class HierarchicalSystem implements CosmicSystem { private final NamedBodyForcePair central; - private final CosmicSystem[] orbit; - private final CosmicSystem[] all; + private CosmicSystem[] orbit; + private CosmicSystem[] all; /** * Initializes this system with a name and a central body. @@ -110,4 +110,21 @@ public class HierarchicalSystem implements CosmicSystem { return sb.toString(); } + + /** + * Puts the system 'cs' at the first place in the orbit of this system. + * Precondition: cs != null + */ + public boolean putFirst(CosmicSystem cs) { + CosmicSystem[] old = orbit; + orbit = new CosmicSystem[old.length + 1]; + all = new CosmicSystem[old.length + 2]; + + orbit[0] = cs; + System.arraycopy(old, 0, orbit, 1, old.length); + all[0] = central; + System.arraycopy(orbit, 0, all, 1, orbit.length); + + return true; + } }