Converting main object to objects and importing randNum []

I have written some code that functions as expected. I am calculating max, min, median, mode, mean and standard dev. All of this is calculated from a random number generator. I want to clean up the main one (I didn't know it was an option at the time) by making all of these functions different objects.

I need a number generator in the new master and I don't know how to call this the new class. I tried using "get", but I don't know if you can use the get method on the array.

The first block of code is what I want to convert to objects. The second is my attempt at doing this. Third, the new main only has a random number generator, I know it doesn't print anything.

import java.util.Random;
import java.util.Arrays;
import java.util.*;

class StatisticsMain {
  public static void main (String[] args) {


    int SIZE = 100; // the number of random # generated
    Random rand = new Random ();
    int[] nums = new int[SIZE];
    for (int q = 0; q < SIZE; q++) {
      nums[q] = rand.nextInt (490) + 10; // only numbers from 10-500 generated

    }
    // System.out.println (Arrays.toString (nums));

     Arrays.sort (nums); // organizes numbers for max min and median
     double median;
     if(nums.length % 2 == 0){
       median = ((double)nums[nums.length/2] 
         + (double)nums[nums.length/2 - 2])/2;
     }else {
         median = (double)nums[nums.length/2];
         }

     System.out.println("The Min number is: \t "+ nums[0]); //  Min 
     System.out.println("The Max number is:\t " + nums[99]); // Max
     System.out.println("The Median is: \t " + median); // Median


    //==============================================================
    //--------------------------- MEAN------------------------------
    double sum= 0 ;
    double  mean = 0 ;
    for(double w : nums){
    sum += w;
    mean = sum/SIZE;    }

    System.out.println("The Mean is:\t " + mean);

    //==============================================================
    //----------------------------MODE------------------------------
     //count the occurrences
    for (int e=0; e < nums.length; e++) {
        nums[e]++;
    }

    //go backwards and find the count with the most occurrences
    int mode = nums.length-1;
       for (int e= nums.length-2; e >=0; e--) 
       {
        if (nums[e] >= nums[mode])
          System.out.println( "The Mode is: \t " +  (mode = e));

        else 
          System.out.println("The Mode is:\t -1");
           break;
       }
     //==============================================================
     //-------------------------Standard Deviation-------------------  

     double val = 0,adding = 0, divide = 0, answer = 0, square= 0 ;
        for ( double r : nums){ 
          val =   r- mean;
          square  = val* val;
          adding += square ;
          divide = adding /100;
          answer = Math.sqrt(divide);

      }
          System.out.println("The Stand. Dev. is: \t " + answer); // standard deviation

     //=================================================================     

    }
  }









//===================================================//
//    NEXT CODE            NEXT CODE       NEXT CODE //
//===================================================//

class Statistics
{
Main nums1 = new Main();
Main [] nums = num1.getNums();

  Main nums = new Main();
public static double mean(nums[]) {
    double sum= 0 ;
    double  mean = 0 ;
    for(double w : nums[]){
    sum += w;
    mean = sum/SIZE;    }

    return mean;
}

public static double mode(nums[])
{

     for (int e=0; e < nums.length; e++) {
        nums[e]++;
    }

    //go backwards and find the count with the most occurrences
       int mode = nums.length-1;
       for (int e= nums.length-2; e >=0; e--) 
       {
        if (nums[e] >= nums[mode])
          // System.out.println( "The Mode is: \t " +  (mode = e));
          mode = e;

        else 
          mode = -1;
          //System.out.println("The Mode is:\t -1");
         return mode;
       }
}

public double median(nums[])
{
     double median;
     if(nums.length % 2 == 0){
         median = ((double)nums[nums.length/2] 
         + (double)nums[nums.length/2 - 2])/2;
     }else {
         median = (double)nums[nums.length/2];
         }
     return median;
}
public int Max(nums[])
{
  Max = nums[99];
  return Max;
}

public int Min(nums[])
{
  Min = nums[0];
  return Min;
}


public double StanDev(nums[])
{
  double val = 0,adding = 0, divide = 0, answer = 0, square= 0 ;
        for ( double r : nums){ 
          val =   r- mean;
          square  = val* val;
          adding += square ;
          divide = adding /100;
          answer = Math.sqrt(divide);

      } return answer;
}
}






//===================================================//
//    NEXT CODE            NEXT CODE       NEXT CODE //
//===================================================//



import java.util.*;


public class Main
{
  public static void main(String [] args)
  {

    int SIZE = 100; // the number of random # generated
    Random rand = new Random ();
    int[] nums = new int[SIZE];
    for (int q = 0; q < SIZE; q++) {
    nums[q] = rand.nextInt (400) + 10; // only numbers from 10-500 generated
    Arrays.sort (nums); // organizes numbers for max min and median
    }


    public int getNums () 
  {
    return nums ;
  }


    }
  }

      

+3
java object main


source to share


No one has answered this question yet

Check out similar questions:

5101
What's the most efficient way to deeply clone an object in JavaScript?
3799
How do I read / convert an InputStream to a string in Java?
2853
How can I convert String to int in Java?
2709
Detecting object property undefined
2685
Checking if a key exists in a JavaScript object?
1864
Iterating through object properties
1395
Find object by id in an array of JavaScript objects
1253
What does "Could not find or load main class" mean?
1186
Convert JS object to JSON string
904
Convert object to string



All Articles
Loading...
X
Show
Funny
Dev
Pics