Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2. (10 points; 2 points each) You have an array of earthquake data for Oklahoma

ID: 3699030 • Letter: 2

Question

2. (10 points; 2 points each) You have an array of earthquake data for Oklahoma for the last year. doublell tichterValues: /constructed and initialized elsewhere as a Perfect Size Array Use the methods in the Arrays APl to do the following actions. Note: Each of these items is a single line of code that will call one method in the Arrays class. Na credit will be given for writing the logic to do this work instead of using the Arrays class method. al Sort the values in the ichterValues array. b) Store a String representation of the ticbteryalues values into a new String called summary. Note: For this and the remaining questions, you will need to declare the new variable to catch the results of the method call) c) Make a new copy of the first 5 items in the array. Store this array in a new double array called five. Note: If there are less than 5 items in the tichtervalues array, leave the new values added as 0.) d) Check to see if the tichterValuss array is equal to the double array named ray (assume the ray array has been declared and initialized for your already) and store that value into a new bgglean variable called isSame e) Make a new copy tichtervalues array that contains only the items in index 3 index7, inclusive. Store this array in a new double array called newbie. (Note: In this case, you may assume that the rishterValues array has at least 4 items so there is definitely a value in index 3. Inelusive means that the items at index 3 and index 7 are both included in the final array.)

Explanation / Answer

Here is the required code for you. Implemented all the required functionalities using individual calls to the Arrays class methods. And finally displayed the complete information. Drop a comment if you have any doubts. Thanks.

// ArraysExample.java

import java.util.Arrays;

public class ArraysExample {

                /**

                * Defining richterValues and ray arrays

                */

                static double[] richterValues = { 6.5, 7.2, 4.3, 4.4, 3.7, 2.9, 6.9, 8.5,

                                                1.3, 7.5, 3.4, 5.22, 7.11, 5.01 };

                static double[] ray = { 7.2, 5.5, 2.3, 4.4, 5.5 };

                public static void main(String[] args) {

                                /**

                                * Sorting the array

                                */

                                Arrays.sort(richterValues);

                                /**

                                * making a String representation of richterValues array

                                */

                                String summary = Arrays.toString(richterValues);

                                /**

                                * Copying the first five values of the richterValues array into a new

                                * array five

                                */

                                double five[] = Arrays.copyOf(richterValues, 5);

                                /**

                                * Checking if richterValues is equal to ray array

                                */

                                boolean isSame = richterValues.equals(ray);

                                /**

                                * Copying the five values of the richterValues array between the

                                * indices 3-7 into a new array newbie

                                */

                                double newbie[] = Arrays.copyOfRange(richterValues, 3, 7);

                                /**

                                * Displaying everything

                                */

                                System.out.println("Sorted richterValues array: " + summary);

                                System.out.println("five array: " + Arrays.toString(five));

                                System.out.println("is richterValues = ray? " + isSame);

                                System.out.println("newbie array: " + Arrays.toString(newbie));

                }

}

//Output

Sorted richterValues array: [1.3, 2.9, 3.4, 3.7, 4.3, 4.4, 5.01, 5.22, 6.5, 6.9, 7.11, 7.2, 7.5, 8.5]

five array: [1.3, 2.9, 3.4, 3.7, 4.3]

is richterValues = ray? false

newbie array: [3.7, 4.3, 4.4, 5.01]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote