Refacotr code for AB8
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
# Aufgabenblatt 8
|
||||
|
||||
## 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.
|
||||
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
|
||||
@ -20,7 +20,7 @@ Validierung, Exceptions (S. 110-123).
|
||||
- [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
|
||||
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).
|
||||
|
||||
**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):
|
||||
Ä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.
|
||||
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.
|
||||
|
@ -1,100 +1,48 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class Aufgabe8Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
/* //TODO: uncomment for testing
|
||||
|
||||
@Test
|
||||
public void testEP2() {
|
||||
MassiveForceTreeMap map = new MassiveForceTreeMap();
|
||||
NamedBody mars;
|
||||
|
||||
map.put(new NamedBody("Oumuamua", 8e6, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
|
||||
new Vector3(0, 0, 0));
|
||||
map.put(new NamedBody("Earth", 5.972E24, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
|
||||
new Vector3(0, 0, 0));
|
||||
map.put(new NamedBody("Moon", 7.349E22, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
|
||||
new Vector3(0, 0, 0));
|
||||
map.put(mars = new NamedBody("Mars", 6.41712E23, new Vector3(0, 0, 0),
|
||||
new Vector3(0, 0, 0)),
|
||||
new Vector3(0, 0, 0));
|
||||
map.put(new NamedBody("Deimos", 1.8E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
|
||||
new Vector3(0, 0, 0));
|
||||
map.put(new NamedBody("Phobos", 1.08E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
|
||||
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));
|
||||
map.put(new NamedBody("Oumuamua", 8e6, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Earth", 5.972E24, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Moon", 7.349E22, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(mars = new NamedBody("Mars", 6.41712E23, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Deimos", 1.8E20, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Phobos", 1.08E20, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Mercury", 3.301E23, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Venus", 4.86747E24, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Vesta", 2.5908E20, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Pallas", 2.14E20, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Hygiea", 8.32E19, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Ceres", 9.394E20, new Vector3(), new Vector3()), new Vector3());
|
||||
|
||||
|
||||
System.out.println("Test1:");
|
||||
MassiveIterator iterator = map.getKeys().iterator();
|
||||
int count = 0;
|
||||
while(iterator.hasNext()) {
|
||||
while (iterator.hasNext()) {
|
||||
if (iterator.next().equals(mars)) {
|
||||
iterator.remove();
|
||||
}
|
||||
count++;
|
||||
}
|
||||
testValue(count, 12);
|
||||
testValue(map.getKeys().size(), 11);
|
||||
testValue(map.getKeys().contains(mars), false);
|
||||
assertEquals(12, count);
|
||||
assertEquals(11, map.getKeys().size());
|
||||
assertFalse(map.getKeys().contains(mars));
|
||||
|
||||
System.out.println("Test2:");
|
||||
try {
|
||||
iterator.next();
|
||||
// this statement must not be reached
|
||||
testValue(true, false);
|
||||
} catch (NoSuchElementException e) {
|
||||
testValue(true, true);
|
||||
}
|
||||
assertThrows(NoSuchElementException.class, iterator::next);
|
||||
|
||||
System.out.println("Test3:");
|
||||
iterator = map.getKeys().iterator();
|
||||
while(iterator.hasNext()) {
|
||||
while (iterator.hasNext()) {
|
||||
iterator.next();
|
||||
iterator.remove();
|
||||
}
|
||||
testValue(map.getKeys().size(),0);
|
||||
|
||||
*/ //TODO: uncomment
|
||||
assertEquals(0, map.getKeys().size());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,26 +2,25 @@ import java.io.*;
|
||||
|
||||
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
|
||||
// successful the method returns 'true'. If the specified 'day' was not found in the file,
|
||||
// 'b' is unchanged and the method returns 'false'.
|
||||
// The file format is validated before reading the state.
|
||||
// Lines before the line "$$SOE" and after the line "$$EOE" the are ignored. Each line of the
|
||||
// file between the line "$$SOE" and the line "$$EOE" is required to have the following format:
|
||||
// JDTDB, TIME, X, Y, Z, VX, VY, VZ
|
||||
// where JDTDB is interpretable as a 'double' value, TIME is a string and X, Y, Z, VX, VY and
|
||||
// VZ are interpretable as 'double' values. JDTDB can be ignored. The character ',' must only
|
||||
// be used as field separator. If the file is not found, an exception of the class
|
||||
// 'StateFileNotFoundException' is thrown. If it does not comply with the format described
|
||||
// above, the method throws an exception of the class 'StateFileFormatException'. Both
|
||||
// exceptions are subtypes of 'IOException'.
|
||||
// Precondition: b != null, path != null, day != null and has the format YYYY-MM-DD.
|
||||
public static boolean readConfiguration(NamedBody b, String path, String day)
|
||||
throws IOException {
|
||||
|
||||
/**
|
||||
* 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
|
||||
* successful the method returns 'true'. If the specified 'day' was not found in the file,
|
||||
* 'b' is unchanged and the method returns 'false'.
|
||||
* The file format is validated before reading the state.
|
||||
* Lines before the line "$$SOE" and after the line "$$EOE" the are ignored. Each line of the
|
||||
* file between the line "$$SOE" and the line "$$EOE" is required to have the following format:
|
||||
* JDTDB, TIME, X, Y, Z, VX, VY, VZ
|
||||
* where JDTDB is interpretable as a 'double' value, TIME is a string and X, Y, Z, VX, VY and
|
||||
* VZ are interpretable as 'double' values. JDTDB can be ignored. The character ',' must only
|
||||
* be used as field separator. If the file is not found, an exception of the class
|
||||
* 'StateFileNotFoundException' is thrown. If it does not comply with the format described
|
||||
* above, the method throws an exception of the class 'StateFileFormatException'. Both
|
||||
* exceptions are subtypes of 'IOException'.
|
||||
* Precondition: b != null, path != null, day != null and has the format YYYY-MM-DD.
|
||||
*/
|
||||
public static boolean readConfiguration(NamedBody b, String path, String day) throws IOException {
|
||||
// TODO: implement this method.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
import codedraw.CodeDraw;
|
||||
|
||||
// Simulates the solar system.
|
||||
//
|
||||
/**
|
||||
* Simulates the solar system.
|
||||
*/
|
||||
public class Simulation8 {
|
||||
|
||||
// gravitational constant
|
||||
@ -24,37 +25,24 @@ public class Simulation8 {
|
||||
// create solar system with 13 bodies
|
||||
MassiveForceTreeMap map = new MassiveForceTreeMap();
|
||||
|
||||
map.put(new NamedBody("Oumuamua", 8e6, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
|
||||
new Vector3(0, 0, 0));
|
||||
map.put(new NamedBody("Earth", 5.972E24, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
|
||||
new Vector3(0, 0, 0));
|
||||
map.put(new NamedBody("Moon", 7.349E22, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
|
||||
new Vector3(0, 0, 0));
|
||||
map.put(new NamedBody("Mars1", 6.41712E23, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
|
||||
new Vector3(0, 0, 0));
|
||||
map.put(new NamedBody("Deimos", 1.8E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
|
||||
new Vector3(0, 0, 0));
|
||||
map.put(new NamedBody("Phobos", 1.08E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
|
||||
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("Ceres1", 9.394E20, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
|
||||
new Vector3(0, 0, 0));
|
||||
map.put(new NamedBody("Oumuamua", 8e6, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Earth", 5.972E24, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Moon", 7.349E22, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Mars1", 6.41712E23, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Deimos", 1.8E20, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Phobos", 1.08E20, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Mercury", 3.301E23, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Venus", 4.86747E24, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Vesta", 2.5908E20, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Pallas", 2.14E20, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Hygiea", 8.32E19, new Vector3(), new Vector3()), new Vector3());
|
||||
map.put(new NamedBody("Ceres1", 9.394E20, new Vector3(), new Vector3()), new Vector3());
|
||||
|
||||
|
||||
//TODO: implementation of this method according to 'Aufgabenblatt8.md'.
|
||||
|
||||
// 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)),
|
||||
new Vector3(0, 0, 0));
|
||||
map.put(new NamedBody("Sun", 1.989E30, new Vector3(), new Vector3()), new Vector3());
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Simulates the solar system.
|
||||
//
|
||||
/**
|
||||
* Simulates the solar system.
|
||||
*/
|
||||
public class Simulation9 {
|
||||
|
||||
// TODO: Implement the simulation using the Java-Collections framework.
|
||||
|
Reference in New Issue
Block a user