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; + } }