Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

Relational Database Technology

Authors: Suad Alagic

1st Edition

354096276X, 978-3540962762

More Books

Students also viewed these Databases questions