Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

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.

1C

Description

Enhance the last assignment by providing the following additional features:

Class Statistics

In the class Statistics, create the following static methods (in addition to the instance methods already provided).

A public static method for computing sorted data.

A public static method for computing min value.

A public static method for computing max value.

A public static method for computing mean value.

A public static method for computing median value.

In the class Statistics, create the following static variable (in addition to the instance variables already provided).

A static variable count that keeps track of the total number of Statistics objects created during the program run.

Increment the static count variable from within the Statistics constructor.

Display the value of the static count variable at the end of the program.

Class TestStatistics

In the main method of the class TestStatistics, do the following:

Input all user data values as a single String using a single input dialog box.

Use a StringTokenizer object to separate individual values in the input String.

Store input values in the elements of the array data.

Create a Statistics object and pass it the array data.

Call instance methods of the Statistics object to compute required statistics.

Call static methods to compute required statistics. (Pass array data to each static method).

Display the required statistics two times: once after calling instance methods and a second time after calling static methods. (See the output of a test run later below).

Display the total number of Statistics objects created during the program run. (Do this by displaying the value of the static variable count at the end).

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago