Question: Modify Assignment #10 so that it can take positive, zero, and negative floating point numbers and calculate the mean and standard deviation. Input ends when

Modify Assignment #10 so that it can take positive, zero, and negative floating point numbers and calculate the mean and standard deviation. Input ends when the user enters a string that can not be interpreted as a floating point number. Use exception handling to detect improper inputs.

This was my assignment 10 code, this is my example to use

try}

String filename = ....;

Scanner in = new Scanner(new File(filename));

String input =in.next();

int value = Integer.parseInt(input);

.......

{

catch (IOException exception){

exception.printStackTrace();

}

catch (NumberFormatException exception){

System.out.println(exception.getMessage());

}

import java.util.Scanner; public class DataSet { static double value; static double count ; static double sum; static 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.println("Average is :"+getAverage(sum,count)); System.out.println("Standard Deviation :"+getStandardDeviation(sumOfSquares)); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!