This is the code for SampleDriver.Java : This is the Code for Sample.Java You ju
ID: 3808259 • Letter: T
Question
This is the code for SampleDriver.Java :
This is the Code for Sample.Java
You just need to make changes in the Sample.Java code and add the formulas so it looks like the example.
I also can share the files via email if that's good.
Please make sure the code works.
Complete the hyperlinked Sam e lava program to compute the required sample statistics invoked from the hyperlinked Sam driver program. Upload only your completed Samplejava program. A sample run is shown below (where input values are shown in lime green Sample minimum: 1.0 Sample maximum: 9.9 Sample sum: 36.9 Sample average: 3.69 Sample variance: 8.954333333333334 Enter number to search Cuse negative number to end 1 Number of instances of 1.0 in sample 3 Enter number to search Cuse negative number to end 2 Number of instances of 2.0 in sample: 0 Enter number to search Cuse negative number to end 2.3 Number of instances of 2.3 in sample 1 Enter number to search Cuse negative number to end): -1 LEND] Note: Sample variances are calculated as follows: i-0 where T is the sample average and n is the size of the sample data.Explanation / Answer
import java.util.ArrayList;
public class Sample{
ArrayList<Double> list = null;
public Sample(double[] a){
list = new ArrayList<Double>(a.length);
for(int i=0;i<a.length;++i){
list.add(a[i]);
}
}
public double min(){
double m = list.get(0);
for(int i=1;i<list.size();i++){
if(list.get(i)<m){
m = list.get(i);
}
}
return m;
}
public double max(){
double mlist = list.get(0);
for(int i=1;i<list.size();i++){
if(list.get(i)<mlist){
mlist = list.get(i);
}
}
return mlist;
}
public double sum(){
double sum=0;
for(int i=0;i<list.size();i++){
sum = sum+list.get(i);
}
return sum;
}
public double average(){
double sum=0;
double average=0;
for(int i=0;i<list.size();i++){
sum = sum+list.get(i);
}
average = sum/list.size();
return average;
}
public double variance(){
double var1=0;
double var=0;
double avg = average();
for(int i=0;i<list.size();i++){
var1 = (list.get(i)-avg)*(list.get(i)-avg);
}
var = var1/(list.size()-1);
return var;
}
public int countInstancesOf(double element){
int count =0 ;
for(int i=0;i<list.size();i++){
if(element == list.get(i)){
count++;
}
}
return count;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.