Reference no: EM132211343
Question :
Write a program that reads a set of floating-point values. Ask the user to enter the values (prompting only a single time for the values), then print:
-the average of the values.
-the smallest of the values.
-the largest of the values.
-the rage, that is the difference between the smallest and largest.
Your program should use a class DataSet. That class should have a method public void add(double value) and methods getAverage, getSmallest, getLargest, and getRange.
So there needs to be a classDataSet, and a DataSetTester.
I've provided both below, but I'm not sure what exactly to place into each. Help? Thanks.
public class DataSet { //public class
private double value=0; //instance variables that should be initialized.
private double sum=0;
private int count=0;
private double smallest=0;
private double largest=0;
public void add(double value){
sum =+ value;
}
public void getAverage(){
while (sum >0){
count++;
double average = sum/count;
}
}
public void getLargest(){
if (value > largest)
largest = value;
}
public void getSmallest(){
if (value<smallest)
smallest = value;
}
public void getRange(){
double range = largest - smallest;
}
}
***********
import java.util.Scanner;
public class DataSetTester {
public void main(String[] args){
DataSet Tester;
Tester = new DataSet();
Scanner scan = new Scanner(System.in);
System.out.println("Enter values, enter Q to finish");
value = scan.nextDouble();
while (value !=-1){
sum =+ value;
}
}
System.out.println("The Range is: " + Tester.getAverage());