diff --git a/NetBeans Projects/DataSet/src/noarray/DataSet.java b/NetBeans Projects/DataSet/src/noarray/DataSet.java new file mode 100644 index 0000000..8159731 --- /dev/null +++ b/NetBeans Projects/DataSet/src/noarray/DataSet.java @@ -0,0 +1,48 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package noarray; + +import java.util.Arrays; + +/** + * + * @author gicorada + */ +public class DataSet { + private int dim; + private T min; + private T max; + private double somma = 0; + + public DataSet(T n) { + max = n; + min = n; + somma = n.getMisura(); + dim++; + } + + public void add(T n) { + if(n.getMisura() < min.getMisura()) min = n; + if(n.getMisura() > min.getMisura()) max = n; + somma += n.getMisura(); + dim++; + } + + public double media() { + return 1.0*somma/dim; + } + + public T min() { + return min; + } + + public T max() { + return max; + } + + public double getScarto() { + return max.getMisura() - min.getMisura(); + } +} diff --git a/NetBeans Projects/DataSet/src/noarray/Misurabile.java b/NetBeans Projects/DataSet/src/noarray/Misurabile.java new file mode 100644 index 0000000..d119078 --- /dev/null +++ b/NetBeans Projects/DataSet/src/noarray/Misurabile.java @@ -0,0 +1,13 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template + */ +package noarray; + +/** + * + * @author gicorada + */ +public interface Misurabile { + double getMisura(); +} diff --git a/NetBeans Projects/DataSet/src/noarray/MyMis.java b/NetBeans Projects/DataSet/src/noarray/MyMis.java new file mode 100644 index 0000000..eb026b1 --- /dev/null +++ b/NetBeans Projects/DataSet/src/noarray/MyMis.java @@ -0,0 +1,23 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package noarray; + +/** + * + * @author gicorada + */ +public class MyMis implements Misurabile { + private double misura; + + public MyMis(double misura) { + this.misura = misura; + } + + @Override + public double getMisura() { + return misura; + } + +} diff --git a/NetBeans Projects/DataSet/src/noarray/Tester.java b/NetBeans Projects/DataSet/src/noarray/Tester.java new file mode 100644 index 0000000..97119b7 --- /dev/null +++ b/NetBeans Projects/DataSet/src/noarray/Tester.java @@ -0,0 +1,21 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package noarray; + +/** + * + * @author gicorada + */ +public class Tester { + public static void main(String[] args) { + DataSet data = new DataSet(new MyMis(50)); + + data.add(new MyMis(10)); + + data.add(new MyMis(100)); + + System.out.println(data.max().getMisura() + " " + data.min().getMisura() + " " + data.media() + " " + data.getScarto()); + } +}