Question

In: Computer Science

Use Java Sample values from an experiment often need to be smoothed out. One simple approach...

Use Java

Sample values from an experiment often need to be smoothed out. One simple approach is to replace each value in an array with the average of the value and its two neighboring values (or one neighboring value if it is at either end of the array). Given a class Data with instance fields

private double[] values;
private double valuesSize;

implement a method

public void smooth()

that carries out this operation. You should not create another array in your solution.

Solutions

Expert Solution

/*========================initial instruction begain===================
 create package smoothning using any editor 
 crate a class by rigth clicking on package at tool bar and->new->select new class->and give name        smooth
*if you are not good at  create a new class than put in same class
================ instruction end=======================================*/

/*------if you have any query please text it again-------------------*/

//===============code begain===================================
 
/*==================== these is the class smooth=========================*/
package smoothning;

//package require to take input
import java.util.Scanner;

public class smooth {
    //-----------Declaration start---------------------
     private double value[]= new double[10];
     private double valuesize;
     //-------------Declaration end--------------------
     
     //------when obj.take_input() function is call----
         public void take_input(){
         //-Create object sc to take input from user    
         Scanner sc=new Scanner(System.in);
         
        System.out.println("Enter the Element want for smoothing to be perform on that");
        valuesize=sc.nextDouble();   //how many  number of element you want 
        System.out.println("Please Enter the element for smoothing  ");
        for(int i=0;i<valuesize;i++){    
           value[i]=sc.nextDouble();//---taking each element
        }
     
     }
         //------------take_input() function end-------------
         
      //--------------when obj.smoothed_fun( is call---------
         
         public void smoothed_fun(){

             double temp,temp1; //temporary variable is declare 
               int i;
               //no need for smoothing 
              temp=value[0];
              value[0]=value[1];
            
            for(i=1;i<valuesize-1;i++){
                   temp1=value[i];
                   value[i]=(temp+value[i+1])/2;
                   temp=temp1;
            }
         value[i]=temp;
         System.out.println("----------------------------------");
         for(i=0;i<valuesize;i++)
             System.out.print(value[i]+" ");
         System.out.println("\n----------------------------------");
         
         }
}
/*==========================main function===============================
      
/*
     from here the main programing is begain
     for smoothoing process we declare class smooth
     and call two function
 */
package smoothning;
public class Smoothning {

 
    public static void main(String[] args) {
        
        
        //Declare an object of class smooth 
        // where obj is the object
       smooth obj=new smooth();
       
       //calling function take_input() to make code user friendly
       obj.take_input();
       
       //here the smoothing is perform
       obj.smoothed_fun();
    }
    
}
o/p:===========================================================
run:
Enter the Element want for smoothing to be perform on that
5
Please Enter the element for smoothing  
1.2
2.2
3.2
4.2
5.2
----------------------------------
2.2 2.2 3.2 4.2 4.2 
----------------------------------
BUILD SUCCESSFUL (total time: 32 seconds)

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


Related Solutions

In a simple experiment, you are going out there to the duck pond to seine out...
In a simple experiment, you are going out there to the duck pond to seine out one redbreast sunfish at random, determine its sex, and put it back in the pond and then, after 30 minutes, repeat this process. Assuming that the sex ratio for redbreast in the pond is 1:1, develop and plot the pmf of the random variable X, defined as the number of females in the two fish observed. Is the distribution of X symmetric or asymmetric?...
Write out the sample space for the given experiment. Use the following letters to indicate each...
Write out the sample space for the given experiment. Use the following letters to indicate each choice: M for mushrooms, O for olives, S for shrimp, E for eggs, V for vinaigrette, and F for French. When deciding what you want to put into a salad for dinner at a restaurant, you will choose one of the following extra toppings: mushrooms, olives. Also, you will add one of following meats: shrimp, eggs. Lastly, you will decide on one of the...
Need this in java .Create a simple login screen in java That lets people sign in...
Need this in java .Create a simple login screen in java That lets people sign in to the emergency room. It needs to ask for name, social,and DOB. Once all the information is received it then display the info back to them if any info is is missing have the program prompt the user to re enter their information.
A famous scientist, Mendel, conducted a genetic experiment with peas. One sample from this experiment consisted...
A famous scientist, Mendel, conducted a genetic experiment with peas. One sample from this experiment consisted of 152 yellow peas out of 580 peas. Calculate a 95% confidence interval for the percentage of yellow peas. Also, find the estimation and the margin of error.
A famous scientist, Mendel, conducted a genetic experiment with peas. One sample from this experiment consisted...
A famous scientist, Mendel, conducted a genetic experiment with peas. One sample from this experiment consisted of 152 yellow peas out of 580 peas. Calculate a 95% confidence interval for the percentage of yellow peas. Also, find the estimation and the margin of error.
Describe an experiment that would require use of one of the three different t-tests (One Sample,...
Describe an experiment that would require use of one of the three different t-tests (One Sample, Correlated Samples, or Independent Groups)
two hundred auditors each took their own simple random sample of fifteen values from a large...
two hundred auditors each took their own simple random sample of fifteen values from a large data set of account balances, and each constructed a 90% confidence interval for the mean balance of the entire data set. About how many of the auditors had the true mean for the entire set in their personal confidence interval?
Describe the Sample Space for the experiment of selecting one card from a deck of regular...
Describe the Sample Space for the experiment of selecting one card from a deck of regular playing cards?
Hi there, I want to make an experiment that you can use a one sample z-...
Hi there, I want to make an experiment that you can use a one sample z- test and interval on it. The project is a paper helicopter and we can make as many we like and then explain the process It should be dropped from a height and a weight like paperclip in the bottom to make fall. Please help me with this project. 1st: what is inference procedure and the variables you are estimating 2nd: the experiment procedure, the...
One of the values of the sort of approach to culture in the world system made...
One of the values of the sort of approach to culture in the world system made possible by practice theory and related developments in anthropology is that it allows us to recognize peoples like the contemporary Kayapo or the Kwakwaka’wakw as: Indigenous Modernities Billiard Ball Polities Isolated Villagers Disappearing Worlds Our contemporary ancestors According to David Miliband, most of the world’s refugees reside In western countries. In Asia. In the poorest parts of the world. All of the above. None...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT