diff --git a/angabe/Aufgabenblatt2.md b/angabe/Aufgabenblatt2.md index 335f5a6..7c9349f 100644 --- a/angabe/Aufgabenblatt2.md +++ b/angabe/Aufgabenblatt2.md @@ -61,5 +61,3 @@ Himmelskörpern: - Implementierung von `BodyForceMap`: 2 Punkte - Anpassung von `Simulation`: 1 Punkt - Gesamt: 5 Punkte - - diff --git a/angabe/Aufgabenblatt3.md b/angabe/Aufgabenblatt3.md index cef24c5..5766d57 100644 --- a/angabe/Aufgabenblatt3.md +++ b/angabe/Aufgabenblatt3.md @@ -47,4 +47,3 @@ Allgemeiner Hinweis: bei einigen Methoden sind Vorbedingungen (_pre-conditions_) - Implementierung von `BodyForceTreeMap`: 2 Punkte - Implementierung von `Simulation3`: 1 Punkt - Gesamt: 5 Punkte - diff --git a/angabe/Aufgabenblatt4.md b/angabe/Aufgabenblatt4.md index e587b90..cab37fe 100644 --- a/angabe/Aufgabenblatt4.md +++ b/angabe/Aufgabenblatt4.md @@ -106,7 +106,7 @@ wird. Sie dürfen hier keine Typumwandlungen (Casts) und auch nicht die Methoden - Es ist möglich, aber nicht verlangt, `addForceTo(CosmicSystem cs)` ohne Verwendung von `getBodies()` zu implementieren. Dazu kann in `addForceTo(CosmicSystem cs)` der Zugriff auf -die eizelnen Körper in `cs` dadurch erreicht werden, dass `this` für alle seine Himmelskörper +die einzelnen Körper in `cs` dadurch erreicht werden, dass `this` für alle seine Himmelskörper und Untersysteme `addForceTo(cs)` aufruft. Wird beim rekursiven Abstieg ein einzelner Himmelskörper erreicht (Blattknoten) ruft dieser `cs.addForceFrom(this)` auf. @@ -120,6 +120,3 @@ verändert wird, wenn `this` und `b` derselbe Himmelskörper sind. - Implementierung von `Simulation4`: 1 Punkte - Gesamt: 5 Punkte - - - diff --git a/src/Aufgabe4Test.java b/src/Aufgabe4Test.java index 4c053dc..422940e 100644 --- a/src/Aufgabe4Test.java +++ b/src/Aufgabe4Test.java @@ -1,112 +1,78 @@ -import java.util.ArrayList; -import java.util.Arrays; import java.util.HashSet; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; public class Aufgabe4Test { - public static void main(String[] args) { + private NamedBodyForcePair sun2, mercury2, venus2, earth2, moon2, mars2, deimos2, phobos2, vesta2, pallas2, hygiea2, ceres2; + public void resetBodies() { + sun2 = new NamedBodyForcePair(SolSystem4.SUN); + earth2 = new NamedBodyForcePair(SolSystem4.EARTH); + moon2 = new NamedBodyForcePair(SolSystem4.MOON); + mars2 = new NamedBodyForcePair(SolSystem4.MARS); + deimos2 = new NamedBodyForcePair(SolSystem4.DEIMOS); + phobos2 = new NamedBodyForcePair(SolSystem4.PHOBOS); + mercury2 = new NamedBodyForcePair(SolSystem4.MERCURY); + venus2 = new NamedBodyForcePair(SolSystem4.VENUS); + vesta2 = new NamedBodyForcePair(SolSystem4.VESTA); + pallas2 = new NamedBodyForcePair(SolSystem4.PALLAS); + hygiea2 = new NamedBodyForcePair(SolSystem4.HYGIEA); + ceres2 = new NamedBodyForcePair(SolSystem4.CERES); + } + + @Test + public void testEP2() { + assertEquals(2, 3); //TODO: uncomment for testing /* - //test classes HierachicalSystem and NamedBodyForcePair + //test classes HierarchicalSystem and NamedBodyForcePair // create 12 bodies - Body sun1, earth1, moon1, mars1, deimos1, phobos1, mercury1, venus1, vesta1, pallas1, - hygiea1, ceres1; - NamedBodyForcePair sun2, mercury2, venus2, earth2, moon2, mars2, deimos2, phobos2, vesta2, - pallas2, hygiea2, ceres2; + Body sun1, earth1, moon1, mars1, deimos1, phobos1, mercury1, venus1, vesta1, pallas1, hygiea1, ceres1; + sun1 = new Body(1.989E30, new Vector3(0.0, 0.0, 0.0), new Vector3(0.0, 0.0, 0.0)); + earth1 = new Body(5.972E24, new Vector3(-6.13135922534815E10, -1.383789852227691E11, 2.719682263474911E7), new Vector3(26832.720535473603, -11948.23168764519, 1.9948243075997851)); + moon1 = new Body(7.349E22, new Vector3(-6.132484773775896E10, -1.387394951280871E11, 1.701046736294776E7), new Vector3(27916.62329282941, -12020.39526008238, -94.89703264508708)); + mars1 = new Body(6.41712E23, new Vector3(-1.7923193702925848E11, 1.726665823982123E11, 7.991673845249474E9), new Vector3(-15925.78496403673, -15381.16179928219, 68.67560910598857)); + deimos1 = new Body(1.8E20, new Vector3(-1.792255010450533E11, 1.726891122683271E11, 7.990659337380297E9), new Vector3(-17100.476719804457, -15020.348656808, 631.2927851249581)); + phobos1 = new Body(1.08E20, new Vector3(-1.792253482539647E11, 1.72661109673625E11, 7.987848354800322E9), new Vector3(-14738.203714241401, -13671.17675223948, -411.0012490555253)); + mercury1 = new Body(3.301E23, new Vector3(-5.167375560011926E10, -4.217574885682655E10, 1.14808913958168E9), new Vector3(21580.25398577148, -34951.03632847389, -4835.225596525241)); + venus1 = new Body(4.86747E24, new Vector3(-3.123150865740532E10, 1.0395568504115701E11, 3.173401325838074E9), new Vector3(-33748.180519629335, -10014.25141045021, 1809.94488874165)); + vesta1 = new Body(2.5908E20, new Vector3(-3.337493557929893E11, -4.7147908276077385E10, 4.1923010146878105E10), new Vector3(4440.54247538484, -19718.49074006637, 48.06573124543601)); + pallas1 = new Body(2.14E20, new Vector3(4.3452066613895575E11, -2.057319365171432E11, 1.0549957423213101E11), new Vector3(5058.947582097117, 11184.45711782372, -8183.524138259704)); + hygiea1 = new Body(8.32E19, new Vector3(-3.983943433707043E11, 2.325833000024021E11, -2.233667695713672E10), new Vector3(-6931.864585548552, -15686.8108598699, -690.5791992347208)); + ceres1 = new Body(9.394E20, new Vector3(3.781372641419032E11, 1.96718960466285E11, -6.366459168068592E10), new Vector3(-8555.324226752316, 14718.33755980907, 2040.230135060142)); - sun1 = new Body(1.989E30, new Vector3(0.0,0.0,0.0), new Vector3(0.0,0.0, - 0.0)); - earth1 = new Body(5.972E24, new Vector3(-6.13135922534815E10,-1.383789852227691E11, - 2.719682263474911E7), new Vector3(26832.720535473603,-11948.23168764519,1.9948243075997851)); - moon1 = new Body(7.349E22, new Vector3(-6.132484773775896E10,-1.387394951280871E11, - 1.701046736294776E7), new Vector3(27916.62329282941,-12020.39526008238,-94.89703264508708)); - mars1 = new Body(6.41712E23, new Vector3(-1.7923193702925848E11,1.726665823982123E11 - ,7.991673845249474E9), new Vector3(-15925.78496403673,-15381.16179928219,68.67560910598857)); - deimos1 = new Body(1.8E20, new Vector3(-1.792255010450533E11,1.726891122683271E11, - 7.990659337380297E9), new Vector3(-17100.476719804457,-15020.348656808,631.2927851249581)); - phobos1 = new Body(1.08E20, new Vector3(-1.792253482539647E11,1.72661109673625E11, - 7.987848354800322E9), new Vector3(-14738.203714241401,-13671.17675223948,-411.0012490555253)); - mercury1 = new Body(3.301E23, new Vector3(-5.167375560011926E10, - -4.217574885682655E10,1.14808913958168E9), new Vector3(21580.25398577148,-34951.03632847389,-4835.225596525241)); - venus1 = new Body(4.86747E24, new Vector3(-3.123150865740532E10, - 1.0395568504115701E11,3.173401325838074E9), new Vector3(-33748.180519629335,-10014.25141045021,1809.94488874165)); - vesta1 = new Body(2.5908E20, new Vector3(-3.337493557929893E11, - -4.7147908276077385E10,4.1923010146878105E10), new Vector3(4440.54247538484,-19718.49074006637,48.06573124543601)); - pallas1 = new Body(2.14E20, new Vector3(4.3452066613895575E11,-2.057319365171432E11, - 1.0549957423213101E11), new Vector3(5058.947582097117,11184.45711782372,-8183.524138259704)); - hygiea1 = new Body(8.32E19, new Vector3(-3.983943433707043E11,2.325833000024021E11, - -2.233667695713672E10), new Vector3(-6931.864585548552,-15686.8108598699,-690.5791992347208)); - ceres1 = new Body(9.394E20, new Vector3(3.781372641419032E11,1.96718960466285E11, - -6.366459168068592E10), new Vector3(-8555.324226752316,14718.33755980907,2040.230135060142)); - - Body[] bodies = new Body[]{sun1, mercury1, venus1, earth1, moon1, mars1, deimos1, phobos1, - vesta1, pallas1, hygiea1, ceres1}; + Body[] bodies = new Body[]{sun1, mercury1, venus1, earth1, moon1, mars1, deimos1, phobos1, vesta1, pallas1, hygiea1, ceres1}; Vector3[] forceOnBody = new Vector3[bodies.length]; + resetBodies(); + NamedBodyForcePair[] pairs = new NamedBodyForcePair[]{sun2, mercury2, venus2, earth2, moon2, mars2, deimos2, phobos2, vesta2, pallas2, hygiea2, ceres2}; - // create the same 12 named body-force pairs - sun2 = new NamedBodyForcePair("Sun",1.989E30, new Vector3(0.0,0.0,0.0) - , new Vector3(0.0,0.0,0.0)); - earth2 = new NamedBodyForcePair("Earth",5.972E24, - new Vector3(-6.13135922534815E10,-1.383789852227691E11,2.719682263474911E7), new Vector3(26832.720535473603,-11948.23168764519,1.9948243075997851)); - moon2 = new NamedBodyForcePair("Moon",7.349E22, - new Vector3(-6.132484773775896E10,-1.387394951280871E11,1.701046736294776E7), new Vector3(27916.62329282941,-12020.39526008238,-94.89703264508708)); - mars2 = new NamedBodyForcePair("Mars",6.41712E23, - new Vector3(-1.7923193702925848E11,1.726665823982123E11,7.991673845249474E9), new Vector3(-15925.78496403673,-15381.16179928219,68.67560910598857)); - deimos2 = new NamedBodyForcePair("Deimos",1.8E20, - new Vector3(-1.792255010450533E11,1.726891122683271E11,7.990659337380297E9), new Vector3(-17100.476719804457,-15020.348656808,631.2927851249581)); - phobos2 = new NamedBodyForcePair("Phobos",1.08E20, - new Vector3(-1.792253482539647E11,1.72661109673625E11,7.987848354800322E9), new Vector3(-14738.203714241401,-13671.17675223948,-411.0012490555253)); - mercury2 = new NamedBodyForcePair("Mercury",3.301E23, - new Vector3(-5.167375560011926E10,-4.217574885682655E10,1.14808913958168E9), new Vector3(21580.25398577148,-34951.03632847389,-4835.225596525241)); - venus2 = new NamedBodyForcePair("Venus",4.86747E24, - new Vector3(-3.123150865740532E10,1.0395568504115701E11,3.173401325838074E9), new Vector3(-33748.180519629335,-10014.25141045021,1809.94488874165)); - vesta2 = new NamedBodyForcePair("Vesta",2.5908E20, - new Vector3(-3.337493557929893E11,-4.7147908276077385E10,4.1923010146878105E10), new Vector3(4440.54247538484,-19718.49074006637,48.06573124543601)); - pallas2 = new NamedBodyForcePair("Pallas",2.14E20, - new Vector3(4.3452066613895575E11,-2.057319365171432E11,1.0549957423213101E11), new Vector3(5058.947582097117,11184.45711782372,-8183.524138259704)); - hygiea2 = new NamedBodyForcePair("Hygiea",8.32E19, - new Vector3(-3.983943433707043E11,2.325833000024021E11,-2.233667695713672E10), new Vector3(-6931.864585548552,-15686.8108598699,-690.5791992347208)); - ceres2 = new NamedBodyForcePair("Ceres",9.394E20, - new Vector3(3.781372641419032E11,1.96718960466285E11,-6.366459168068592E10), new Vector3(-8555.324226752316,14718.33755980907,2040.230135060142)); - - NamedBodyForcePair[] pairs = new NamedBodyForcePair[] {sun2, mercury2, venus2, earth2, - moon2, mars2, deimos2, phobos2, - vesta2, pallas2, hygiea2, ceres2}; - - // check basic functions of 'HierachicalSystem' - System.out.println("Test1:"); - + // check basic functions of 'HierarchicalSystem' CosmicSystem earthSystem = new HierarchicalSystem(earth2, moon2); CosmicSystem marsSystem = new HierarchicalSystem(mars2, deimos2, phobos2); - CosmicSystem solarSystem = new HierarchicalSystem(sun2, mercury2, venus2, earthSystem, - marsSystem, vesta2, pallas2, hygiea2, ceres2); + CosmicSystem solarSystem = new HierarchicalSystem(sun2, mercury2, venus2, earthSystem, marsSystem, vesta2, pallas2, hygiea2, ceres2); - testValue(earthSystem.numberOfBodies(), 2); - testValue(solarSystem.numberOfBodies(), 12); + assertEquals(2, earthSystem.numberOfBodies()); + assertEquals(12, solarSystem.numberOfBodies()); - System.out.println("Test2:"); - System.out.println(solarSystem.toString()); - testValue(solarSystem.toString().contains("Mars"), true); - testValue(solarSystem.toString().contains("Deimos"), true); - testValue(solarSystem.toString().contains("Moon"), true); - testValue(earthSystem.toString().contains("Moon"), true); - testValue(earthSystem.toString().contains("Earth"), true); + assertTrue(solarSystem.toString().contains("Mars")); + assertTrue(solarSystem.toString().contains("Deimos")); + assertTrue(solarSystem.toString().contains("Moon")); + assertTrue(earthSystem.toString().contains("Moon")); + assertTrue(earthSystem.toString().contains("Earth")); - System.out.println("Test3:"); - testValue(solarSystem.getMass(),1.9890118865556799E30); + assertEquals(1.9890118865556799E30, solarSystem.getMass()); - System.out.println("Test4:"); BodyLinkedList bl = solarSystem.getBodies(); - testValue(bl.size(),12); + assertEquals(12, bl.size()); HashSet set = new HashSet<>(); - while(bl.size() > 0) { + while (bl.size() > 0) { set.add(bl.pollFirst()); } - testValue(set.size(), 12); + assertEquals(12, set.size()); - System.out.println("Test5:"); for (int seconds = 0; seconds < 50000; seconds++) { // for each body (with index i): compute the total force exerted on it. for (int i = 0; i < bodies.length; i++) { @@ -129,41 +95,12 @@ public class Aufgabe4Test { } for (int i = 0; i < bodies.length; i++) { - testValue(bodies[i].massCenter().distanceTo(pairs[i].getMassCenter()),0); + assertEquals(0, bodies[i].massCenter().distanceTo(pairs[i].getMassCenter())); } - System.out.println("Test6:"); - sun2 = new NamedBodyForcePair("Sun",1.989E30, new Vector3(0.0,0.0,0.0) - , new Vector3(0.0,0.0,0.0)); - earth2 = new NamedBodyForcePair("Earth",5.972E24, - new Vector3(-6.13135922534815E10,-1.383789852227691E11,2.719682263474911E7), new Vector3(26832.720535473603,-11948.23168764519,1.9948243075997851)); - moon2 = new NamedBodyForcePair("Moon",7.349E22, - new Vector3(-6.132484773775896E10,-1.387394951280871E11,1.701046736294776E7), new Vector3(27916.62329282941,-12020.39526008238,-94.89703264508708)); - mars2 = new NamedBodyForcePair("Mars",6.41712E23, - new Vector3(-1.7923193702925848E11,1.726665823982123E11,7.991673845249474E9), new Vector3(-15925.78496403673,-15381.16179928219,68.67560910598857)); - deimos2 = new NamedBodyForcePair("Deimos",1.8E20, - new Vector3(-1.792255010450533E11,1.726891122683271E11,7.990659337380297E9), new Vector3(-17100.476719804457,-15020.348656808,631.2927851249581)); - phobos2 = new NamedBodyForcePair("Phobos",1.08E20, - new Vector3(-1.792253482539647E11,1.72661109673625E11,7.987848354800322E9), new Vector3(-14738.203714241401,-13671.17675223948,-411.0012490555253)); - mercury2 = new NamedBodyForcePair("Mercury",3.301E23, - new Vector3(-5.167375560011926E10,-4.217574885682655E10,1.14808913958168E9), new Vector3(21580.25398577148,-34951.03632847389,-4835.225596525241)); - venus2 = new NamedBodyForcePair("Venus",4.86747E24, - new Vector3(-3.123150865740532E10,1.0395568504115701E11,3.173401325838074E9), new Vector3(-33748.180519629335,-10014.25141045021,1809.94488874165)); - vesta2 = new NamedBodyForcePair("Vesta",2.5908E20, - new Vector3(-3.337493557929893E11,-4.7147908276077385E10,4.1923010146878105E10), new Vector3(4440.54247538484,-19718.49074006637,48.06573124543601)); - pallas2 = new NamedBodyForcePair("Pallas",2.14E20, - new Vector3(4.3452066613895575E11,-2.057319365171432E11,1.0549957423213101E11), new Vector3(5058.947582097117,11184.45711782372,-8183.524138259704)); - hygiea2 = new NamedBodyForcePair("Hygiea",8.32E19, - new Vector3(-3.983943433707043E11,2.325833000024021E11,-2.233667695713672E10), new Vector3(-6931.864585548552,-15686.8108598699,-690.5791992347208)); - ceres2 = new NamedBodyForcePair("Ceres",9.394E20, - new Vector3(3.781372641419032E11,1.96718960466285E11,-6.366459168068592E10), new Vector3(-8555.324226752316,14718.33755980907,2040.230135060142)); - - pairs = new NamedBodyForcePair[] {sun2, mercury2, venus2, earth2, - moon2, mars2, deimos2, phobos2, - vesta2, pallas2, hygiea2, ceres2}; - HierarchicalSystem hs = new HierarchicalSystem(sun2, mercury2, venus2, - new HierarchicalSystem(earth2, moon2), new HierarchicalSystem(mars2, deimos2, - phobos2), vesta2, pallas2, hygiea2, ceres2); + resetBodies(); + pairs = new NamedBodyForcePair[]{sun2, mercury2, venus2, earth2, moon2, mars2, deimos2, phobos2, vesta2, pallas2, hygiea2, ceres2}; + HierarchicalSystem hs = new HierarchicalSystem(sun2, mercury2, venus2, new HierarchicalSystem(earth2, moon2), new HierarchicalSystem(mars2, deimos2, phobos2), vesta2, pallas2, hygiea2, ceres2); for (int seconds = 0; seconds < 50000; seconds++) { hs.addForceTo(hs); @@ -171,35 +108,8 @@ public class Aufgabe4Test { } for (int i = 0; i < bodies.length; i++) { - testValue(bodies[i].massCenter().distanceTo(pairs[i].getMassCenter()),0); + assertEquals(0, bodies[i].massCenter().distanceTo(pairs[i].getMassCenter())); } */ //TODO: uncomment } - - public static void testComparison(Object first, Object second, boolean expected) { - boolean real = first == second; - - if (real == expected) { - System.out.println("Successful comparison"); - } else { - System.out.println("Comparison NOT successful! Expected value: " + expected + " / Given value: " + real); - } - } - - public static void testValue(Object given, Object expected) { - if (given == expected) { - System.out.println("Successful test"); - } else { - System.out.println("Test NOT successful! Expected value: " + expected + " / Given value: " + given); - } - } - - public static void testValue(double given, double expected) { - if (given < expected + (expected + 1) / 1e12 && given > expected - (expected + 1) / 1e12) { - System.out.println("Successful test"); - } else { - System.out.println("Test NOT successful! Expected value: " + expected + " / Given value: " + given); - } - } - } diff --git a/src/CosmicSystem.java b/src/CosmicSystem.java index 3aa654e..3091539 100644 --- a/src/CosmicSystem.java +++ b/src/CosmicSystem.java @@ -1,41 +1,59 @@ -// A representation of a system of bodies with associated forces. Provides methods -// for computing current mutual forces, updating the positions of bodies and drawing -// the bodies in a CodeDraw object. -// +/** + * A representation of a system of bodies with associated forces. Provides methods + * for computing current mutual forces, updating the positions of bodies and drawing + * the bodies in a CodeDraw object. + */ public interface CosmicSystem extends Drawable { - // Returns a readable representation of this system. + /** + * Returns a readable representation of this system. + */ String toString(); - // Returns the mass center of this system. + /** + * Returns the mass center of this system. + */ Vector3 getMassCenter(); - // Returns the overall mass of this system. + /** + * Returns the overall mass of this system. + */ double getMass(); - // Returns the overall number of bodies contained in this system. + /** + * Returns the overall number of bodies contained in this system. + */ int numberOfBodies(); - // Returns the distance between the mass centers of 'this' and the specified system. - //Precondition: cs != null + /** + * Returns the distance between the mass centers of 'this' and the specified system. + * Precondition: cs != null + */ double distanceTo(CosmicSystem cs); - // Adds the force that the specified body exerts on each of this systems bodies to each of this - // systems bodies. - // Precondition: b != null + /** + * Adds the force that the specified body exerts on each of this systems bodies to each of this + * systems bodies. + * Precondition: b != null + */ void addForceFrom(Body b); - // Adds the force that this system exerts on each of the bodies of 'cs' to the bodies in 'cs'. - // For exact computations this means that for each body of 'this' its force on each body of - // 'cs' is added to this body of 'cs'. - // Precondition: cs != null + /** + * Adds the force that this system exerts on each of the bodies of 'cs' to the bodies in 'cs'. + * For exact computations this means that for each body of 'this' its force on each body of + * 'cs' is added to this body of 'cs'. + * Precondition: cs != null + */ void addForceTo(CosmicSystem cs); - // Returns a list with all the bodies of 'this'. The order is not defined. + /** + * Returns a list with all the bodies of 'this'. The order is not defined. + */ BodyLinkedList getBodies(); - // Moves each of the bodies of 'this' according to the previously accumulated forces and - // resets all forces to zero. + /** + * Moves each of the bodies of 'this' according to the previously accumulated forces and + * resets all forces to zero. + */ void update(); - } diff --git a/src/Drawable.java b/src/Drawable.java index 86e02f3..d55c572 100644 --- a/src/Drawable.java +++ b/src/Drawable.java @@ -1,10 +1,13 @@ import codedraw.CodeDraw; -// An object that can be drawn in a CodeDraw canvas. -// +/** + * An object that can be drawn in a CodeDraw canvas. + */ public interface Drawable { - //draws the object into the canvas 'cd' - //Precondition: cd != null + /** + * draws the object into the canvas 'cd' + * Precondition: cd != null + */ void draw(CodeDraw cd); } diff --git a/src/HierarchicalSystem.java b/src/HierarchicalSystem.java index de0661a..f17adf9 100644 --- a/src/HierarchicalSystem.java +++ b/src/HierarchicalSystem.java @@ -1,14 +1,16 @@ -// A cosmic system that is composed of a central named body (of type 'NamedBodyForcePair') -// and an arbitrary number of subsystems (of type 'HierarchicalSystem') in its orbit. -// This class implements 'CosmicSystem'. -// +/** + * A cosmic system that is composed of a central named body (of type 'NamedBodyForcePair') + * and an arbitrary number of subsystems (of type 'HierarchicalSystem') in its orbit. + * This class implements 'CosmicSystem'. + */ public class HierarchicalSystem /* TODO: add clause */ { // TODO: define missing parts of this class. - // Initializes this system with a name and a central body. + /** + * Initializes this system with a name and a central body. + */ public HierarchicalSystem(NamedBodyForcePair central, CosmicSystem... inOrbit) { // TODO: implement constructor. - } } diff --git a/src/NamedBodyForcePair.java b/src/NamedBodyForcePair.java index 4cd1b68..1568c5a 100644 --- a/src/NamedBodyForcePair.java +++ b/src/NamedBodyForcePair.java @@ -1,21 +1,28 @@ -// A body with a name and an associated force. The leaf node of -// a hierarchical cosmic system. This class implements 'CosmicSystem'. -// +/** + * A body with a name and an associated force. The leaf node of + * a hierarchical cosmic system. This class implements 'CosmicSystem'. + */ public class NamedBodyForcePair /* TODO: add clause */ { // TODO: define missing parts of this class. - // Initializes this with name, mass, current position and movement. The associated force - // is initialized with a zero vector. + /** + * Initializes this with name, mass, current position and movement. The associated force + * is initialized with a zero vector. + */ public NamedBodyForcePair(String name, double mass, Vector3 massCenter, Vector3 currentMovement) { // TODO: implement constructor. - } - // Returns the name of the body. + public NamedBodyForcePair(NamedBodyForcePair other) { + // TODO + } + + /** + * Returns the name of the body. + */ public String getName() { // TODO: implement method. return ""; - } } diff --git a/src/Simulation4.java b/src/Simulation4.java index eb407a5..84737c1 100644 --- a/src/Simulation4.java +++ b/src/Simulation4.java @@ -2,8 +2,9 @@ import codedraw.CodeDraw; import java.awt.*; -// Simulates the formation of a massive solar system. -// +/** + * Simulates the formation of a massive solar system. + */ public class Simulation4 { // gravitational constant @@ -26,28 +27,27 @@ public class Simulation4 { // all quantities are based on units of kilogram respectively second and meter. - // The main simulation method using instances of other classes. + /** + * The main simulation method using instances of other classes. + */ public static void main(String[] args) { - // simulation CodeDraw cd = new CodeDraw(); // create solar system with 12 bodies - NamedBodyForcePair sun = new NamedBodyForcePair("Sun",1.989E30, new Vector3(0.0,0.0,0.0), new Vector3(0.0,0.0,0.0)); - NamedBodyForcePair earth = new NamedBodyForcePair("Earth",5.972E24, new Vector3(-6.13135922534815E10,-1.383789852227691E11,2.719682263474911E7), new Vector3(26832.720535473603,-11948.23168764519,1.9948243075997851)); - NamedBodyForcePair moon = new NamedBodyForcePair("Moon",7.349E22, new Vector3(-6.132484773775896E10,-1.387394951280871E11,1.701046736294776E7), new Vector3(27916.62329282941,-12020.39526008238,-94.89703264508708)); - NamedBodyForcePair mars = new NamedBodyForcePair("Mars",6.41712E23, new Vector3(-1.7923193702925848E11,1.726665823982123E11,7.991673845249474E9), new Vector3(-15925.78496403673,-15381.16179928219,68.67560910598857)); - NamedBodyForcePair deimos = new NamedBodyForcePair("Deimos",1.8E20, new Vector3(-1.792255010450533E11,1.726891122683271E11,7.990659337380297E9), new Vector3(-17100.476719804457,-15020.348656808,631.2927851249581)); - NamedBodyForcePair phobos = new NamedBodyForcePair("Phobos",1.08E20, new Vector3(-1.792253482539647E11,1.72661109673625E11,7.987848354800322E9), new Vector3(-14738.203714241401,-13671.17675223948,-411.0012490555253)); - NamedBodyForcePair mercury = new NamedBodyForcePair("Mercury",3.301E23, new Vector3(-5.167375560011926E10,-4.217574885682655E10,1.14808913958168E9), new Vector3(21580.25398577148,-34951.03632847389,-4835.225596525241)); - NamedBodyForcePair venus = new NamedBodyForcePair("Venus",4.86747E24, new Vector3(-3.123150865740532E10,1.0395568504115701E11,3.173401325838074E9), new Vector3(-33748.180519629335,-10014.25141045021,1809.94488874165)); - NamedBodyForcePair vesta = new NamedBodyForcePair("Vesta",2.5908E20, new Vector3(-3.337493557929893E11,-4.7147908276077385E10,4.1923010146878105E10), new Vector3(4440.54247538484,-19718.49074006637,48.06573124543601)); - NamedBodyForcePair pallas = new NamedBodyForcePair("Pallas",2.14E20, new Vector3(4.3452066613895575E11,-2.057319365171432E11,1.0549957423213101E11), new Vector3(5058.947582097117,11184.45711782372,-8183.524138259704)); - NamedBodyForcePair hygiea = new NamedBodyForcePair("Hygiea",8.32E19, new Vector3(-3.983943433707043E11,2.325833000024021E11,-2.233667695713672E10), new Vector3(-6931.864585548552,-15686.8108598699,-690.5791992347208)); - NamedBodyForcePair ceres = new NamedBodyForcePair("Ceres",9.394E20, new Vector3(3.781372641419032E11,1.96718960466285E11,-6.366459168068592E10), new Vector3(-8555.324226752316,14718.33755980907,2040.230135060142)); + NamedBodyForcePair sun = new NamedBodyForcePair(SolSystem4.SUN); + NamedBodyForcePair earth = new NamedBodyForcePair(SolSystem4.EARTH); + NamedBodyForcePair moon = new NamedBodyForcePair(SolSystem4.MOON); + NamedBodyForcePair mars = new NamedBodyForcePair(SolSystem4.MARS); + NamedBodyForcePair deimos = new NamedBodyForcePair(SolSystem4.DEIMOS); + NamedBodyForcePair phobos = new NamedBodyForcePair(SolSystem4.PHOBOS); + NamedBodyForcePair mercury = new NamedBodyForcePair(SolSystem4.MERCURY); + NamedBodyForcePair venus = new NamedBodyForcePair(SolSystem4.VENUS); + NamedBodyForcePair vesta = new NamedBodyForcePair(SolSystem4.VESTA); + NamedBodyForcePair pallas = new NamedBodyForcePair(SolSystem4.PALLAS); + NamedBodyForcePair hygiea = new NamedBodyForcePair(SolSystem4.HYGIEA); + NamedBodyForcePair ceres = new NamedBodyForcePair(SolSystem4.CERES); //TODO: implementation of this method according to 'Aufgabenblatt4.md'. - - } } diff --git a/src/SolSystem4.java b/src/SolSystem4.java new file mode 100644 index 0000000..2cd31ae --- /dev/null +++ b/src/SolSystem4.java @@ -0,0 +1,14 @@ +public class SolSystem4 { + public static final NamedBodyForcePair SUN = new NamedBodyForcePair("Sun", 1.989E30, new Vector3(0.0, 0.0, 0.0), new Vector3(0.0, 0.0, 0.0)); + public static final NamedBodyForcePair EARTH = new NamedBodyForcePair("Earth", 5.972E24, new Vector3(-6.13135922534815E10, -1.383789852227691E11, 2.719682263474911E7), new Vector3(26832.720535473603, -11948.23168764519, 1.9948243075997851)); + public static final NamedBodyForcePair MOON = new NamedBodyForcePair("Moon", 7.349E22, new Vector3(-6.132484773775896E10, -1.387394951280871E11, 1.701046736294776E7), new Vector3(27916.62329282941, -12020.39526008238, -94.89703264508708)); + public static final NamedBodyForcePair MARS = new NamedBodyForcePair("Mars", 6.41712E23, new Vector3(-1.7923193702925848E11, 1.726665823982123E11, 7.991673845249474E9), new Vector3(-15925.78496403673, -15381.16179928219, 68.67560910598857)); + public static final NamedBodyForcePair DEIMOS = new NamedBodyForcePair("Deimos", 1.8E20, new Vector3(-1.792255010450533E11, 1.726891122683271E11, 7.990659337380297E9), new Vector3(-17100.476719804457, -15020.348656808, 631.2927851249581)); + public static final NamedBodyForcePair PHOBOS = new NamedBodyForcePair("Phobos", 1.08E20, new Vector3(-1.792253482539647E11, 1.72661109673625E11, 7.987848354800322E9), new Vector3(-14738.203714241401, -13671.17675223948, -411.0012490555253)); + public static final NamedBodyForcePair MERCURY = new NamedBodyForcePair("Mercury", 3.301E23, new Vector3(-5.167375560011926E10, -4.217574885682655E10, 1.14808913958168E9), new Vector3(21580.25398577148, -34951.03632847389, -4835.225596525241)); + public static final NamedBodyForcePair VENUS = new NamedBodyForcePair("Venus", 4.86747E24, new Vector3(-3.123150865740532E10, 1.0395568504115701E11, 3.173401325838074E9), new Vector3(-33748.180519629335, -10014.25141045021, 1809.94488874165)); + public static final NamedBodyForcePair VESTA = new NamedBodyForcePair("Vesta", 2.5908E20, new Vector3(-3.337493557929893E11, -4.7147908276077385E10, 4.1923010146878105E10), new Vector3(4440.54247538484, -19718.49074006637, 48.06573124543601)); + public static final NamedBodyForcePair PALLAS = new NamedBodyForcePair("Pallas", 2.14E20, new Vector3(4.3452066613895575E11, -2.057319365171432E11, 1.0549957423213101E11), new Vector3(5058.947582097117, 11184.45711782372, -8183.524138259704)); + public static final NamedBodyForcePair HYGIEA = new NamedBodyForcePair("Hygiea", 8.32E19, new Vector3(-3.983943433707043E11, 2.325833000024021E11, -2.233667695713672E10), new Vector3(-6931.864585548552, -15686.8108598699, -690.5791992347208)); + public static final NamedBodyForcePair CERES = new NamedBodyForcePair("Ceres", 9.394E20, new Vector3(3.781372641419032E11, 1.96718960466285E11, -6.366459168068592E10), new Vector3(-8555.324226752316, 14718.33755980907, 2040.230135060142)); +}