Skip to content
Snippets Groups Projects
Commit 94bd5285 authored by fefe's avatar fefe
Browse files

Functions: Add,od,constructors,len

parent dee54ffc
Branches
Tags
No related merge requests found
package ch.hepia.numeric; package ch.hepia.numeric;
import java.util.List; import java.util.List;
import java.util.ArrayList;
import java.util.function.DoubleFunction; import java.util.function.DoubleFunction;
import java.util.function.Function; import java.util.function.Function;
final public class Vector { final public class Vector {
private List<Double> values;
private Vector() {} private Vector() {}
private Vector(Double... elements) { private Vector(Double... elements) {
throw new UnsupportedOperationException("This feature isn't implemented yet"); List<Double> vec = new ArrayList<>();
for (double elem : elements){vec.add(elem);}
this.values = vec;
} }
private Vector(List<Double> elements) { private Vector(List<Double> elements) {
throw new UnsupportedOperationException("This feature isn't implemented yet"); this.values = elements;
} }
public Transposed t() { public Transposed t() {
...@@ -18,18 +23,22 @@ final public class Vector { ...@@ -18,18 +23,22 @@ final public class Vector {
} }
public int len() { public int len() {
throw new UnsupportedOperationException("This feature isn't implemented yet"); return this.values.size();
} }
public double get(int i) { public double get(int i) {
throw new UnsupportedOperationException("This feature isn't implemented yet"); return this.values.get(i);
} }
void set(int i, double value) { void set(int i, double value) {
throw new UnsupportedOperationException("This feature isn't implemented yet"); this.values.set(i, value);
} }
public Vector add(Vector that) { public Vector add(Vector that) {
throw new UnsupportedOperationException("This feature isn't implemented yet"); List<Double> newVec = new ArrayList<>();
for(int i=0; i < this.len();i++){
newVec.add(this.get(i)+that.get(i));
}
return new Vector(newVec);
} }
public Vector mul(double m) { public Vector mul(double m) {
...@@ -77,7 +86,7 @@ final public class Vector { ...@@ -77,7 +86,7 @@ final public class Vector {
} }
public static Vector of(Double... elements) { public static Vector of(Double... elements) {
throw new UnsupportedOperationException("This feature isn't implemented yet"); return new Vector(elements);
} }
public static Vector of(List<Double> elements) { public static Vector of(List<Double> elements) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment