diff --git a/README.md b/README.md index 75d424e..2e53c82 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Dateien wie Bilder die zur Lösung einer Aufgabe gehören sind in
Medie - Vorlesung 7 komplett - Vorlesung 8 komplett - Vorlesung 9 Aufgabe 2 -- Vorlesung 10 Aufgabe 1 +- Vorlesung 10 komplett ## Angefangene unfertige Lösungen: - Damenproblem: VL 5 Aufgabe 2 diff --git a/src/part10/aufg2/NegativeValueException.java b/src/part10/aufg2/NegativeValueException.java new file mode 100644 index 0000000..d9e1d3b --- /dev/null +++ b/src/part10/aufg2/NegativeValueException.java @@ -0,0 +1,7 @@ +package part10.aufg2; + +public class NegativeValueException extends RuntimeException{ + NegativeValueException(String s) { + super(s); + } +} diff --git a/src/part10/aufg2/PositiveVector.java b/src/part10/aufg2/PositiveVector.java new file mode 100644 index 0000000..a80781f --- /dev/null +++ b/src/part10/aufg2/PositiveVector.java @@ -0,0 +1,94 @@ +package part10.aufg2; + +import java.util.Arrays; + +public class PositiveVector { + double[] values; + + PositiveVector(int size){ + this.values = new double[size]; + Arrays.fill(values, 0); + } + + public int length(){ + return this.values.length; + } + public void setValues(double[] values) { + for (int i=0; i= 0) : "Value cannot be negative"; + } + this.values = values; + } + + public double[] getValues() { + return values; + } + + public void setSingleValue(double value, int index){ + if (value < 0){ + System.out.println(value + " is negativ and cannot be assigned!"); + return; + } + this.values[index] = value; + } + + public double getSingleValue(int index){ + return this.values[index]; + } + + public void print(){ + System.out.println(Arrays.toString(this.values)); + } + + public PositiveVector vectorAddition(PositiveVector vector2){ + PositiveVector result = new PositiveVector(this.length()); + + if (this.values.length == vector2.getValues().length){ + for (int i=0; i