Hallo,
kann bitte jemand kontrollieren, ob ich die Ausnahmebehandlung richtig implementiert habe? Den letzten Absatz habe ich noch nicht implementiert, da ich etwas überfordert bin^^.
Die Aufgabenstellung poste ich in einem zusätzlichen Kommentar der Übersichthalber.
kann bitte jemand kontrollieren, ob ich die Ausnahmebehandlung richtig implementiert habe? Den letzten Absatz habe ich noch nicht implementiert, da ich etwas überfordert bin^^.
Die Aufgabenstellung poste ich in einem zusätzlichen Kommentar der Übersichthalber.
Java:
public static void main(String[] args) throws WrongDimensionException, NullvectorException {
System.out.println(normalizeVector3D(null));
System.out.println(vectorSum(new int[] { 2, 2, 2 }));
}
public static double[] normalizeVector3D(int[] integerArray) throws WrongDimensionException, NullvectorException {
int dimensionArray = 0;
try {
if (integerArray.length < 3 || integerArray.length > 3) {
for (int i = 0; i < integerArray.length; i++) {
dimensionArray++;
}
throw new WrongDimensionException("Falsche Dimension " + dimensionArray);
}
} catch (NullPointerException e) {
System.out.println("Übergebene Array ist gleich Null");
}
double result = vectorSum(integerArray);
result = ((1 / (Math.sqrt(result))));
result = Math.round(result * 1000.0) / 1000.0;
System.out.println(result);
double[] doubleArray = new double[(integerArray.length)];
for (int i = 0; i < integerArray.length; i++) {
doubleArray[i] = integerArray[i];
}
for (int i = 0; i < doubleArray.length; i++) {
doubleArray[i] *= Math.round(result * 1000.0) / 1000.0;
}
System.out.println(Arrays.toString(doubleArray));
return doubleArray;
}
public static int vectorSum(int[] x) throws NullvectorException {
try {
for (int i = 0; i < x.length; i++) {
if (x[i] == 0 && x[i + 1] == 0 && x[i + 2] == 0) {
throw new NullvectorException("Das übergeben Array ist ein Nullvektor");
}
}
} catch (NullPointerException e) {
System.out.println("Übergebene Array ist gleich Null");
}
int result = 0;
for (int i = 0; i < x.length; i++) {
result += x[i] * x[i];
}
return result;
}