Announcement

Collapse
No announcement yet.

Dataset - Sum , Min, Max and Interface

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dataset - Sum , Min, Max and Interface

    dataset
    PHP Code:
    package data;

    /**
     * Created with MONSTER.
     * User: xgiovio
     * Date: 28/10/13
     * Time: 23.18
     */
    public class dataset {

            public 
    void add (misurabile_interface obj) {
                     
    sum += obj.get_misure();
                     
    count++;
                     if (
    min == null || obj.get_misure() < min.get_misure()){
                        
    min=obj;
                      }
                     if (
    max == null || obj.get_misure() > min.get_misure()){
                        
    max=obj;
                     }
            }

            public 
    misurabile_interface get_min (){
            return 
    min;
            }
            public 
    misurabile_interface get_max (){
                return 
    max;
            }
            public 
    double get_average (){
                if (
    count != 0)
                return (
    sum/count);
                return 
    0;
            }




        private 
    int count 0;
        private 
    double sum 0;
        private 
    misurabile_interface min null;
        private 
    misurabile_interface max null;





    misurabile_interface
    PHP Code:
    package data;

    /**
     * Created with MONSTER.
     * User: xgiovio
     * Date: 28/10/13
     * Time: 23.35
     */
    public interface misurabile_interface {

        
    double get_misure();

    Oggetto_misurabile
    PHP Code:
    package data;

    /**
     * Created with MONSTER.
     * User: xgiovio
     * Date: 28/10/13
     * Time: 23.36
     */
    public class Oggetto_misurabile  implements misurabile_interface {

        public 
    Oggetto_misurabile (double in_data) {
          
    misura in_data;
        }

        public 
    double get_misure() {
            return 
    misura;
        }

        private 
    double misura;


    main
    PHP Code:
    import data.Oggetto_misurabile;
    import data.dataset;

    public class 
    test {

        public static 
    void main(String[] input){

            
    dataset dati = new dataset();
            
    dati.add(new Oggetto_misurabile(10.5));
            
    dati.add(new Oggetto_misurabile(11));
            
    dati.add(new Oggetto_misurabile(2));

            
    System.out.println( (dati.get_max()).get_misure() );
            
    System.out.println( (dati.get_min()).get_misure() );
            
    System.out.printlndati.get_average() );

        }


    | VFX Artist, C++ Programmer, HW Overclocker | Web: xgiovio.com Email: xgiovio@gmail.com Twitter: @xgiovio
Working...
X

Google Profile


My name is Giovanni Di Grezia, but people call me xgiovio.

Here is my homepage:.

I'm a VFX Artist and Software Developer.

Giovanni Di Grezia