Question
I am lost as to what I need ugh!!! This is what I need answered... ... Write a program that reads a set of positive
I am lost as to what I need ugh!!!
This is what I need answered......
Write a program that reads a set of positive floating point data values. A negative value signals the end of the data set. When all of the positive values have been read, your program will print out the count, average, and standard deviation of the positive data values.
The average of a data set is ∑xin where ∑xi means
The standard deviation is
s=
You can compute this quantity by keeping track of the count, the sum and the sum of squares as each data value is processed.
Write a class DataSet with instance variables value, count, sum, and sumOfSquares. That class should have a method
public void addValue(double value)
to process the input value and update count, sum, and sumOfSquares.
Write methods getAverage() and getStandardDeviation() in the class DataSet.
Your main program will create a DataSet object, read in values and call the addValue instance method until it encounters a negative value. Then it will call the getAverage and getStandardDeviation methods and print out the return results.
Example Run:
Enter Data: 1 2 3 4.4 6 -1
Average is 3.28 Standard Deviation is 1.972815247
This is the code I got so far.....
import java.util.Scanner; public class DataSet { double value; double count; double sum; double sumOfSquares; public DataSet(double value, double count, double sum, double sumOfSquares){ this.value=value; this.count=count; this.sum=sum; this.sum=sumOfSquares; } public void addValue(double value){ count++; sum+=value; sumOfSquares+=value*value; } public static double getAverage(double sum, double count){ return sum/count; } public static double getStandardDeviation(double someOfSquares){ return Math.sqrt((count*sumOfSquares-sum*sum)/(count*(count-1))); } public static void main(String[] args){ DataSet d=new DataSet(value, count, sum, sumOfSquares); Scanner sc=new Scanner(System.in); System.out.print("Enter Data :"); while(value=sc.nextDouble()>0){ d.addValue(value); System.out.print(); } System.out.println("Average is :"+getAverage(sum,count)); System.out.println("Standard Deviation :"+getStandardDeviation(sumOfSquares)); } }
1, T2, In
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started