Aggiunto DataSet misurabile
This commit is contained in:
		
							
								
								
									
										48
									
								
								NetBeans Projects/DataSet/src/noarray/DataSet.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								NetBeans Projects/DataSet/src/noarray/DataSet.java
									
									
									
									
									
										Normal file
									
								
							@@ -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 <T extends Misurabile> {
 | 
			
		||||
    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();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										13
									
								
								NetBeans Projects/DataSet/src/noarray/Misurabile.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								NetBeans Projects/DataSet/src/noarray/Misurabile.java
									
									
									
									
									
										Normal file
									
								
							@@ -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();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										23
									
								
								NetBeans Projects/DataSet/src/noarray/MyMis.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								NetBeans Projects/DataSet/src/noarray/MyMis.java
									
									
									
									
									
										Normal file
									
								
							@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										21
									
								
								NetBeans Projects/DataSet/src/noarray/Tester.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								NetBeans Projects/DataSet/src/noarray/Tester.java
									
									
									
									
									
										Normal file
									
								
							@@ -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());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user