Refacotr code for AB8

This commit is contained in:
2022-06-03 14:23:51 +02:00
parent 8f6320e069
commit cfba0106a9
10 changed files with 170 additions and 234 deletions

View File

@ -1,7 +1,7 @@
# Aufgabenblatt 8 # Aufgabenblatt 8
## Allgemeine Anmerkungen ## Allgemeine Anmerkungen
Ihre Lösung für dieses Aufgabenblatt ist bis Dienstag, 13.6., 11h durch `git commit` und `git push` Ihre Lösung für dieses Aufgabenblatt ist bis Montag, 13.6., 11h durch `git commit` und `git push`
abzugeben. abzugeben.
Wenn Sie zusätzlich zu den gefragten Klassen und Interfaces weitere Klassen oder Wenn Sie zusätzlich zu den gefragten Klassen und Interfaces weitere Klassen oder
Interfaces definieren, achten Sie darauf, dass die Klassennamen mit `My` beginnen, um Konflikte Interfaces definieren, achten Sie darauf, dass die Klassennamen mit `My` beginnen, um Konflikte
@ -20,7 +20,7 @@ Validierung, Exceptions (S. 110-123).
- [states](../states) ist ein Verzeichnis, in dem mehrere Dateien mit der Endung `.txt` - [states](../states) ist ein Verzeichnis, in dem mehrere Dateien mit der Endung `.txt`
mitgeliefert werden. Diese enthalten Daten von je einem Himmelskörper sowie dessen Positionen und mitgeliefert werden. Diese enthalten Daten von je einem Himmelskörper sowie dessen Positionen und
Geschwindigkeitsvektoren für alle Tage der Jahre 2019-2021. Die Angaben sind wie gewohnt in Geschwindigkeitsvektoren für alle Tage der Jahre 2019-2021. Die Angaben sind wie gewohnt in
kartesischen Koordinaten, wobei die Sonne den Urspung des Koordinatensystems bildet und die kartesischen Koordinaten, wobei die Sonne den Ursprung des Koordinatensystems bildet und die
Ekliptik die x-y-Ebene darstellt. Die Daten stammen von [https://ssd.jpl.nasa.gov/horizons.cgi#top](https://ssd.jpl.nasa.gov/horizons.cgi#top). Ekliptik die x-y-Ebene darstellt. Die Daten stammen von [https://ssd.jpl.nasa.gov/horizons.cgi#top](https://ssd.jpl.nasa.gov/horizons.cgi#top).
**ACHTUNG**: Die Werte sind in km bzw. km/sec angegeben! **ACHTUNG**: Die Werte sind in km bzw. km/sec angegeben!
@ -122,7 +122,7 @@ müssen diese Klasse nicht weiter verändern, können aber eigene Testfälle hin
6. Freiwillige Zusatzaufgabe (ohne Bewertung): 6. Freiwillige Zusatzaufgabe (ohne Bewertung):
Ändern Sie die Klasse `Simulation8` so um, dass ein drittes optionales Kommandozeilenargument Ändern Sie die Klasse `Simulation8` so um, dass ein drittes optionales Kommandozeilenargument
verarbeitet werden kann. Dieses gibt an, wieviele Tage simuliert werden sollen. Beispielsweise verarbeitet werden kann. Dieses gibt an, wie viele Tage simuliert werden sollen. Beispielsweise
kann eine zweite Datumsangabe möglich sein, oder die Anzahl an Tagen. kann eine zweite Datumsangabe möglich sein, oder die Anzahl an Tagen.
Sobald dieser Zeitpunkt in der Simulation erreicht wurde, können die aktuellen Positionen der Sobald dieser Zeitpunkt in der Simulation erreicht wurde, können die aktuellen Positionen der
Himmelskörper mit den in den txt-Dateien angegebenen Positionen verglichen werden (z.B. Himmelskörper mit den in den txt-Dateien angegebenen Positionen verglichen werden (z.B.

View File

@ -1,100 +1,48 @@
import org.junit.jupiter.api.Test;
import java.util.HashSet;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import static org.junit.jupiter.api.Assertions.*;
public class Aufgabe8Test { public class Aufgabe8Test {
public static void main(String[] args) { @Test
public void testEP2() {
/* //TODO: uncomment for testing
MassiveForceTreeMap map = new MassiveForceTreeMap(); MassiveForceTreeMap map = new MassiveForceTreeMap();
NamedBody mars; NamedBody mars;
map.put(new NamedBody("Oumuamua", 8e6, new Vector3(0, 0, 0), new Vector3(0, 0, 0)), map.put(new NamedBody("Oumuamua", 8e6, new Vector3(), new Vector3()), new Vector3());
new Vector3(0, 0, 0)); map.put(new NamedBody("Earth", 5.972E24, new Vector3(), new Vector3()), new Vector3());
map.put(new NamedBody("Earth", 5.972E24, new Vector3(0, 0, 0), new Vector3(0, 0, 0)), map.put(new NamedBody("Moon", 7.349E22, new Vector3(), new Vector3()), new Vector3());
new Vector3(0, 0, 0)); map.put(mars = new NamedBody("Mars", 6.41712E23, new Vector3(), new Vector3()), new Vector3());
map.put(new NamedBody("Moon", 7.349E22, new Vector3(0, 0, 0), new Vector3(0, 0, 0)), map.put(new NamedBody("Deimos", 1.8E20, new Vector3(), new Vector3()), new Vector3());
new Vector3(0, 0, 0)); map.put(new NamedBody("Phobos", 1.08E20, new Vector3(), new Vector3()), new Vector3());
map.put(mars = new NamedBody("Mars", 6.41712E23, new Vector3(0, 0, 0), map.put(new NamedBody("Mercury", 3.301E23, new Vector3(), new Vector3()), new Vector3());
new Vector3(0, 0, 0)), map.put(new NamedBody("Venus", 4.86747E24, new Vector3(), new Vector3()), new Vector3());
new Vector3(0, 0, 0)); map.put(new NamedBody("Vesta", 2.5908E20, new Vector3(), new Vector3()), new Vector3());
map.put(new NamedBody("Deimos", 1.8E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)), map.put(new NamedBody("Pallas", 2.14E20, new Vector3(), new Vector3()), new Vector3());
new Vector3(0, 0, 0)); map.put(new NamedBody("Hygiea", 8.32E19, new Vector3(), new Vector3()), new Vector3());
map.put(new NamedBody("Phobos", 1.08E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)), map.put(new NamedBody("Ceres", 9.394E20, new Vector3(), new Vector3()), new Vector3());
new Vector3(0, 0, 0));
map.put(new NamedBody("Mercury", 3.301E23, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
new Vector3(0, 0, 0));
map.put(new NamedBody("Venus", 4.86747E24, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
new Vector3(0, 0, 0));
map.put(new NamedBody("Vesta", 2.5908E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
new Vector3(0, 0, 0));
map.put(new NamedBody("Pallas", 2.14E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
new Vector3(0, 0, 0));
map.put(new NamedBody("Hygiea", 8.32E19, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
new Vector3(0, 0, 0));
map.put(new NamedBody("Ceres", 9.394E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
new Vector3(0, 0, 0));
System.out.println("Test1:");
MassiveIterator iterator = map.getKeys().iterator(); MassiveIterator iterator = map.getKeys().iterator();
int count = 0; int count = 0;
while(iterator.hasNext()) { while (iterator.hasNext()) {
if (iterator.next().equals(mars)) { if (iterator.next().equals(mars)) {
iterator.remove(); iterator.remove();
} }
count++; count++;
} }
testValue(count, 12); assertEquals(12, count);
testValue(map.getKeys().size(), 11); assertEquals(11, map.getKeys().size());
testValue(map.getKeys().contains(mars), false); assertFalse(map.getKeys().contains(mars));
System.out.println("Test2:"); assertThrows(NoSuchElementException.class, iterator::next);
try {
iterator.next();
// this statement must not be reached
testValue(true, false);
} catch (NoSuchElementException e) {
testValue(true, true);
}
System.out.println("Test3:");
iterator = map.getKeys().iterator(); iterator = map.getKeys().iterator();
while(iterator.hasNext()) { while (iterator.hasNext()) {
iterator.next(); iterator.next();
iterator.remove(); iterator.remove();
} }
testValue(map.getKeys().size(),0); assertEquals(0, map.getKeys().size());
*/ //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);
}
}
} }

View File

@ -2,26 +2,25 @@ import java.io.*;
public class ReadDataUtil { public class ReadDataUtil {
// Reads the position and velocity vector on the specified 'day' from the file with the /**
// specified 'path', and sets position and current velocity of 'b' accordingly. If * Reads the position and velocity vector on the specified 'day' from the file with the
// successful the method returns 'true'. If the specified 'day' was not found in the file, * specified 'path', and sets position and current velocity of 'b' accordingly. If
// 'b' is unchanged and the method returns 'false'. * successful the method returns 'true'. If the specified 'day' was not found in the file,
// The file format is validated before reading the state. * 'b' is unchanged and the method returns 'false'.
// Lines before the line "$$SOE" and after the line "$$EOE" the are ignored. Each line of the * The file format is validated before reading the state.
// file between the line "$$SOE" and the line "$$EOE" is required to have the following format: * Lines before the line "$$SOE" and after the line "$$EOE" the are ignored. Each line of the
// JDTDB, TIME, X, Y, Z, VX, VY, VZ * file between the line "$$SOE" and the line "$$EOE" is required to have the following format:
// where JDTDB is interpretable as a 'double' value, TIME is a string and X, Y, Z, VX, VY and * JDTDB, TIME, X, Y, Z, VX, VY, VZ
// VZ are interpretable as 'double' values. JDTDB can be ignored. The character ',' must only * where JDTDB is interpretable as a 'double' value, TIME is a string and X, Y, Z, VX, VY and
// be used as field separator. If the file is not found, an exception of the class * VZ are interpretable as 'double' values. JDTDB can be ignored. The character ',' must only
// 'StateFileNotFoundException' is thrown. If it does not comply with the format described * be used as field separator. If the file is not found, an exception of the class
// above, the method throws an exception of the class 'StateFileFormatException'. Both * 'StateFileNotFoundException' is thrown. If it does not comply with the format described
// exceptions are subtypes of 'IOException'. * above, the method throws an exception of the class 'StateFileFormatException'. Both
// Precondition: b != null, path != null, day != null and has the format YYYY-MM-DD. * exceptions are subtypes of 'IOException'.
public static boolean readConfiguration(NamedBody b, String path, String day) * Precondition: b != null, path != null, day != null and has the format YYYY-MM-DD.
throws IOException { */
public static boolean readConfiguration(NamedBody b, String path, String day) throws IOException {
// TODO: implement this method. // TODO: implement this method.
return false; return false;
} }
} }

View File

@ -1,7 +1,8 @@
import codedraw.CodeDraw; import codedraw.CodeDraw;
// Simulates the solar system. /**
// * Simulates the solar system.
*/
public class Simulation8 { public class Simulation8 {
// gravitational constant // gravitational constant
@ -24,37 +25,24 @@ public class Simulation8 {
// create solar system with 13 bodies // create solar system with 13 bodies
MassiveForceTreeMap map = new MassiveForceTreeMap(); MassiveForceTreeMap map = new MassiveForceTreeMap();
map.put(new NamedBody("Oumuamua", 8e6, new Vector3(0, 0, 0), new Vector3(0, 0, 0)), map.put(new NamedBody("Oumuamua", 8e6, new Vector3(), new Vector3()), new Vector3());
new Vector3(0, 0, 0)); map.put(new NamedBody("Earth", 5.972E24, new Vector3(), new Vector3()), new Vector3());
map.put(new NamedBody("Earth", 5.972E24, new Vector3(0, 0, 0), new Vector3(0, 0, 0)), map.put(new NamedBody("Moon", 7.349E22, new Vector3(), new Vector3()), new Vector3());
new Vector3(0, 0, 0)); map.put(new NamedBody("Mars1", 6.41712E23, new Vector3(), new Vector3()), new Vector3());
map.put(new NamedBody("Moon", 7.349E22, new Vector3(0, 0, 0), new Vector3(0, 0, 0)), map.put(new NamedBody("Deimos", 1.8E20, new Vector3(), new Vector3()), new Vector3());
new Vector3(0, 0, 0)); map.put(new NamedBody("Phobos", 1.08E20, new Vector3(), new Vector3()), new Vector3());
map.put(new NamedBody("Mars1", 6.41712E23, new Vector3(0, 0, 0), new Vector3(0, 0, 0)), map.put(new NamedBody("Mercury", 3.301E23, new Vector3(), new Vector3()), new Vector3());
new Vector3(0, 0, 0)); map.put(new NamedBody("Venus", 4.86747E24, new Vector3(), new Vector3()), new Vector3());
map.put(new NamedBody("Deimos", 1.8E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)), map.put(new NamedBody("Vesta", 2.5908E20, new Vector3(), new Vector3()), new Vector3());
new Vector3(0, 0, 0)); map.put(new NamedBody("Pallas", 2.14E20, new Vector3(), new Vector3()), new Vector3());
map.put(new NamedBody("Phobos", 1.08E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)), map.put(new NamedBody("Hygiea", 8.32E19, new Vector3(), new Vector3()), new Vector3());
new Vector3(0, 0, 0)); map.put(new NamedBody("Ceres1", 9.394E20, new Vector3(), new Vector3()), new Vector3());
map.put(new NamedBody("Mercury", 3.301E23, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
new Vector3(0, 0, 0));
map.put(new NamedBody("Venus", 4.86747E24, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
new Vector3(0, 0, 0));
map.put(new NamedBody("Vesta", 2.5908E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
new Vector3(0, 0, 0));
map.put(new NamedBody("Pallas", 2.14E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
new Vector3(0, 0, 0));
map.put(new NamedBody("Hygiea", 8.32E19, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
new Vector3(0, 0, 0));
map.put(new NamedBody("Ceres1", 9.394E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
new Vector3(0, 0, 0));
//TODO: implementation of this method according to 'Aufgabenblatt8.md'. //TODO: implementation of this method according to 'Aufgabenblatt8.md'.
// add sun after states have been read from files. // add sun after states have been read from files.
map.put(new NamedBody("Sun", 1.989E30, new Vector3(0, 0, 0), new Vector3(0, 0, 0)), map.put(new NamedBody("Sun", 1.989E30, new Vector3(), new Vector3()), new Vector3());
new Vector3(0, 0, 0));
} }
} }

View File

@ -1,5 +1,6 @@
// Simulates the solar system. /**
// * Simulates the solar system.
*/
public class Simulation9 { public class Simulation9 {
// TODO: Implement the simulation using the Java-Collections framework. // TODO: Implement the simulation using the Java-Collections framework.