Aufgabenblatt 8
This commit is contained in:
100
src/Aufgabe8Test.java
Normal file
100
src/Aufgabe8Test.java
Normal file
@ -0,0 +1,100 @@
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class Aufgabe8Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
/* //TODO: uncomment for testing
|
||||
|
||||
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));
|
||||
|
||||
|
||||
System.out.println("Test1:");
|
||||
MassiveIterator iterator = map.getKeys().iterator();
|
||||
int count = 0;
|
||||
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);
|
||||
|
||||
System.out.println("Test2:");
|
||||
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();
|
||||
while(iterator.hasNext()) {
|
||||
iterator.next();
|
||||
iterator.remove();
|
||||
}
|
||||
testValue(map.getKeys().size(),0);
|
||||
|
||||
*/ //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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
27
src/ReadDataUtil.java
Normal file
27
src/ReadDataUtil.java
Normal file
@ -0,0 +1,27 @@
|
||||
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 {
|
||||
|
||||
// TODO: implement this method.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
60
src/Simulation8.java
Normal file
60
src/Simulation8.java
Normal file
@ -0,0 +1,60 @@
|
||||
import codedraw.CodeDraw;
|
||||
|
||||
// Simulates the solar system.
|
||||
//
|
||||
public class Simulation8 {
|
||||
|
||||
// gravitational constant
|
||||
public static final double G = 6.6743e-11;
|
||||
|
||||
// one astronomical unit (AU) is the average distance of earth to the sun.
|
||||
public static final double AU = 150e9; // meters
|
||||
|
||||
// set some system parameters
|
||||
public static final double SECTION_SIZE = 10 * AU; // the size of the square region in space
|
||||
|
||||
// all quantities are based on units of kilogram respectively second and meter.
|
||||
|
||||
// The main simulation method using instances of other classes.
|
||||
public static void main(String[] args) {
|
||||
|
||||
// simulation
|
||||
CodeDraw cd = new CodeDraw();
|
||||
|
||||
// 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));
|
||||
|
||||
|
||||
//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));
|
||||
|
||||
}
|
||||
}
|
7
src/Simulation9.java
Normal file
7
src/Simulation9.java
Normal file
@ -0,0 +1,7 @@
|
||||
// Simulates the solar system.
|
||||
//
|
||||
public class Simulation9 {
|
||||
|
||||
// TODO: Implement the simulation using the Java-Collections framework.
|
||||
|
||||
}
|
7
src/StateFileFormatException.java
Normal file
7
src/StateFileFormatException.java
Normal file
@ -0,0 +1,7 @@
|
||||
import java.io.IOException;
|
||||
|
||||
public class StateFileFormatException extends IOException {
|
||||
|
||||
// TODO: implement class
|
||||
|
||||
}
|
7
src/StateFileNotFoundException.java
Normal file
7
src/StateFileNotFoundException.java
Normal file
@ -0,0 +1,7 @@
|
||||
import java.io.IOException;
|
||||
|
||||
public class StateFileNotFoundException extends IOException {
|
||||
|
||||
// TODO: implement class
|
||||
|
||||
}
|
Reference in New Issue
Block a user