Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 image text in transcribed is image text in transcribed∑xin where image text in transcribed∑xi means image text in transcribed

The standard deviation is

s=image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions

Question

Outline the employee's role in the succession management process.

Answered: 1 week ago