Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an interactive program that displays statistics about an array of randomly generated integers. The program will also save the output to a file. First,

image text in transcribed

image text in transcribedimage text in transcribed

Write an interactive program that displays statistics about an array of randomly generated integers. The program will also save the output to a file. First, your program should display an introduction. Second, your program should prompt for the name of an output file to use. Now, in a loop until the user chooses to quit: prompt the user for a size (for the array of integers). The range of valid sizes is 3 to 8 inclusive. If the user enters a value that is not in the valid range, give an error message and prompt again. After obtaining a valid size from the user, your program will construct an array of random integers. The size of the array will be the value previously input by the user. The random integers should be in the range -5 to 5 inclusive. Your program should then display the following on the console: The numbers in the array inside square brackets and separated by commas. Example: [2,-5, 3, 1, 6] The minimum value in the array. (an int) The maximum value in the array. (an int) The sum of the numbers in the array. (an int) The average of the numbers in the array rounded to two decimal places. (a double) (Use printf for this) The median of the numbers in the array rounded to two decimal places. (a double) (Use printf for this) (The median of a sorted array of odd length is the middle number) (The median of a sorted array of even length is the average of the middle two numbers) Your program should repeat until the user enters -1 as the size of the array. (-1 is a sentinel to quit the program) Your program will be divided into two separate java files: NumbersMain.java' and 'Numbers.java' NumbersMain.java will contain a main method and methods to: Display an introduction public static void displayIntroduction () Prompt the user for an input file name prompt ForFileName() Prompt the user for the size of the array public static int prompt ForArraySize() Create an output String which can be displayed on the console and sent to a file public static String format Statistics (int[] numbers, int min, int max, int sum, double average, double median) Display an exit message public static void displayExit Message() NOTE: No calculations or random number generation will be done anywhere in the NumbersMain.java class. NOTE: You can include additional methods to help structure your program. Numbers.java will not have a main method but will have methods to: Create an array of a given size and fill it with random integers in the range min<>

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

Multidimensional Array Data Management In Databases

Authors: Florin Rusu

1st Edition

1638281483, 978-1638281481

More Books

Students also viewed these Databases questions