Your software company has been contracted to write a prototy

Your software company has been contracted to write a prototype program to perform simple statistical evaluations of integer data. Your portion of this program requires that you implement one object class: StatPackage. For final testing your class will be compiled and linked to a driver program. You need to throughly test your package with your own drivers prior to delivery of your code.

The interface specification for the StatPackage is:

The functional specification for your package is:

Your StatPackage will accept up to 500 values as input.

Mean is the mean value for the values inserted into the StatPackage, mean is essentially the same as the average.

Median is middle value if the number of items is odd or the average of the middle two values if the number of items is even.

Variance is determined by the formula:

StdDev is the square root of the variance

Histogram is a graphical output of the items inserted into the StatPackage. The format of the Histogram is:

Where each \'*\' represents 5 items in the partition.

Solution

import java.util.ArrayList;
import java.util.List;

class StatPackage {
  
   int MAX = 500;
   List<Double> doubleList;
           // constructor for the class
    StatPackage (){
       doubleList = new ArrayList<Double>();
    }
           // insert value into the next position of the List
           // attempts to enter values once MAX is exceeded are ignored
    public void insert (double value){
       if(MAX>doubleList.size()){
           doubleList.add(value);
       }
    }
  
           // Print a histogram of the data in the List
    public void Histogram (){
       //If MAX/10==0 then create array size MAX/10 else (MAX/10)+1
       //get max number in the list
       double max = 0.0;
       for(int i=0;i<doubleList.size();i++){
           if(max<doubleList.get(i)){
               max=doubleList.get(i);
           }
       }
      
       //Array size: if max%10>0 then max/10+1 else max/10
       int[] histogram = new int[(int)max%10>0?(int)max/10+1:(int)max/10];
      
       for(Double db:doubleList){
           //finding box to put the number
           int k = (int) ((db-1)/10);
           histogram[k]++;
       }
      
       for(int i=0;i<histogram.length;i++){
           //String builder to append * depending upon the frequency
           StringBuilder stars = new StringBuilder();
           for(int j=histogram[i]/5;j>0;j--){
               stars.append(\"*\");
           }
           //Printing the range and asterisks
           System.out.println((i*10+1)+\" - \"+(i*10+10)+\" | \"+stars.toString());
       }
    }
           // Calculate the mean of the data in the List
    public double Mean (){
       double mean = 0.0;
       double sum = 0.0;
      
       for(Double db:doubleList){
           sum+=db;
       }
      
       mean = sum/doubleList.size();
       return mean;
    }
           // Calculate the median value for the data in the List
    public double Median (){
       double median = 0.0;
      
       //For even
       if(doubleList.size()%2==0){
           median = (doubleList.get(doubleList.size()/2-1)+doubleList.get(doubleList.size()/2))/2;
       }
       //For odd
       else{
           median = doubleList.get(doubleList.size()/2);
       }
      
       return median;
    }
           // Calculate the variance value for the data in the List
    public double Variance (){
       double sqSum = 0.0;
       double sum = 0.0;
       double variance = 0.0;
      
       for(Double db:doubleList){
           sqSum+=Math.pow(db, 2);
           sum+=db;
       }
      
       variance = sqSum/doubleList.size()-(Math.pow(sum/doubleList.size(), 2));
       return variance;
    }
           // Calculate the standard deviation value for the data in the List
    public double StdDev (double variance){
       return Math.sqrt(variance);
    }
          
}

Your software company has been contracted to write a prototype program to perform simple statistical evaluations of integer data. Your portion of this program r
Your software company has been contracted to write a prototype program to perform simple statistical evaluations of integer data. Your portion of this program r

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site