1 Commits

Author SHA1 Message Date
a62ef91a8a Implement Übungstest 4 2022-05-12 14:35:07 +02:00

View File

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