Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Today's Activities Create a new project (L06), download the file ArrayStats.java into the project src/106 folder The ArrayStat: class is meant to compute some array

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Today's Activities Create a new project (L06), download the file ArrayStats.java into the project src/106 folder The ArrayStat: class is meant to compute some array related operations. The specific operations are the following. i. Fill the array with random values. 2. Get the minimum and maximum values of the array. 3. Create a counter array containing the number of occurrences of each element in the array. For now, Arraystate class contains incomplete code, and they do not function properly. In this week's lab, you will modify the code (ArrayStats.java) so that it will work as intended. Activity #1 (Array filling): Write the code for filling the array 'a' with random number in the range 1 to maxRange. The value maxRange is entered by the user. Run the program and check the output before the second pause. It should look somethinglike this (the actual numbers will be different): Array Statistics ... press enter... ---- Filling the array with random numbers--- Enter the maximum range: 10 Original array: a = 16, 0, 8, 7, 1 of 6 2 ... press enter... Q Activity #2 (Min and Max): Implement the code for getting the minimum and maximum values of the array a'. These are very straightforward methods, and you should not have any issues by now! Run the program again and check that the minimum and maximum values before the third pause match the numbers shown before the second pause. You will see an output similar to the following (again the values may be different as we fill the arrays with random values). -- Checking the min and max values of the array --- Min and Max of the array a are 0 and 9 ... press enter... Activity #3 (Element counter): Write the code for counting how many times each value appears in the array a? and returns them as an array of counters. For example, for the data array (4, 6, 3, 4,4, 1,4,9,4, 2, 10, 5,5,6, 1, 4, 5, 5, 10, 2, 6,2,3,4,4, 2, 10,9,2, 6): 1. First you need to find the maximum value (which is already available in max). In this case we have 10. 2. Now create an array with one more element than the maximum (for example, if the max is 10, then create an array with 11 elements). Let's call this array counter 3. Go through each value in the data array 'a', and increment the corresponding element in counter For example, the 1st data value is 4 so we increment counter [4] ++. The next data value is 6, so we do counter 161 ++. Repeat for all the values in the data array. Hint: You don't need to do a big if-else-if for this step. You can do it in two lines: put the number from the data array into a variable and use that variable as the index into the array of counters. (In fact, you don't even need the variable; it can be done in one line.) For example, the 1st data value is 4 so we increment counter [4]++. The next data value is 6, so we do counter [6] ++. Repeat for all the values in the data array. Hint: You don't need to do a big if-else-if for this step. You can do it in two lines: put the number from the data array into a variable and use that variable as the index into the array of counters. (In fact, you don't even need the variable; it can be done in one line.) In this example of the data set, for each step, counter will change as shown below: Data value = 4, counter = 10, Data value = 6, counter Data value = 3, counter Data value = 4, counter Data value = 4, counter Data value = counter Data value = 4, counter Data value = 9, counter Data value = 4, counter Data value = 2, counter Data value = 10, counter Data value = 5, counter Data value = 5, counter Data value = 6, counter Data value = 1, counter Data value = 4, counter Data value = 5, counter Data value = 5, counter Data value = 10, counter Data value = 2, counter Data value = 6, counter = (0, Data value = 2, counter Data value = 3, counter Data value = 4, counter Data value = 4, counter Data value = 2, counter Data value = 10, counter Data value = 9, counter Data value = 2, counter = Data value = 6, counter = , 7, 4, 3, 2, 9, 4, 3, 0, 0, 2, 4, 3, 0, 0, 4. After the loop, you will display the counter. Once everything is completed, you can run a few times to make sure your code produce the correct values. The last part of the program uses the counter array you created to print a bar chart of the values in one of the arrays you counted. It might help you check your result The below are a few sample runs (NB: the arrays are created randomly, so your values will be different from the sample output). Sample output 1 Array Statistics -press enter. ---- Filling the arrays with random numbers--- Enter an integer: 10 Original array: a = [6,0, 8, 7, 9, 6, 3, 2,5, 2] ...press enter... ---- Checking the min and max values of the array --- Min and Max of the array a are 0 and 9 ...press enter... ---- Checking the counters --- Counters of the array a is:[1,0, 2, 1, 0, 1, 2, 1, 1, 1] --press enter... ---- Bar Chart! ---- Bar Chart for a = [5, 6, 8, 7,9,6, 3, 2, 5, 2] 11 2 ** 314 41 51* 6 ** 81 9* ...press enter... Sample output 2 Array Statistics ...press enter... ---- Filling the arrays with random numbers--- Enter the maximum range: 15 Original array: 3 = [13, 11, 12, 1, 3, 11, 10, 11, 4, 1] ...press enter... ---- Checking the min and max values of the array --- Min and Max of the array a are 1 and 13 ...press enter... ---- Checking the counters Counters of the array a is:(0,2,0,1,1,0,0,0,0,0, 1, 3, 1, 1] ...press enter... 2 ---- Bar Chart! ---- Bar Chart for a = [13, 11, 12, 1, 3, 11, 10, 11, 4, 1] 1 ** 21 3* 4* 5 5 61 8 9 7| 81 91 10 * 11 12* 13* *** ... press enter... soro a

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_2

Step: 3

blur-text-image_3

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago