Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create two Java classes StatDriver.java with a main method and Stats.java without a main method, goal of the main method is to read a series

  1. Create two Java classes StatDriver.java with a main method and Stats.java without a main method, goal of the main method is to read a series of numbers from System.in, create an Arraylist containing those numbers, call the mean and standard deviation functions of the Stats class, and then report the results.

  2. While executing your program, user should be able to provide a string on the command line indicating whether they want to calculate the mean ("mean") or the standard deviation ("std"). If no argument is provided, the mean should be calculated.

  3. While entering the numbers from the terminal, as program input, the user should be able to indicate that no more numbers will be entered by pressing CTRL-d or any non-number character (ex.letters A-Z) in the terminal.

  4. To start coding, first create an Arraylist of double values: ArrayList data in your main method.

  5. Now, use a loop to read the input values from the keyboard (as doubles) and store them into the Arraylist. No prompt should be given before reading the values. The loop should terminate when user indicates that no more numbers will be entered by pressing CTRL-d in the terminal.

    - The following lines of code will allow you to read the numbers from the terminal and will store it in an Arraylist named data, till user presses CTRL-d in the terminal:

    Scanner input = new Scanner(System.in);

    while (input.hasNextDouble()) { data.add(input.nextDouble()); }

  6. Note: The condition of the while loop works for anything other than numbers. User can either press ctrl-d or any non-number (ex.letters A-Z) in the keyboard to stop taking input.

  7. Once the Arraylist is built, if the user wanted to compute mean, you will call the appropriate method (either mean or stdDev) of Stats class and pass this Arraylist as the argument.

  8. In the Stats.java file, create a public static method called mean that will take an Arraylist of double values as its parameter, and then calculate and return the mean of those numbers (which is of double datatype).

  9. The method should ensure that the Arraylist is not null and that it has more than 0 elements. If either of these conditions exists, the method should return Double.NaN (not a number).

  10. Test your mean method from the StatDriver.java program. The main method should output the return value as a single line, using the format "Mean: %.2f ".

THANK YOU!

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions