Question: 1A Description Write a Java program that will compute a number of statistics for a set of data provided by the user. The data will
1A
Description
Write a Java program that will compute a number of statistics for a set of data provided by the user. The data will be made up of decimal numbers. After inputting the data, the program will compute and display the following statistics relating to the data.
Min Value
Max Value
Mean Value
Median Value
Implementation
Do the above assignment by creating two classes: Statistics and TestStatistics.
The class Statistics will be used as a blue print for a Statistics object.
It will keep a set of data and will provide methods to compute statistics relating to the data. The data will be provided to the Statistics object in an array during object construction.
The class TestStatistics will be used to hold the method main. The method main will be used to input the data, create the Statistics object, compute statistics by calling Statistics object methods and display the values received.
Class Statistics
The class Statistics will provide the following:
A private array variable data for holding user data.
A private array variable sdata for holding a sorted copy of the above data.
A constructor to initialize the array data.
A method getOrigData for returning a copy of the array data.
A method getSortedData for returning a copy of the original array but now sorted.
A method findMin for computing min
A method findMax for computing max
A method findMean for computing mean (or average)
A method findMedian for computing median
Class TestStatistics
The class TestStatistics will provide the method main which will do the following:
Prompt the user for the number of total items in the data.
Create an array of that size.
Input data items from the user and store them in the array.
Create an object of the class Statistics and pass it the data array.
Call a Statistics object method to obtain the original data array.
Call a Statistics object method to obtain the data array but now sorted in ascending order.
Call Statistics object methods for calculating the min, max, mean and median values.
Display the original data, data sorted in ascending order, min, max, mean and median values.
Testing
Test Run:
Input
(User input is shown in bold).
Enter the Number Of Data Values: 12
Enter Data Value: 7.2
Enter Data Value: 7.6
Enter Data Value: 5.1
Enter Data Value: 4.2
Enter Data Value: 2.8
Enter Data Value: 0.9
Enter Data Value: 0.8
Enter Data Value: 0.0
Enter Data Value: 0.4
Enter Data Value: 1.6
Enter Data Value: 3.2
Enter Data Value: 6.4
Output
Original Data:
7.2 7.6 5.1 4.2 2.8 0.9 0.8 0.0 0.4 1.6 3.2 6.4
Sorted Data:
0.0 0.4 0.8 0.9 1.6 2.8 3.2 4.2 5.1 6.4 7.2 7.6
Min Value: 0.0
Max Value: 7.6
Mean: 3.35
Median: 3.0
1B
Description
Enhance the last assignment by providing the following additional features:
Input All Data As A Single String
Input all data values as a single input string using one input dialog box. Then use a StringTokenizer object to tokenize (separate into components) the data. For this purpose, do the following:
Input all data as a single String using JOptionPane.showInputDialog.
Create a StringTokenizer object and supply it with the input string and a token delimiter (separator) during object construction.
Find the token count by calling StringTokernizers method countTokens ( ).
Create an array of size count to store data values.
Write a Java For statement to loop token count times. During each pass through the loop, obtain the next token by calling StringTokenizers nextToken( ) method. Convert the token received as a String to a double and save it in the corresponding array element.
Output All Data To Three Decimal Places
You can display output data to desired number of decimal places. For this purpose do the following:
Create a DecimalFormat object and supply it with the appropriate Format String to format decimal numbers to required decimal places.
Use the DecimalFormat object to format any decimal numbers into a formatted strings.
Display the formatted String.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
