Can you help me complete the Tester? import java.lang.Math; public class P6_2{ i
ID: 3857156 • Letter: C
Question
Can you help me complete the Tester?
import java.lang.Math;
public class P6_2{
int count ;
double sum;
double sumSquares ;
public P6_2(){
this.count = 0;
this.sum = 0;
this.sumSquares = 0 ;
}
public void add (double num){
sum = sum +num;
sumSquares = sumSquares + num * num;
count ++;
}
public double getAverage(){
return sum / count;
}
public int getCount(){
return count;
}
public double getStandardDeviation(){
return Math.sqrt((sumSquares - Math.pow(sum,2)/count)/(count-1));
}
}
import java.util.Scanner;
public class P6_2Tester{
public static void main(String[] args){
P6_2 a =new P6_2();
Scanner in = new Scanner(System.in);
System.out.println("Please enter numbers: ");
double num = in.nextDouble();
a.add(num);
System.out.println("Total counts are " + a.getCount());
System.out.println("The average is " + a.getAverage());
System.out.println("Standard Deviation is " + a.getStandardDeviation());
in.close();
}
}
Explanation / Answer
Hi i make change to program and run it please follow the below output:
program:
import java.lang.Math;
import java.util.Scanner;
class P6_2{
int count ;
double sum;
double sumSquares ;
public P6_2(){
this.count = 0;
this.sum = 0;
this.sumSquares = 0 ;
}
public void add (double num){
sum = sum +num;
sumSquares = sumSquares + num * num;
count ++;
}
public double getAverage(){
return sum / count;
}
public int getCount(){
return count;
}
public double getStandardDeviation(){
return Math.sqrt((sumSquares - Math.pow(sum,2)/count)/(count-1));
}
}
class P6_2Tester{
public static void main(String[] args){
P6_2 a =new P6_2();
Scanner in = new Scanner(System.in);
System.out.println("Please enter numbers: ");
double num = in.nextDouble();
a.add(num);
System.out.println("Total counts are " + a.getCount());
System.out.println("The average is " + a.getAverage());
System.out.println("Standard Deviation is " + a.getStandardDeviation());
in.close();
}
}
output:
input 34
output:
Success time: 0.07 memory: 4386816 signal:0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.